Description
The code base no longer supports Python 2.7.
In of itself, that's not such a bad thing because the sunset of Python 2.7 was two years ago. It's fine to drop support for Python 2.7 at this point.
However, it is a bit of an issue that the current release of pypandoc claims to support Python 2.7 when it does not. If pypandoc is not intended to support Python 2.7 any more, it needs to have the Python 2.7 Trove classifier removed [a] [b], and have python_requires=">=3.6"
set correctly in setup.py (not currently set) and pyproject.toml. This is important so that pip knows which version of pypandoc it can install on any given version of python, and users installing pypandoc on an old version of python will install a valid version of pypandoc that can run on their system.
The changes which were made that are incompatible with Python 2.7 are:
- The use of
FileNotFoundError
(requires python>3), introduced in v1.5 by commit ffe8c52
https://github.com/NicklasTegner/pypandoc/blob/02f94233d3d3d0bf3c4d80e11b858e1cd22a4c0f/pypandoc/pandoc_download.py#L106 - Use of the
typing
module (requires python>=3.5), introduced by commit 2cfcc1e (unreleased)
https://github.com/NicklasTegner/pypandoc/blob/02f94233d3d3d0bf3c4d80e11b858e1cd22a4c0f/pypandoc/pandoc_download.py#L12
https://github.com/NicklasTegner/pypandoc/blob/02f94233d3d3d0bf3c4d80e11b858e1cd22a4c0f/pypandoc/__init__.py#L3-L4
I've gone through the history of pypandoc releases, and the most recent one to run the affected code correctly on Python 2.7 was v1.3.3 (I tested to find this by trying to run the command python -c "import pypandoc; pypandoc.download_pandoc(targetfolder='$PWD/test')"
on Linux).
The bleeding edge version does not install on Python 2.7, with a syntax error caused by type hinting:
File "pypandoc/__init__.py", line 29
def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encoding:str='utf-8',
^
SyntaxError: invalid syntax
Versions 1.6 to 1.7.4 (latest release) produce the error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pypandoc/pandoc_download.py", line 254, in download_pandoc
unpack(filename, targetfolder)
File "pypandoc/pandoc_download.py", line 100, in _handle_linux
except FileNotFoundError:
NameError: global name 'FileNotFoundError' is not defined
Versions 1.4 and 1.5 produce the error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pypandoc/pandoc_download.py", line 207, in download_pandoc
unpack(filename, targetfolder)
File "pypandoc/pandoc_download.py", line 92, in _handle_linux
shutil.copyfile(src, dst)
File "/usr/lib/python2.7/shutil.py", line 96, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/tmp/tmp_eV01E/usr/bin/pandoc-citeproc'
To resolve this, what I propose is to make a hotfix release forked from the latest release (v1.7.4) which re-enables support for Python 2.7 by adding a block to define FileNotFoundError in the preamble of pypandoc/pandoc_download.py as follows:
try:
FileNotFoundError
except NameError:
# Python <3.5
FileNotFoundError = IOError
Alternatively a new release can be made from the master branch, but in that case 2cfcc1e will have to be reverted in order to remove the dependency on the typing module as well.
After this hotfix release, I think Python 2.7 support can be officially dropped, and the minimum python version in setup.py and pyproject.toml bumped up to 3.6 so that pypandoc can make use of all the new features in Python 3. Given that nobody has reported the issue in the 9 months since v1.5 was released until now, Python 2.7 support does not appear to be crucial going forward.