diff -Nru pypandoc-1.4+ds0/debian/changelog pypandoc-1.5+ds0/debian/changelog --- pypandoc-1.4+ds0/debian/changelog 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/changelog 2020-04-18 18:14:01.000000000 +0000 @@ -1,3 +1,15 @@ +pypandoc (1.5+ds0-1) unstable; urgency=medium + + * New upstream release. + * Remove patches applied upstream. + * Update maintainer email. + * Updated debhelper-compat and Standards-Version (no changes needed). + * Add Rules-Requires-Root: no. + * Added basic UMEGAYA. + * Add autopkgtests with autopkgtest-pkg-python. + + -- Elena Grandi Sat, 18 Apr 2020 20:14:01 +0200 + pypandoc (1.4+ds0-2) unstable; urgency=medium [ Ondřej Nový ] diff -Nru pypandoc-1.4+ds0/debian/control pypandoc-1.5+ds0/debian/control --- pypandoc-1.4+ds0/debian/control 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/control 2020-04-18 18:14:01.000000000 +0000 @@ -1,10 +1,10 @@ Source: pypandoc -Maintainer: Elena Grandi +Maintainer: Elena Grandi Uploaders: Debian Python Modules Team Section: python Priority: optional Build-Depends: - debhelper-compat (= 9), + debhelper-compat (= 12), dh-python, lmodern, pandoc, @@ -18,7 +18,9 @@ texlive-latex-recommended, texlive-luatex, texlive-xetex -Standards-Version: 3.9.8 +Standards-Version: 4.5.0 +Rules-Requires-Root: no +Testsuite: autopkgtest-pkg-python Homepage: https://github.com/bebraw/pypandoc Vcs-Git: https://salsa.debian.org/python-team/modules/pypandoc.git Vcs-Browser: https://salsa.debian.org/python-team/modules/pypandoc diff -Nru pypandoc-1.4+ds0/debian/gbp.conf pypandoc-1.5+ds0/debian/gbp.conf --- pypandoc-1.4+ds0/debian/gbp.conf 1970-01-01 00:00:00.000000000 +0000 +++ pypandoc-1.5+ds0/debian/gbp.conf 2020-04-18 18:14:01.000000000 +0000 @@ -0,0 +1,2 @@ +[DEFAULT] +debian-branch=debian/master diff -Nru pypandoc-1.4+ds0/debian/patches/0001-Skip-test-s-that-require-the-network.patch pypandoc-1.5+ds0/debian/patches/0001-Skip-test-s-that-require-the-network.patch --- pypandoc-1.4+ds0/debian/patches/0001-Skip-test-s-that-require-the-network.patch 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/patches/0001-Skip-test-s-that-require-the-network.patch 2020-04-18 18:14:01.000000000 +0000 @@ -1,4 +1,3 @@ -From e3b4a2d31120f526ab6e70b6f4b0e32757d7b305 Mon Sep 17 00:00:00 2001 From: Elena Grandi Date: Sat, 5 Nov 2016 12:47:21 +0100 Subject: Skip test(s) that require the network. @@ -8,14 +7,14 @@ 1 file changed, 1 insertion(+) diff --git a/tests.py b/tests.py -index 90c801f..f501218 100755 +index deb50e0..574eeea 100755 --- a/tests.py +++ b/tests.py -@@ -168,6 +168,7 @@ class TestPypandoc(unittest.TestCase): - received = pypandoc.convert(file_url, 'rst') +@@ -179,6 +179,7 @@ class TestPypandoc(unittest.TestCase): + received = pypandoc.convert_file(file_url, 'rst') self.assertEqualExceptForNewlineEnd(expected, received) + @unittest.skip('requires network') def test_basic_conversion_from_http_url(self): url = 'https://raw.githubusercontent.com/bebraw/pypandoc/master/README.md' - received = pypandoc.convert(url, 'html') + received = pypandoc.convert_file(url, 'html') diff -Nru pypandoc-1.4+ds0/debian/patches/0002-Fix-parsing-of-unicode-paths-on-non-unicode-locales.patch pypandoc-1.5+ds0/debian/patches/0002-Fix-parsing-of-unicode-paths-on-non-unicode-locales.patch --- pypandoc-1.4+ds0/debian/patches/0002-Fix-parsing-of-unicode-paths-on-non-unicode-locales.patch 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/patches/0002-Fix-parsing-of-unicode-paths-on-non-unicode-locales.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -From 9d59e8362374dfc516cfc606d9ffd81b2f1ed5e1 Mon Sep 17 00:00:00 2001 -From: Elena Grandi -Date: Sat, 5 Nov 2016 13:50:56 +0100 -Subject: Fix parsing of unicode paths on non-unicode locales - ---- - pypandoc/__init__.py | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/pypandoc/__init__.py b/pypandoc/__init__.py -index abde4e3..6196d88 100644 ---- a/pypandoc/__init__.py -+++ b/pypandoc/__init__.py -@@ -149,8 +149,7 @@ def _identify_path(source): - try: - path = os.path.exists(source) - except UnicodeEncodeError: -- source = source.encode('utf-8') -- path = os.path.exists(source) -+ path = os.path.exists(source.encode('utf-8')) - except: - path # still false - diff -Nru pypandoc-1.4+ds0/debian/patches/0003-Fix-tests-with-newer-pandoc.patch pypandoc-1.5+ds0/debian/patches/0003-Fix-tests-with-newer-pandoc.patch --- pypandoc-1.4+ds0/debian/patches/0003-Fix-tests-with-newer-pandoc.patch 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/patches/0003-Fix-tests-with-newer-pandoc.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,159 +0,0 @@ -From ea9d2642f91489646b56faf13d8a852e7b737b0b Mon Sep 17 00:00:00 2001 -From: Jan Schulz -Date: Fri, 6 Apr 2018 02:03:32 +0200 -Subject: [PATCH] Fix tests with newer pandoc - ---- - tests.py | 38 +++++++++++++++++++------------------- - 1 file changed, 19 insertions(+), 19 deletions(-) - ---- a/tests.py -+++ b/tests.py -@@ -134,7 +134,7 @@ - self.assertTrue(isinstance(version, pypandoc.string_types)) - major = int(version.split(".")[0]) - # according to http://pandoc.org/releases.html there were only two versions 0.x ... -- self.assertTrue(major in [0, 1]) -+ self.assertTrue(major in [0, 1, 2]) - - def test_converts_valid_format(self): - self.assertEqualExceptForNewlineEnd(pypandoc.convert("ok", format='md', to='rest'), 'ok') -@@ -150,7 +150,7 @@ - self.assertRaises(RuntimeError, f) - - def test_basic_conversion_from_file(self): -- with closed_tempfile('.md', text='#some title\n') as file_name: -+ with closed_tempfile('.md', text='# some title\n') as file_name: - expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert(file_name, 'rst') - self.assertEqualExceptForNewlineEnd(expected, received) -@@ -158,7 +158,7 @@ - def test_basic_conversion_from_file_url(self): - # this currently doesn't work: https://github.com/jgm/pandoc/issues/3196 - return -- with closed_tempfile('.md', text='#some title\n') as file_name: -+ with closed_tempfile('.md', text='# some title\n') as file_name: - expected = u'some title{0}=========={0}{0}'.format(os.linesep) - # this keeps the : (which should be '|' on windows but pandoc - # doesn't like it -@@ -176,14 +176,14 @@ - - def test_convert_with_custom_writer(self): - lua_file_content = self.create_sample_lua() -- with closed_tempfile('.md', text='#title\n') as file_name: -+ with closed_tempfile('.md', text='# title\n') as file_name: - with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz") as lua_file_name: - expected = u'

title

{0}'.format(os.linesep) - received = pypandoc.convert_file(file_name, lua_file_name) - self.assertEqualExceptForNewlineEnd(expected, received) - - def test_basic_conversion_from_file_with_format(self): -- with closed_tempfile('.md', text='#some title\n') as file_name: -+ with closed_tempfile('.md', text='# some title\n') as file_name: - expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert(file_name, 'rst', format='md') - self.assertEqualExceptForNewlineEnd(expected, received) -@@ -193,11 +193,11 @@ - - def test_basic_conversion_from_string(self): - expected = u'some title{0}=========={0}{0}'.format(os.linesep) -- received = pypandoc.convert('#some title', 'rst', format='md') -+ received = pypandoc.convert('# some title', 'rst', format='md') - self.assertEqualExceptForNewlineEnd(expected, received) - - expected = u'some title{0}=========={0}{0}'.format(os.linesep) -- received = pypandoc.convert_text('#some title', 'rst', format='md') -+ received = pypandoc.convert_text('# some title', 'rst', format='md') - self.assertEqualExceptForNewlineEnd(expected, received) - - def test_conversion_with_markdown_extensions(self): -@@ -215,16 +215,16 @@ - def test_conversion_from_markdown_with_extensions(self): - input = u'~~strike~~' - expected_with_extension = u'

strike

' -- expected_without_extension = u'

strike

' -+ #expected_without_extension = u'

strike

' - received_with_extension = pypandoc.convert(input, 'html', format=u'markdown+strikeout') -- received_without_extension = pypandoc.convert(input, 'html', format=u'markdown-strikeout') -+ #received_without_extension = pypandoc.convert(input, 'html', format=u'markdown-strikeout') - self.assertEqualExceptForNewlineEnd(expected_with_extension, received_with_extension) -- self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension) -+ #self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension) - - def test_basic_conversion_to_file(self): - with closed_tempfile('.rst',) as file_name: - expected = u'some title{0}=========={0}{0}'.format(os.linesep) -- received = pypandoc.convert('#some title\n', to='rst', format='md', outputfile=file_name) -+ received = pypandoc.convert('# some title\n', to='rst', format='md', outputfile=file_name) - self.assertEqualExceptForNewlineEnd("", received) - with io.open(file_name) as f: - written = f.read() -@@ -232,7 +232,7 @@ - - # to odf does not work without a file - def f(): -- pypandoc.convert('#some title\n', to='odf', format='md', -+ pypandoc.convert('# some title\n', to='odf', format='md', - outputfile=None) - self.assertRaises(RuntimeError, f) - -@@ -313,14 +313,14 @@ - expected = u'some title{0}=========={0}{0}'.format(os.linesep) - # let's just test conversion (to and) from docx, testing e.g. odt - # as well would really be testing pandoc rather than pypandoc -- received = pypandoc.convert('#some title\n', to='docx', format='md', outputfile=file_name) -+ received = pypandoc.convert('# some title\n', to='docx', format='md', outputfile=file_name) - self.assertEqualExceptForNewlineEnd("", received) - received = pypandoc.convert(file_name, to='rst') - self.assertEqualExceptForNewlineEnd(expected, received) - - def test_pdf_conversion(self): - with closed_tempfile('.pdf') as file_name: -- ret = pypandoc.convert_text('#some title\n', to='pdf', format='md', outputfile=file_name) -+ ret = pypandoc.convert_text('# some title\n', to='pdf', format='md', outputfile=file_name) - assert ret == "" - with io.open(file_name, mode='rb') as f: - written = f.read() -@@ -329,21 +329,21 @@ - - def f(): - # needs an outputfile -- pypandoc.convert_text('#some title\n', to='pdf', format='md') -+ pypandoc.convert_text('# some title\n', to='pdf', format='md') - - self.assertRaises(RuntimeError, f) - - # outputfile needs to end in pdf - with closed_tempfile('.WRONG') as file_name: - def f(): -- pypandoc.convert_text('#some title\n', to='pdf', format='md', outputfile=file_name) -+ pypandoc.convert_text('# some title\n', to='pdf', format='md', outputfile=file_name) - - self.assertRaises(RuntimeError, f) - - # no extensions allowed - with closed_tempfile('.pdf') as file_name: - def f(): -- pypandoc.convert_text('#some title\n', to='pdf+somethign', format='md', outputfile=file_name) -+ pypandoc.convert_text('# some title\n', to='pdf+somethign', format='md', outputfile=file_name) - - self.assertRaises(RuntimeError, f) - -@@ -372,7 +372,7 @@ - self.assertRaises(RuntimeError, f, filepath) - - def test_convert_text_with_existing_file(self): -- with closed_tempfile('.md', text='#some title\n') as file_name: -+ with closed_tempfile('.md', text='# some title\n') as file_name: - received = pypandoc.convert_text(file_name, 'rst', format='md') - self.assertTrue("title" not in received) - -@@ -383,7 +383,7 @@ - def test_depreaction_warnings(self): - # convert itself is deprecated... - with assert_produces_warning(DeprecationWarning): -- pypandoc.convert('#some title\n', to='rst', format='md') -+ pypandoc.convert('# some title\n', to='rst', format='md') - - def create_sample_lua(self): - args = [pypandoc.get_pandoc_path(), '--print-default-data-file', 'sample.lua'] diff -Nru pypandoc-1.4+ds0/debian/patches/0004-Workaround-a-problem-with-uppercase-lua-filenames-in-pandoc.patch pypandoc-1.5+ds0/debian/patches/0004-Workaround-a-problem-with-uppercase-lua-filenames-in-pandoc.patch --- pypandoc-1.4+ds0/debian/patches/0004-Workaround-a-problem-with-uppercase-lua-filenames-in-pandoc.patch 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/patches/0004-Workaround-a-problem-with-uppercase-lua-filenames-in-pandoc.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -From 0d12f7d04eb746e41241657afcdb38ebe0af7e0d Mon Sep 17 00:00:00 2001 -From: Jan Schulz -Date: Sun, 29 Apr 2018 19:03:18 +0200 -Subject: [PATCH] Workaround a problem with uppercase lua filenames in pandoc - ---- - tests.py | 39 ++++++++++++++++++++++++--------------- - 1 file changed, 24 insertions(+), 15 deletions(-) - ---- a/tests.py -+++ b/tests.py -@@ -16,19 +16,27 @@ - - - @contextlib.contextmanager --def closed_tempfile(suffix, text=None, dir_name=None): -- if dir_name: -- dir_name = tempfile.mkdtemp(suffix=dir_name) -- with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file: -- file_name = test_file.name -- if text: -- test_file.write(text) -- test_file.flush() -- yield file_name -- if dir_name: -- shutil.rmtree(dir_name, ignore_errors=True) -- else: -- os.remove(file_name) -+def closed_tempfile(suffix, text=None, dir_name=None, check_case=False): -+ file_name = None -+ try: -+ if dir_name: -+ dir_name = tempfile.mkdtemp(suffix=dir_name) -+ -+ with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file: -+ file_name = test_file.name -+ if text: -+ test_file.write(text) -+ test_file.flush() -+ if check_case and file_name != file_name.lower(): -+ # there is a bug in pandoc which can't work with uppercase lua files -+ # https://github.com/jgm/pandoc/issues/4610 -+ raise unittest.SkipTest("pandoc has problems with uppercase filenames, got %s" % file_name) -+ yield file_name -+ finally: -+ if dir_name: -+ shutil.rmtree(dir_name, ignore_errors=True) -+ elif file_name: -+ os.remove(file_name) - - - # Stolen from pandas -@@ -177,7 +185,8 @@ - def test_convert_with_custom_writer(self): - lua_file_content = self.create_sample_lua() - with closed_tempfile('.md', text='# title\n') as file_name: -- with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz") as lua_file_name: -+ with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz", -+ check_case=True) as lua_file_name: - expected = u'

title

{0}'.format(os.linesep) - received = pypandoc.convert_file(file_name, lua_file_name) - self.assertEqualExceptForNewlineEnd(expected, received) diff -Nru pypandoc-1.4+ds0/debian/patches/series pypandoc-1.5+ds0/debian/patches/series --- pypandoc-1.4+ds0/debian/patches/series 2020-01-04 22:40:55.000000000 +0000 +++ pypandoc-1.5+ds0/debian/patches/series 2020-04-18 18:14:01.000000000 +0000 @@ -1,4 +1 @@ 0001-Skip-test-s-that-require-the-network.patch -0002-Fix-parsing-of-unicode-paths-on-non-unicode-locales.patch -0003-Fix-tests-with-newer-pandoc.patch -0004-Workaround-a-problem-with-uppercase-lua-filenames-in-pandoc.patch diff -Nru pypandoc-1.4+ds0/debian/upstream/metadata pypandoc-1.5+ds0/debian/upstream/metadata --- pypandoc-1.4+ds0/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ pypandoc-1.5+ds0/debian/upstream/metadata 2020-04-18 18:14:01.000000000 +0000 @@ -0,0 +1,4 @@ +Bug-Database: https://github.com/bebraw/pypandoc/releases +Repository: https://github.com/bebraw/pypandoc.git +Repository-Browse: https://github.com/bebraw/pypandoc + diff -Nru pypandoc-1.4+ds0/pypandoc/__init__.py pypandoc-1.5+ds0/pypandoc/__init__.py --- pypandoc-1.4+ds0/pypandoc/__init__.py 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/pypandoc/__init__.py 2020-04-13 00:41:24.000000000 +0000 @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- -from __future__ import with_statement, absolute_import, print_function +from __future__ import absolute_import, print_function, with_statement +import os +import re import subprocess import sys +import tempfile import textwrap -import os -import re import warnings -import tempfile - -from .py3compat import string_types, cast_bytes, cast_unicode, urlparse -from pypandoc.pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc +from .pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc +from .py3compat import cast_bytes, cast_unicode, string_types, url2path, urlparse __author__ = u'Juho Vepsäläinen' -__version__ = '1.4' +__version__ = '1.5' __license__ = 'MIT' __all__ = ['convert', 'convert_file', 'convert_text', 'get_pandoc_formats', 'get_pandoc_version', 'get_pandoc_path', @@ -71,7 +70,6 @@ def convert_text(source, to, format, extra_args=(), encoding='utf-8', outputfile=None, filters=None): - """Converts given `source` from `format` to `to`. :param str source: Unicode string or bytes (see encoding) @@ -145,29 +143,27 @@ if source is None or not isinstance(source, string_types): return False - path = False + is_path = False try: - path = os.path.exists(source) + is_path = os.path.exists(source) except UnicodeEncodeError: - source = source.encode('utf-8') - path = os.path.exists(source) - except: - path # still false + is_path = os.path.exists(source.encode('utf-8')) + except: # noqa + # still false + pass - if not path: + if not is_path: # check if it's an URL result = urlparse(source) if result.scheme in ["http", "https"]: - path = True - # unfortunately, pandoc currently doesn't support anything else currently - # https://github.com/jgm/pandoc/issues/319 - # elif result.scheme and result.netloc and result.path: - # # complete uri including one with a network path - # path = True - # elif result.scheme == "file" and result.path: - # path = path = os.path.exists(url2path(source)) + is_path = True + elif result.scheme and result.netloc and result.path: + # complete uri including one with a network path + is_path = True + elif result.scheme == "file" and result.path: + is_path = os.path.exists(url2path(source)) - return path + return is_path def _identify_format_from_path(sourcefile, format): @@ -206,7 +202,7 @@ fmt = formats.get(fmt, fmt) # rst format can have extensions if fmt[:4] == "rest": - fmt = "rst"+fmt[4:] + fmt = "rst" + fmt[4:] return fmt format = normalize_format(format) @@ -227,11 +223,11 @@ file_extension = os.path.splitext(to)[1] if (base_to_format not in to_formats and - base_to_format != "pdf" and # pdf is handled later # noqa: E127 - file_extension != '.lua'): + base_to_format != "pdf" and # pdf is handled later # noqa: E127 + file_extension != '.lua'): raise RuntimeError( 'Invalid output format! Got %s but expected one of these: %s' % ( - base_to_format, ', '.join(to_formats))) + base_to_format, ', '.join(to_formats))) # list from https://github.com/jgm/pandoc/blob/master/pandoc.hs # `[...] where binaries = ["odt","docx","epub","epub3"] [...]` @@ -270,7 +266,7 @@ args += input_file if outputfile: - args.append("--output="+outputfile) + args.append("--output=" + outputfile) args.extend(extra_args) @@ -336,7 +332,7 @@ appending +EXTENSION or -EXTENSION to the format name. Return the base format without any extensions. ''' - return re.split('\+|-', format)[0] + return re.split(r'\+|-', format)[0] def get_pandoc_formats(): @@ -388,8 +384,8 @@ txt = ' '.join(help_text[1:help_text.index('Options:')]) aux = txt.split('Output formats: ') - in_ = re.sub('Input\sformats:\s|\*|\[.*?\]', '', aux[0]).split(',') - out = re.sub('\*|\[.*?\]', '', aux[1]).split(',') + in_ = re.sub(r'Input\sformats:\s|\*|\[.*?\]', '', aux[0]).split(',') + out = re.sub(r'\*|\[.*?\]', '', aux[1]).split(',') return [f.strip() for f in in_], [f.strip() for f in out] @@ -458,17 +454,17 @@ return __pandoc_path -def _ensure_pandoc_path(): +def _ensure_pandoc_path(quiet=False): global __pandoc_path if __pandoc_path is None: included_pandoc = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files", "pandoc") - search_paths = ["pandoc", included_pandoc] + search_paths = ["pandoc", included_pandoc] pf = "linux" if sys.platform.startswith("linux") else sys.platform try: search_paths.append(os.path.join(DEFAULT_TARGET_FOLDER[pf], "pandoc")) - except: + except: # noqa # not one of the know platforms... pass if pf == "linux": @@ -478,6 +474,13 @@ # installed if it's an environment and the environment wasn't activated if pf == "win32": search_paths.append(os.path.join(sys.exec_prefix, "Scripts", "pandoc")) + + # Since this only runs on Windows, use Windows slashes + if os.getenv('ProgramFiles', None): + search_paths.append(os.path.expandvars("${ProgramFiles}\\Pandoc\\Pandoc")) + if os.getenv('ProgramFiles(x86)', None): + search_paths.append(os.path.expandvars("${ProgramFiles(x86)}\\Pandoc\\Pandoc")) + # bin can also be used on windows (conda at leats has it in path), so # include it unconditionally search_paths.append(os.path.join(sys.exec_prefix, "bin", "pandoc")) @@ -486,11 +489,11 @@ # version in some other places. if os.getenv('PYPANDOC_PANDOC', None): search_paths = [os.getenv('PYPANDOC_PANDOC')] + curr_version = [0, 0, 0] for path in search_paths: # Needed for windows and subprocess which can't expand it on it's # own... path = os.path.expanduser(path) - curr_version = [0, 0, 0] version_string = "0.0.0" # print("Trying: %s" % path) try: @@ -499,53 +502,72 @@ # we can't use that path... if os.path.exists(path): # path exist but is not useable -> not executable? - print("Found %s, but not using it because of an error:" % (path), file=sys.stderr) - print(e, file=sys.stderr) + if not quiet: + print("Found %s, but not using it because of an error:" % (path), file=sys.stderr) + print(e, file=sys.stderr) continue version = [int(x) for x in version_string.split(".")] while len(version) < len(curr_version): version.append(0) # print("%s, %s" % (path, version)) - for pos in range(len(curr_version)): - # Only use the new version if it is any bigger... - if version[pos] > curr_version[pos]: - # print("Found: %s" % path) - __pandoc_path = path - curr_version = version - break + # Only use the new version if it is any bigger... + if version > curr_version: + # print("Found: %s" % path) + __pandoc_path = path + curr_version = version if __pandoc_path is None: - if os.path.exists('/usr/local/bin/brew'): - sys.stderr.write(textwrap.dedent("""\ - Maybe try: + # Only print hints if requested + if not quiet: + if os.path.exists('/usr/local/bin/brew'): + sys.stderr.write(textwrap.dedent("""\ + Maybe try: + + brew install pandoc + """)) + elif os.path.exists('/usr/bin/apt-get'): + sys.stderr.write(textwrap.dedent("""\ + Maybe try: + + sudo apt-get install pandoc + """)) + elif os.path.exists('/usr/bin/yum'): + sys.stderr.write(textwrap.dedent("""\ + Maybe try: - brew install pandoc - """)) - elif os.path.exists('/usr/bin/apt-get'): + sudo yum install pandoc + """)) sys.stderr.write(textwrap.dedent("""\ - Maybe try: - - sudo apt-get install pandoc + See http://johnmacfarlane.net/pandoc/installing.html + for installation options """)) - elif os.path.exists('/usr/bin/yum'): sys.stderr.write(textwrap.dedent("""\ - Maybe try: + --------------------------------------------------------------- - sudo yum install pandoc """)) - sys.stderr.write(textwrap.dedent("""\ - See http://johnmacfarlane.net/pandoc/installing.html - for installation options - """)) - sys.stderr.write(textwrap.dedent("""\ - --------------------------------------------------------------- - - """)) raise OSError("No pandoc was found: either install pandoc and add it\n" "to your PATH or or call pypandoc.download_pandoc(...) or\n" "install pypandoc wheels with included pandoc.") +def ensure_pandoc_installed(url=None, targetfolder=None, version="latest", quiet=False, delete_installer=False): + """Try to install pandoc if it isn't installed. + + Parameters are passed to download_pandoc() + + :raises OSError: if pandoc cannot be installed + """ + try: + # Perform the test quietly if asked + _ensure_pandoc_path(quiet=quiet) + + except OSError: + download_pandoc(url=url, targetfolder=targetfolder, version=version, quiet=quiet, delete_installer=delete_installer) + + # Show errors in case of secondary failure + _ensure_pandoc_path(quiet=False) + + # ----------------------------------------------------------------------------- # Internal state management # ----------------------------------------------------------------------------- diff -Nru pypandoc-1.4+ds0/pypandoc/pandoc_download.py pypandoc-1.5+ds0/pypandoc/pandoc_download.py --- pypandoc-1.4+ds0/pypandoc/pandoc_download.py 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/pypandoc/pandoc_download.py 2020-04-13 00:41:24.000000000 +0000 @@ -1,20 +1,19 @@ # -*- coding: utf-8 -*- -import sys import os -import shutil -import tempfile import os.path -import subprocess import platform import re +import shutil +import subprocess +import sys +import tempfile try: from urllib.request import urlopen except ImportError: from urllib import urlopen - DEFAULT_TARGET_FOLDER = { "win32": "~\\AppData\\Local\\Pandoc", "linux": "~/bin", @@ -39,7 +38,7 @@ """ # url to pandoc download page url = "https://github.com/jgm/pandoc/releases/" + \ - ("tag/" if version != "latest" else "") + version + ("tag/" if version != "latest" else "") + version # read the HTML content response = urlopen(url) content = response.read() @@ -59,19 +58,18 @@ # py26 don't like dict comprehension. Use this one instead when py26 support is dropped # pandoc_urls = {ext2platform[url_frag[-3:]]: ("https://github.com" + url_frag) for url_frag in pandoc_urls_list} pandoc_urls = dict((ext2platform[ - url_frag[-3:]], ("https://github.com" + url_frag)) for url_frag in pandoc_urls_list) + url_frag[-3:]], ("https://github.com" + url_frag)) for url_frag in pandoc_urls_list) return pandoc_urls, version def _make_executable(path): mode = os.stat(path).st_mode - mode |= (mode & 0o444) >> 2 # copy R bits to X + mode |= (mode & 0o444) >> 2 # copy R bits to X print("* Making %s executeable..." % (path)) os.chmod(path, mode) def _handle_linux(filename, targetfolder): - print("* Unpacking %s to tempfolder..." % (filename)) tempfolder = tempfile.mkdtemp() @@ -82,7 +80,9 @@ cmd = ["ar", "x", filename] # if only 3.5 is supported, should be `run(..., check=True)` subprocess.check_call(cmd) - cmd = ["tar", "xzf", "data.tar.gz"] + files = os.listdir(".") + archive_name = next(x for x in files if x.startswith('data.tar')) + cmd = ["tar", "xf", archive_name] subprocess.check_call(cmd) # pandoc and pandoc-citeproc are in ./usr/bin subfolder for exe in ["pandoc", "pandoc-citeproc"]: @@ -149,7 +149,7 @@ print("* Done.") -def download_pandoc(url=None, targetfolder=None, version="latest"): +def download_pandoc(url=None, targetfolder=None, version="latest", quiet=False, delete_installer=False, download_folder=None): """Download and unpack pandoc Downloads prebuild binaries for pandoc from `url` and unpacks it into @@ -160,28 +160,40 @@ the latest available release at the time pypandoc was released. :param str targetfolder: directory, where the binaries should be installed - to. If no `targetfolder` is give, uses a platform specific user + to. If no `targetfolder` is given, uses a platform specific user location: `~/bin` on Linux, `~/Applications/pandoc` on Mac OS X, and `~\\AppData\\Local\\Pandoc` on Windows. + + :param str download_folder: Directory, where the installer should download files before unpacking + to the target folder. If no `download_folder` is given, uses the current directory. example: `/tmp/`, `/tmp` """ - # get pandoc_urls - pandoc_urls, _ = _get_pandoc_urls(version) + if quiet: + sys.stdout = open(os.devnull, 'w') pf = sys.platform - # compatibility with py3 - if pf.startswith("linux"): - pf = "linux" - if platform.architecture()[0] != "64bit": - raise RuntimeError("Linux pandoc is only compiled for 64bit.") - - if pf not in pandoc_urls: - raise RuntimeError("Can't handle your platform (only Linux, Mac OS X, Windows).") - if url is None: + # compatibility with py3 + if pf.startswith("linux"): + pf = "linux" + if platform.architecture()[0] != "64bit": + raise RuntimeError("Linux pandoc is only compiled for 64bit.") + + # get pandoc_urls + pandoc_urls, _ = _get_pandoc_urls(version) + if pf not in pandoc_urls: + raise RuntimeError("Can't handle your platform (only Linux, Mac OS X, Windows).") + url = pandoc_urls[pf] filename = url.split("/")[-1] + + if download_folder is not None: + if download_folder.endswith('/'): + download_folder = download_folder[:-1] + + filename = os.path.expanduser(download_folder) + '/' + filename + if os.path.isfile(filename): print("* Using already downloaded file %s" % (filename)) else: @@ -205,3 +217,7 @@ assert unpack is not None, "Can't handle download, only Linux, Windows and OS X are supported." unpack(filename, targetfolder) + if delete_installer: + os.remove(filename) + if quiet: + sys.stdout = sys.__stdout__ diff -Nru pypandoc-1.4+ds0/pypandoc/py3compat.py pypandoc-1.5+ds0/pypandoc/py3compat.py --- pypandoc-1.4+ds0/pypandoc/py3compat.py 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/pypandoc/py3compat.py 2020-04-13 00:41:24.000000000 +0000 @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- + from __future__ import with_statement -import sys import locale +import sys # compat code from IPython py3compat.py and encoding.py, which is licensed under the terms of the # Modified BSD License (also known as New or Revised or 3-Clause BSD) @@ -50,10 +51,12 @@ from urllib.parse import urljoin, urlparse from urllib.request import pathname2url, url2pathname - def path2url(path): + + def path2url(path): # noqa: E303 return urljoin('file:', pathname2url(path)) - def url2path(url): + + def url2path(url): # noqa: E303 return url2pathname(urlparse(url).path) else: @@ -65,8 +68,10 @@ from urlparse import urljoin, urlparse import urllib - def path2url(path): + + def path2url(path): # noqa: E303 return urljoin('file:', urllib.pathname2url(path)) - def url2path(url): + + def url2path(url): # noqa: E303 return urllib.url2pathname(urlparse(url).path) diff -Nru pypandoc-1.4+ds0/README.md pypandoc-1.5+ds0/README.md --- pypandoc-1.4+ds0/README.md 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/README.md 2020-04-13 00:41:24.000000000 +0000 @@ -15,7 +15,7 @@ ## Installation Pypandoc uses pandoc, so it needs an available installation of pandoc. For some common cases -(wheels, conda packages), pypandoc already includes pandoc (and pandoc-citeproc) in it's +(wheels, conda packages), pypandoc already includes pandoc (and pandoc-citeproc) in its prebuilt package. If pandoc is already installed (i.e. pandoc is in the `PATH`), pypandoc uses the version with the @@ -82,8 +82,8 @@ - Machine with Haskell: `cabal-install pandoc` - Windows: There is an installer available [here](https://pandoc.org/installing.html) -- [FreeBSD port](https://www.freshports.org/textproc/pandoc/) - - Or see [Pandoc - Installing pandoc](https://pandoc.org/installing.html) +- [FreeBSD with pkg:](https://www.freshports.org/textproc/hs-pandoc/) `pkg install hs-pandoc` +- Or see [Pandoc - Installing pandoc](https://pandoc.org/installing.html) Be aware that not all install mechanisms put pandoc in the `PATH`, so you either have to change the `PATH` yourself or set the full `PATH` to pandoc in @@ -121,7 +121,7 @@ # alternatively you could just pass some string. In this case you need to # define the input format: -output = pypandoc.convert_text('#some title', 'rst', format='md') +output = pypandoc.convert_text('# some title', 'rst', format='md') # output == 'some title\r\n==========\r\n\r\n' ``` @@ -162,11 +162,11 @@ filters = ['pandoc-citeproc'] pdoc_args = ['--mathjax', '--smart'] -output = pd.convert_file(source=filename, - to='html5', - format='md', - extra_args=pdoc_args, - filters=filters) +output = pypandoc.convert_file(filename, + to='html5', + format='md', + extra_args=pdoc_args, + filters=filters) ``` Please pass any filters in as a list and not as a string. @@ -248,7 +248,9 @@ * [Paul Osborne](https://github.com/posborne) - Don't require pandoc to install pypandoc. * [Felix Yan](https://github.com/felixonmars) - Added installation instructions for Arch Linux. * [Kolen Cheung](https://github.com/ickc) - Implement `_get_pandoc_urls` for installing arbitrary version as well as the latest version of pandoc. Minor: README, Travis, setup.py. - +* [Rebecca Heineman](https://github.com/burgerbecky) - Added scanning code for finding pandoc in Windows +* [Andrew Barraford](https://github.com/abarrafo) - Download destination. + ## License Pypandoc is available under MIT license. See LICENSE for more details. Pandoc itself is [available under the GPL2 license](https://github.com/jgm/pandoc/blob/master/COPYING.md). diff -Nru pypandoc-1.4+ds0/setup.py pypandoc-1.5+ds0/setup.py --- pypandoc-1.4+ds0/setup.py 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/setup.py 2020-04-13 00:41:24.000000000 +0000 @@ -6,21 +6,16 @@ import sys import os import os.path +import io try: from urllib.request import urlopen except ImportError: from urllib import urlopen -try: - long_description = pypandoc.convert('README.md', 'rst') - long_description = long_description.replace("\r","") -except OSError as e: - print("\n\n!!! pandoc not found, long_description is bad, don't upload this to PyPI !!!\n\n") - import io - # pandoc is not installed, fallback to using raw contents - with io.open('README.md', encoding="utf-8") as f: - long_description = f.read() + +with io.open('README.md', encoding="utf-8") as f: + long_description = f.read() @@ -87,7 +82,8 @@ license = 'MIT', description = 'Thin wrapper for pandoc.', long_description = long_description, - author = module.__author__, + long_description_content_type='text/markdown', + author = module.__author__.encode('utf8'), author_email = 'bebraw@gmail.com', packages = ['pypandoc'], package_data={'pypandoc': ['files/*']}, @@ -103,12 +99,11 @@ 'Topic :: Text Processing', 'Topic :: Text Processing :: Filters', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy' ], diff -Nru pypandoc-1.4+ds0/tests.py pypandoc-1.5+ds0/tests.py --- pypandoc-1.4+ds0/tests.py 2017-04-22 11:32:05.000000000 +0000 +++ pypandoc-1.5+ds0/tests.py 2020-04-13 00:41:24.000000000 +0000 @@ -1,34 +1,42 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import unittest -import tempfile -import pypandoc -from pypandoc.py3compat import unicode_type, string_types, path2url -import os +import contextlib import io +import os +import shutil +import subprocess import sys +import tempfile +import unittest import warnings -import contextlib -import shutil -import subprocess +import pypandoc +from pypandoc.py3compat import path2url, string_types, unicode_type @contextlib.contextmanager -def closed_tempfile(suffix, text=None, dir_name=None): - if dir_name: - dir_name = tempfile.mkdtemp(suffix=dir_name) - with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file: - file_name = test_file.name - if text: - test_file.write(text) - test_file.flush() - yield file_name - if dir_name: - shutil.rmtree(dir_name, ignore_errors=True) - else: - os.remove(file_name) +def closed_tempfile(suffix, text=None, dir_name=None, check_case=False): + file_name = None + try: + if dir_name: + dir_name = tempfile.mkdtemp(suffix=dir_name) + + with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file: + file_name = test_file.name + if text: + test_file.write(text) + test_file.flush() + if check_case and file_name != file_name.lower(): + # there is a bug in pandoc which can't work with uppercase lua files + # https://github.com/jgm/pandoc/issues/4610 + raise unittest.SkipTest("pandoc has problems with uppercase filenames, got %s" % file_name) + yield file_name + finally: + if dir_name: + shutil.rmtree(dir_name, ignore_errors=True) + elif file_name: + os.remove(file_name) # Stolen from pandas @@ -74,8 +82,9 @@ for m in clear: try: m.__warningregistry__.clear() - except: - pass + except Exception as e: + # ignore... + print(str(e)) saw_warning = False warnings.simplefilter(filter_level) @@ -92,11 +101,11 @@ DeprecationWarning)): from inspect import getframeinfo, stack caller = getframeinfo(stack()[2][0]) - msg = ("Warning not set with correct stacklevel. " - "File where warning is raised: {0} != {1}. " - "Warning message: {2}".format( - actual_warning.filename, caller.filename, - actual_warning.message)) + msg = (("Warning not set with correct stacklevel. " + + "File where warning is raised: {0} != {1}. " + + "Warning message: {2}").format( + actual_warning.filename, caller.filename, + actual_warning.message)) assert actual_warning.filename == caller.filename, msg else: extra_warnings.append(actual_warning.category.__name__) @@ -134,57 +143,60 @@ self.assertTrue(isinstance(version, pypandoc.string_types)) major = int(version.split(".")[0]) # according to http://pandoc.org/releases.html there were only two versions 0.x ... - self.assertTrue(major in [0, 1]) + self.assertTrue(major in [0, 1, 2]) def test_converts_valid_format(self): - self.assertEqualExceptForNewlineEnd(pypandoc.convert("ok", format='md', to='rest'), 'ok') + self.assertEqualExceptForNewlineEnd(pypandoc.convert_text("ok", format='md', to='rest'), 'ok') def test_does_not_convert_to_invalid_format(self): def f(): - pypandoc.convert("ok", format='md', to='invalid') + pypandoc.convert_text("ok", format='md', to='invalid') + self.assertRaises(RuntimeError, f) def test_does_not_convert_from_invalid_format(self): def f(): - pypandoc.convert("ok", format='invalid', to='rest') + pypandoc.convert_text("ok", format='invalid', to='rest') + self.assertRaises(RuntimeError, f) def test_basic_conversion_from_file(self): - with closed_tempfile('.md', text='#some title\n') as file_name: + with closed_tempfile('.md', text='# some title\n') as file_name: expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert(file_name, 'rst') + received = pypandoc.convert_file(file_name, 'rst') self.assertEqualExceptForNewlineEnd(expected, received) + @unittest.skipIf(sys.platform.startswith("win"), "File based urls do not work on windows: " + "https://github.com/jgm/pandoc/issues/4613") def test_basic_conversion_from_file_url(self): - # this currently doesn't work: https://github.com/jgm/pandoc/issues/3196 - return - with closed_tempfile('.md', text='#some title\n') as file_name: + with closed_tempfile('.md', text='# some title\n') as file_name: expected = u'some title{0}=========={0}{0}'.format(os.linesep) # this keeps the : (which should be '|' on windows but pandoc # doesn't like it file_url = path2url(file_name) assert pypandoc._identify_path(file_url) - received = pypandoc.convert(file_url, 'rst') + received = pypandoc.convert_file(file_url, 'rst') self.assertEqualExceptForNewlineEnd(expected, received) def test_basic_conversion_from_http_url(self): url = 'https://raw.githubusercontent.com/bebraw/pypandoc/master/README.md' - received = pypandoc.convert(url, 'html') + received = pypandoc.convert_file(url, 'html') assert "GPL2 license" in received def test_convert_with_custom_writer(self): lua_file_content = self.create_sample_lua() - with closed_tempfile('.md', text='#title\n') as file_name: - with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz") as lua_file_name: + with closed_tempfile('.md', text='# title\n') as file_name: + with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz", + check_case=True) as lua_file_name: expected = u'

title

{0}'.format(os.linesep) received = pypandoc.convert_file(file_name, lua_file_name) self.assertEqualExceptForNewlineEnd(expected, received) def test_basic_conversion_from_file_with_format(self): - with closed_tempfile('.md', text='#some title\n') as file_name: + with closed_tempfile('.md', text='# some title\n') as file_name: expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert(file_name, 'rst', format='md') + received = pypandoc.convert_file(file_name, 'rst', format='md') self.assertEqualExceptForNewlineEnd(expected, received) received = pypandoc.convert_file(file_name, 'rst', format='md') @@ -192,38 +204,37 @@ def test_basic_conversion_from_string(self): expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert('#some title', 'rst', format='md') + received = pypandoc.convert_text('# some title', 'rst', format='md') self.assertEqualExceptForNewlineEnd(expected, received) expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert_text('#some title', 'rst', format='md') + received = pypandoc.convert_text('# some title', 'rst', format='md') self.assertEqualExceptForNewlineEnd(expected, received) def test_conversion_with_markdown_extensions(self): input = 'strike' expected_with_extension = u'~~strike~~' expected_without_extension = u'strike' - received_with_extension = pypandoc.convert(input, 'markdown+strikeout', + received_with_extension = pypandoc.convert_text(input, 'markdown+strikeout', format='html') - received_without_extension = pypandoc.convert(input, + received_without_extension = pypandoc.convert_text(input, 'markdown-strikeout', format='html') self.assertEqualExceptForNewlineEnd(expected_with_extension, received_with_extension) self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension) def test_conversion_from_markdown_with_extensions(self): + # Aparently without the extension, ~~ gets turned into different code + # depending on the pandoc version. So we do not test for that anymore... input = u'~~strike~~' expected_with_extension = u'

strike

' - expected_without_extension = u'

strike

' - received_with_extension = pypandoc.convert(input, 'html', format=u'markdown+strikeout') - received_without_extension = pypandoc.convert(input, 'html', format=u'markdown-strikeout') + received_with_extension = pypandoc.convert_text(input, 'html', format=u'markdown+strikeout') self.assertEqualExceptForNewlineEnd(expected_with_extension, received_with_extension) - self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension) def test_basic_conversion_to_file(self): - with closed_tempfile('.rst',) as file_name: + with closed_tempfile('.rst', ) as file_name: expected = u'some title{0}=========={0}{0}'.format(os.linesep) - received = pypandoc.convert('#some title\n', to='rst', format='md', outputfile=file_name) + received = pypandoc.convert_text('# some title\n', to='rst', format='md', outputfile=file_name) self.assertEqualExceptForNewlineEnd("", received) with io.open(file_name) as f: written = f.read() @@ -231,14 +242,15 @@ # to odf does not work without a file def f(): - pypandoc.convert('#some title\n', to='odf', format='md', + pypandoc.convert_text('# some title\n', to='odf', format='md', outputfile=None) + self.assertRaises(RuntimeError, f) def test_conversion_with_citeproc_filter(self): # we just want to get a temp file name, where we can write to filters = ['pandoc-citeproc'] - written = pypandoc.convert('./filter_test.md', to='html', format='md', + written = pypandoc.convert_file('./filter_test.md', to='html', format='md', outputfile=None, filters=filters) import re as re # only properly converted file will have this in it @@ -250,7 +262,7 @@ # make sure that it splits the filter line for filters in ['pandoc-citeproc', u'pandoc-citeproc']: - written = pypandoc.convert('./filter_test.md', to='html', format='md', + written = pypandoc.convert_file('./filter_test.md', to='html', format='md', outputfile=None, filters=filters) # only properly converted file will have this in it found = re.search(r'Fenner', written) @@ -262,7 +274,7 @@ def test_conversion_with_empty_filter(self): # we just want to get a temp file name, where we can write to filters = '' - written = pypandoc.convert('./filter_test.md', to='html', format='md', + written = pypandoc.convert_file('./filter_test.md', to='html', format='md', outputfile=None, filters=filters) import re as re # This should not use the pandoc-citeproc module and will not find the @@ -275,35 +287,39 @@ def test_conversion_error(self): # pandoc dies on wrong commandline arguments def f(): - pypandoc.convert('

Primary Heading

', 'md', format='html', extra_args=["--blah"]) + pypandoc.convert_text('

Primary Heading

', 'md', format='html', extra_args=["--blah"]) + self.assertRaises(RuntimeError, f) def test_unicode_input(self): # make sure that pandoc always returns unicode and does not mishandle it expected = u'üäöîôû{0}======{0}{0}'.format(os.linesep) - written = pypandoc.convert(u'

üäöîôû

', 'md', format='html') + written = pypandoc.convert_text(u'

üäöîôû

', 'md', format='html') self.assertTrue(isinstance(written, unicode_type)) self.assertEqualExceptForNewlineEnd(expected, written) bytes = u'

üäöîôû

'.encode("utf-8") - written = pypandoc.convert(bytes, 'md', format='html') + written = pypandoc.convert_text(bytes, 'md', format='html') self.assertEqualExceptForNewlineEnd(expected, written) self.assertTrue(isinstance(written, unicode_type)) # Only use german umlauts in th next test, as iso-8859-15 covers that expected = u'üäö€{0}===={0}{0}'.format(os.linesep) bytes = u'

üäö€

'.encode("iso-8859-15") + # Without encoding, this fails as we expect utf-8 per default def f(): - pypandoc.convert(bytes, 'md', format='html') + pypandoc.convert_text(bytes, 'md', format='html') + self.assertRaises(RuntimeError, f) def f(): # we have to use something which interprets '\xa4', so latin and -1 does not work :-/ - pypandoc.convert(bytes, 'md', format='html', encoding="utf-16") + pypandoc.convert_text(bytes, 'md', format='html', encoding="utf-16") + self.assertRaises(RuntimeError, f) # with the right encoding it should work... - written = pypandoc.convert(bytes, 'md', format='html', encoding="iso-8859-15") + written = pypandoc.convert_text(bytes, 'md', format='html', encoding="iso-8859-15") self.assertEqualExceptForNewlineEnd(expected, written) self.assertTrue(isinstance(written, unicode_type)) @@ -312,14 +328,14 @@ expected = u'some title{0}=========={0}{0}'.format(os.linesep) # let's just test conversion (to and) from docx, testing e.g. odt # as well would really be testing pandoc rather than pypandoc - received = pypandoc.convert('#some title\n', to='docx', format='md', outputfile=file_name) + received = pypandoc.convert_text('# some title\n', to='docx', format='md', outputfile=file_name) self.assertEqualExceptForNewlineEnd("", received) - received = pypandoc.convert(file_name, to='rst') + received = pypandoc.convert_file(file_name, to='rst') self.assertEqualExceptForNewlineEnd(expected, received) def test_pdf_conversion(self): with closed_tempfile('.pdf') as file_name: - ret = pypandoc.convert_text('#some title\n', to='pdf', format='md', outputfile=file_name) + ret = pypandoc.convert_text('# some title\n', to='pdf', format='md', outputfile=file_name) assert ret == "" with io.open(file_name, mode='rb') as f: written = f.read() @@ -328,21 +344,21 @@ def f(): # needs an outputfile - pypandoc.convert_text('#some title\n', to='pdf', format='md') + pypandoc.convert_text('# some title\n', to='pdf', format='md') self.assertRaises(RuntimeError, f) # outputfile needs to end in pdf with closed_tempfile('.WRONG') as file_name: def f(): - pypandoc.convert_text('#some title\n', to='pdf', format='md', outputfile=file_name) + pypandoc.convert_text('# some title\n', to='pdf', format='md', outputfile=file_name) self.assertRaises(RuntimeError, f) # no extensions allowed with closed_tempfile('.pdf') as file_name: def f(): - pypandoc.convert_text('#some title\n', to='pdf+somethign', format='md', outputfile=file_name) + pypandoc.convert_text('# some title\n', to='pdf+somethign', format='md', outputfile=file_name) self.assertRaises(RuntimeError, f) @@ -359,30 +375,24 @@ ] def f(filepath): - pypandoc.convert(filepath, 'rst') - - for filepath in files: - self.assertRaises(RuntimeError, f, filepath) - - def f(filepath): pypandoc.convert_file(filepath, 'rst') for filepath in files: self.assertRaises(RuntimeError, f, filepath) def test_convert_text_with_existing_file(self): - with closed_tempfile('.md', text='#some title\n') as file_name: + with closed_tempfile('.md', text='# some title\n') as file_name: received = pypandoc.convert_text(file_name, 'rst', format='md') self.assertTrue("title" not in received) # The following is a problematic case - received = pypandoc.convert(file_name, 'rst', format='md') + received = pypandoc.convert_file(file_name, 'rst', format='md') self.assertTrue("title" in received) def test_depreaction_warnings(self): # convert itself is deprecated... with assert_produces_warning(DeprecationWarning): - pypandoc.convert('#some title\n', to='rst', format='md') + pypandoc.convert('# some title\n', to='rst', format='md') def create_sample_lua(self): args = [pypandoc.get_pandoc_path(), '--print-default-data-file', 'sample.lua'] @@ -390,7 +400,7 @@ out, err = p.communicate() return out.decode('utf-8') - def assertEqualExceptForNewlineEnd(self, expected, received): + def assertEqualExceptForNewlineEnd(self, expected, received): # noqa # output written to a file does not seem to have os.linesep # handle everything here by replacing the os linesep by a simple \n expected = expected.replace(os.linesep, "\n") @@ -398,6 +408,7 @@ self.assertEqual(expected.rstrip('\n'), received.rstrip('\n')) -suite = unittest.TestLoader().loadTestsFromTestCase(TestPypandoc) -ret = unittest.TextTestRunner(verbosity=2).run(suite) -sys.exit(0 if ret.wasSuccessful() else 1) +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(TestPypandoc) + ret = unittest.TextTestRunner(verbosity=2).run(suite) + sys.exit(0 if ret.wasSuccessful() else 1)