NatLibFi / Annif

Annif is a multi-algorithm automated subject indexing tool for libraries, archives and museums.
https://annif.org
Other
197 stars 41 forks source link

Python 3.11 support #703

Closed osma closed 1 year ago

osma commented 1 year ago

Python 3.11 was released in October 2022. We should aim at supporting it in Annif. Some concrete steps:

  1. Enable running GitHub Actions CI tests under Python 3.11 (most likely in experimental mode i.e. allowed to fail)
  2. Check all the dependencies and see if they work under 3.11
  3. tomllib (PEP 690) is now part of the standard library so we could use that instead of tomli
  4. Fix 3.11 compatibility issues in the Annif codebase, if any

It's quite likely that some libraries we depend on don't yet support 3.11, so there will be a transition period, perhaps with some optional dependencies not working. This happened with 3.10 as well.

Not sure whether this can be done before the 1.0 release, so I'm putting this into the "Long term" milestone for now.

juhoinkinen commented 1 year ago

Omikuji does not have a wheel for Python 3.11, so we should probably request to have it. Previously Omikuji maintainer has responded very promptly (https://github.com/NatLibFi/Annif/issues/589#issuecomment-1139368528).

However, when I tried to install Omikuji by building wheel on Python 3.11 (essentially just having cargo installed and then running pip install), there was an error by milksnake dependency:

...
        File "/tmp/pip-build-env-nmoyebyz/normal/lib/python3.11/site-packages/milksnake/ffi.py", line 8, in <module>
          _directive_re = re.compile(r'^\s*#.*?$(?m)')
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/__init__.py", line 227, in compile
          return _compile(pattern, flags)
                 ^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/__init__.py", line 294, in _compile
          p = _compiler.compile(pattern, flags)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/_compiler.py", line 743, in compile
          p = _parser.parse(p, flags)
              ^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/_parser.py", line 980, in parse
          p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/_parser.py", line 455, in _parse_sub
          itemsappend(_parse(source, state, verbose, nested + 1,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/re/_parser.py", line 841, in _parse
          raise source.error('global flags not at the start '
      re.error: global flags not at the start of the expression at position 9
      [end of output]

A fix for this incompatibility of milksnake for Python 3.11 has been merged, but currently there is no release to include it (see an issue requesting it).

So it's probably better to wait for milksnake release, and only then request Omikuji to have wheel for Python 3.11.

juhoinkinen commented 1 year ago

TensorFlow v2.11.1 does not have wheel for Python 3.11, but v2.12.0 does have. So upgrading to TF v2.12+ should be done (also) for this reason.

However, there was a conflict with TF 2.12.0 and NumPy 1.24: https://github.com/NatLibFi/Annif/pull/683#issuecomment-1481532935. Hopefully soon to be released TF 2.13 is compatible with more recent Numpy (1.25.0 was released Jun 17th).