rougier / freetype-py

Python binding for the freetype library
Other
298 stars 88 forks source link

python 2 compatibility, and unsighty errors from it #137

Open HinTak opened 3 years ago

HinTak commented 3 years ago

I think I saw the dropping of python 2 support from a while back, but it is a bit disappointing what it now shows:

$ python2 setup.py 
# Will use the system-provided FreeType.
/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/src
<pkg_resources.WorkingSet object at 0x7faf8e46f1d0>
Traceback (most recent call last):
  File "setup.py", line 130, in <module>
    setup_requires=['setuptools_scm'],
  File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 144, in setup
    _install_setup_requires(attrs)
  File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
    dist.fetch_build_eggs(dist.setup_requires)
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 720, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
    replace_conflicting=replace_conflicting
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1065, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1077, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 787, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 684, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 710, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 895, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1163, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1149, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 253, in run_setup
    raise
  File "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 250, in run_setup
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/site-packages/setuptools/sandbox.py", line 45, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/setup.py", line 52, in <module>
    if isinstance(ext, SharedLibrary):
  File "/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/setup.py", line 29, in scm_config
    """Object that describes the library (filename) and how to make it."""
  File "/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/src/setuptools_scm/__init__.py", line 8, in <module>
  File "/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/src/setuptools_scm/config.py", line 6, in <module>
  File "/tmp/easy_install-A4zNzt/setuptools_scm-6.0.1/src/setuptools_scm/utils.py", line 41
    print(*k)
          ^
SyntaxError: invalid syntax

Instead, it should just check python version and abort...

(FWIW, trying to update the python binding to FontVal freetype backend - it is mostly a single script examples/font-diag.py in the fontval-diag branch of my fork).

HinTak commented 3 years ago

Hmm, I just checked the log, there is no explicit reference to not supporting python 2, just that CI / tox wasn't set up to use it.

If python 2 supposedly still works, the message above is definitely very unsighty!

rougier commented 3 years ago

I would be surpeised that python2 still works. What's your suggestion? We try to check if we can still support Pythpn2 (without too much effort) or do we add a specific check?

anthrotype commented 3 years ago

python2 support was dropped in https://github.com/rougier/freetype-py/pull/124

the python_requires=">=3.6" keyword in setup.py should ensure that pip will skip downloading the incompatible package when called from a python2 interpreter

HinTak commented 3 years ago

Okay, I agree we don't need to support python 2; it would be nice if a single message comes out saying "python 2 no longer works" than the whole pile of stuff above.

Otoh, it should not be too much effort to just keep a python-2 branch and only add critical or tested changes to it?

HinTak commented 3 years ago

I think the interior of freetype-py is not particularly python 2/3 specific. The example scripts may be a bigger problem.

That said, I think it is a good idea to leave behind a python 2 branch as "the last known version/revision that works with python 2".

HinTak commented 2 years ago

Actually I found that only two lines needed to be changed for it to work with python 2.7: https://github.com/rougier/freetype-py/tree/py27-branch . All the Cairo and non-graphic examples still works; the matplot-based examples no longer runs on my system mainly because I have uninstalled python 2's matplot binding on my system. This probably was because most of it was written in python 2 then made compatible with python 3, and very little was done as a pure python 3 example.

Both of the lines are to do with setuptools - for those who knows it better, maybe you can just made them conditional.

python_requires=">=3.6" seems to have no effect - maybe I am just old-fashioned: I am just doing python2 setup.py build and python2 setup.py install --user. Do we really need the two scm related lines?

rougier commented 2 years ago

We can simply add a test inside setup.py that'll drop the build/install for python 2 and redirect to last known working version for python 2.7.

HinTak commented 2 years ago

Actually the unsightly error I posted at the beginning is gone by one of the two lines I changed... The other line I changed only removes a non-fatal warning.

rougier commented 2 years ago

Ok. But sooner or later we'll have a real incompatibility and it might be easier to issue a warning that python 2 is no more supported. I guess this can wait next report.