Bug 2245645

Summary: python-cython0.29 fails to build with Python 3.13: ModuleNotFoundError: No module named 'cgi'
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-cython0.29Assignee: Miro Hrončok <mhroncok>
Status: CLOSED DUPLICATE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: code, ksurma, mhroncok, python-packagers-sig
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-12-11 16:53:04 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2244399, 2246145    
Bug Blocks: 2244836    

Description Karolina Surma 2023-10-23 12:07:32 UTC
python-cython0.29 fails to build with Python 3.13.0a1.

Traceback (most recent call last):
  File "/builddir/build/BUILD/cython-0.29.35/setup.py", line 228, in <module>
    setup(
  File "/usr/lib/python3.13/site-packages/setuptools/__init__.py", line 103, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.13/site-packages/setuptools/dist.py", line 989, in run_command
    super().run_command(command)
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/command/build.py", line 131, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.13/site-packages/setuptools/dist.py", line 989, in run_command
    super().run_command(command)
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
    cmd_obj.ensure_finalized()
  File "/usr/lib/python3.13/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized
    self.finalize_options()
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Distutils/build_ext.py", line 20, in finalize_options
    self.distribution.ext_modules[:] = cythonize(
                                       ^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Build/Dependencies.py", line 971, in cythonize
    ctx = c_options.create_context()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Main.py", line 600, in create_context
    return Context(self.include_path, self.compiler_directives,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Main.py", line 80, in __init__
    from . import Builtin, CythonScope
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/CythonScope.py", line 5, in <module>
    from .UtilityCode import CythonUtilityCode
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/UtilityCode.py", line 3, in <module>
    from .TreeFragment import parse_from_strings, StringParseContext
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/TreeFragment.py", line 17, in <module>
    from .Visitor import VisitorTransform
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Visitor.py", line 17, in <module>
    from . import ExprNodes
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/ExprNodes.py", line 4749, in <module>
    class SliceIndexNode(ExprNode):
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/ExprNodes.py", line 4946, in SliceIndexNode
    get_slice_utility_code = TempitaUtilityCode.load(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Code.py", line 404, in load
    return cls(**kwargs)
           ^^^^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Code.py", line 649, in __init__
    proto = sub_tempita(proto, context, file, name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Compiler/Code.py", line 641, in sub_tempita
    from ..Tempita import sub
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Tempita/__init__.py", line 4, in <module>
    from ._tempita import *
  File "/builddir/build/BUILD/cython-0.29.35/Cython/Tempita/_tempita.py", line 36, in <module>
    import cgi
ModuleNotFoundError: No module named 'cgi'


According to https://docs.python.org/3.13/whatsnew/3.13.html:

PEP 594: Remove the cgi and cgitb modules, deprecated in Python 3.11.

cgi.FieldStorage can typically be replaced with urllib.parse.parse_qsl() for GET and HEAD requests, and the email.message module or multipart PyPI project for POST and PUT.

cgi.parse() can be replaced by calling urllib.parse.parse_qs() directly on the desired query string, except for multipart/form-data input, which can be handled as described for cgi.parse_multipart().

cgi.parse_multipart() can be replaced with the functionality in the email package (e.g. email.message.EmailMessage and email.message.Message) which implements the same MIME RFCs, or with the multipart PyPI project.

cgi.parse_header() can be replaced with the functionality in the email package, which implements the same MIME RFCs. For example, with email.message.EmailMessage:

from email.message import EmailMessage
msg = EmailMessage()
msg['content-type'] = 'application/json; charset="utf8"'
main, params = msg.get_content_type(), msg['content-type'].params

(Contributed by Victor Stinner in gh-104773.)


https://docs.python.org/3.13/whatsnew/3.13.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.13/fedora-rawhide-x86_64/06546776-python-cython0.29/

For all our attempts to build python-cython0.29 with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/package/python-cython0.29/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Miro Hrončok 2023-10-23 12:16:05 UTC
I was hoping we can get rid of this package during the Python 3.13 rebuild.

Neverthelss, if we want to get rid of this:

https://github.com/cython/cython/commit/54b92e3d4f75225c55609076afd2d901be8326d2

part of 0.29.36

Comment 2 Miro Hrončok 2023-10-23 12:18:10 UTC
$ comm -23 <(repoquery -q --repo=koji{,-source} --whatrequires python3-cython  | sort) <(repoquery -q --repo=koji{,-source} --whatrequires python3-cython0.29  | sort)
python-fiona-0:1.9.5-1.fc40.src
python-nipy-1:0.5.0^20231006gite5e063b-4.fc40.src
python-rapidfuzz-0:2.13.7-8.fc39.src
python3-neatdend-0:0.9.2-14.fc40.x86_64

Comment 3 Miro Hrončok 2023-10-23 12:20:20 UTC
Ignore my previous comments, those were the package explicitly requiring cython 3. We need the opposite:

$ comm -13 <(repoquery -q --repo=koji{,-source} --whatrequires python3-cython  | sort) <(repoquery -q --repo=koji{,-source} --whatrequires python3-cython0.29  | sort)
grpc-0:1.48.4-26.fc40.src
libarrow-0:13.0.0-3.fc40.src
MUSIC-0:1.1.16-13.20201002git8c6b77a.fc39.src
python-asyncpg-0:0.28.0-5.fc40.src
python-basemap-0:1.3.8-1.fc40.src
python-cyipopt-0:1.2.0-2.fc40.src
python-httptools-0:0.6.0-1.fc40.src
python-jnius-0:1.3.0-17.fc39.src
python-pandas-0:1.5.3-7.fc39~bootstrap.src
python-pyedflib-0:0.1.36-2.fc40.src
python-pyspike-0:0.7.0-9.fc40.src
python-pyunicorn-0:0.7.0~a1-2.20230730gitmaster.fc40.src
python-rasterio-0:1.3.8-2.fc39.src
python-shapely-0:2.0.1^20230725giteeb51ad-2.fc39.src
python-statsmodels-0:0.14.0-4.fc40.src
python-uvloop-0:0.18.0-1.fc40.src
python3-cangjie-0:1.3-2.fc40.src
rdma-core-0:48.0-1.fc40.src
urh-0:2.9.4-6.fc40.src


So this might actually still be needed :(

Comment 4 Ben Beasley 2023-10-23 14:20:22 UTC
Some of these might fix Cython 3 compatibility in the next few months, but grpc is stuck at 1.48.4 until someone has a chance to drive an update of the protobuf package package to v4 (22.x, 23.x, 24.x…), which is a very far-reaching change. See discussion in https://src.fedoraproject.org/rpms/protobuf/pull-request/25 for a sense of the potential impact and effort involved. Furthermore, grpc upstream still pins Cython even in their master branch. I don’t think this compat package can disappear anytime soon without taking out a huge tree of packages.

Comment 5 Miro Hrončok 2023-11-01 16:43:57 UTC
FTR grpc and libarrow have been successfully ported to Cython 3.

Comment 6 Ben Beasley 2023-11-04 19:29:16 UTC
Just filling in some additional details.

(In reply to Miro Hrončok from comment #3)
> grpc-0:1.48.4-26.fc40.src

As Miro said (and was responsible for), fixed in Rawhide (thanks!):
https://src.fedoraproject.org/rpms/grpc/c/8bf11b8c20d2c54dcf7b88777d7590237b6b0555?branch=rawhide

> libarrow-0:13.0.0-3.fc40.src

As Miro said, looks like this is fixed in Rawhide too:
https://src.fedoraproject.org/rpms/libarrow/c/c3bf13a18d078e053bac1453707cea9f520031a0?branch=rawhide

> MUSIC-0:1.1.16-13.20201002git8c6b77a.fc39.src

Upstream issue: https://github.com/INCF/MUSIC/issues/77

> python-asyncpg-0:0.28.0-5.fc40.src

Upstream issue: https://github.com/MagicStack/asyncpg/issues/1083

> python-basemap-0:1.3.8-1.fc40.src

Note that this package is deprecated upstream in favor of cartopy, but there are a couple of things that still depend on it:

mirrormanager2-statistics-0:1.0.0-1.fc40.noarch
python-pyunicorn-0:0.7.0~a1-2.20230730gitmaster.fc40.src

Note also that upstream doesn’t support Python 3.12 yet:

https://github.com/matplotlib/basemap/commit/ee5860bbbc6c3fbff813d10485bdddbdadf0faf3
https://github.com/matplotlib/basemap/issues/590#issuecomment-1747360186

Still, I just offered a patch:

https://github.com/matplotlib/basemap/pull/593
https://src.fedoraproject.org/rpms/python-basemap/pull-request/6

> python-cyipopt-0:1.2.0-2.fc40.src

Fixed in an unmerged upstream PR,

https://github.com/mechmotum/cyipopt/pull/227

which I’m preparing to patch into Rawhide,

https://src.fedoraproject.org/rpms/python-cyipopt/pull-request/3

> python-httptools-0:0.6.0-1.fc40.src

Still pinned upstream,

https://github.com/MagicStack/httptools/blob/de13727218c8e5855e6299ec2734f7c7b801d4a4/setup.py#L18

and no upstream issue filed.

> python-jnius-0:1.3.0-17.fc39.src

(shrug)

> python-pandas-0:1.5.3-7.fc39~bootstrap.src

Still pinned upstream,

https://github.com/pandas-dev/pandas/blob/c2cdeaf3615ee21a2995ee37e14b35175beaae8f/pyproject.toml#L8

and I found a tracking issue, but it’s not clear that it’s still being updated:

https://github.com/pandas-dev/pandas/issues/34213

> python-pyedflib-0:0.1.36-2.fc40.src
> python-pyspike-0:0.7.0-9.fc40.src
> python-pyunicorn-0:0.7.0~a1-2.20230730gitmaster.fc40.src
> python-rasterio-0:1.3.8-2.fc39.src

(haven’t looked into any of these yet)

> python-shapely-0:2.0.1^20230725giteeb51ad-2.fc39.src

Fixed in Rawhide and F39 with version 2.0.2.

> python-statsmodels-0:0.14.0-4.fc40.src
> python-uvloop-0:0.18.0-1.fc40.src
> python3-cangjie-0:1.3-2.fc40.src
> rdma-core-0:48.0-1.fc40.src
> urh-0:2.9.4-6.fc40.src

(haven’t looked into any of these yet)

Comment 8 Miro Hrončok 2023-11-11 07:53:59 UTC
Ben, I really appreciate your work on this.

Comment 9 Miro Hrončok 2023-11-11 08:17:51 UTC
In https://copr.fedorainfracloud.org/coprs/churchyard/cython-3-forced/builds/ I try to build the rest with Cython 3, so we can at least have the logs.

Comment 10 Karolina Surma 2023-11-13 14:40:26 UTC
I sent downstream/upstream changes where applicable:

https://src.fedoraproject.org/rpms/urh/pull-request/2
https://src.fedoraproject.org/rpms/python3-cangjie/pull-request/3
https://src.fedoraproject.org/rpms/python-pyunicorn/pull-request/3
https://src.fedoraproject.org/rpms/python-httptools/pull-request/6
Also, python-asyncpg actually built with Cython 3.0.5, although with quite a few warnings: https://download.copr.fedorainfracloud.org/results/churchyard/cython-3-forced/fedora-rawhide-x86_64/06629681-python-asyncpg/builder-live.log.gz -- @Ben, are you interested in getting a simple unpinning patch or would you like to take a look/wait for a proper fix?
+sed -i 's/Cython(>=0.29.24,<0.30.0)/Cython(>=3)/' setup.py
+sed -i 's/Cython(>=0.29.24,<3.0.0)/Cython(>=3)/' pyproject.toml

I am yet to look at the failures of the rest of the builds in the copr.

Comment 11 Ben Beasley 2023-11-13 15:00:55 UTC
(In reply to Karolina Surma from comment #10)
> Also, python-asyncpg actually built with Cython 3.0.5, although with quite a
> few warnings:
> https://download.copr.fedorainfracloud.org/results/churchyard/cython-3-
> forced/fedora-rawhide-x86_64/06629681-python-asyncpg/builder-live.log.gz --
> @Ben, are you interested in getting a simple unpinning patch or would you
> like to take a look/wait for a proper fix?
> +sed -i 's/Cython(>=0.29.24,<0.30.0)/Cython(>=3)/' setup.py
> +sed -i 's/Cython(>=0.29.24,<3.0.0)/Cython(>=3)/' pyproject.toml

Thanks for looking at this.

The warnings I see are pre-existing and don’t seem to be related to Cython 3. There are quite a few -Wsign-conversion and -Wconversion warnings that upstream doesn’t seem to care about, plus

  asyncpg/protocol/record/recordobj.c: In function ‘record_dealloc’:
  asyncpg/protocol/record/recordobj.c:101:5: warning: ‘UsingDeprecatedTrashcanMacro’ is deprecated [-Wdeprecated-declarations]
    101 |     Py_TRASHCAN_SAFE_BEGIN(o)
        |     ^~~~~~~~~~~~~~~~~~~~~~

which will have to be patched for Python 3.13.

Furthermore, the tests pass and, based on [1], it looks like upstream has always preemptively pinned/upper-bounded the version of Cython.

I’ll send a PR upstream just in case they want it, and patch out the upper bounds.

[1] https://github.com/MagicStack/asyncpg/commit/deea86cebf69a2b489d5e0bfa8ba5b5a562b5839

Comment 12 Ben Beasley 2023-11-13 15:17:04 UTC
Upstream’s CI passed with Cython 3 as well.

https://github.com/MagicStack/asyncpg/pull/1101

Building for Rawhide: https://koji.fedoraproject.org/koji/taskinfo?taskID=108975634

Comment 13 Karolina Surma 2023-11-14 08:36:35 UTC
I copied out the failure-related parts of the build logs of packages in Copr: https://hackmd.io/DZSb948qSXG9euB9bdDIpg?view

Comment 14 Miro Hrončok 2023-11-14 08:43:56 UTC
I had a look at MUSIC -- the found failure is fixed upstream (for 2 years), but I didn't get too far away, was bitten by what appears to be a Cython regression: https://github.com/cython/cython/issues/5818

Comment 15 Miro Hrončok 2023-11-14 08:53:35 UTC
pyjnius has https://github.com/kivy/pyjnius/commit/fd748e5db48d8e69e4aeab9a2af1400871dff46b -- the Fedora package seems quite outdated as well.

Comment 16 Miro Hrončok 2023-11-14 09:43:49 UTC
(In reply to Miro Hrončok from comment #14)
> I had a look at MUSIC -- the found failure is fixed upstream (for 2 years),
> but I didn't get too far away, was bitten by what appears to be a Cython
> regression: https://github.com/cython/cython/issues/5818

OK,

MUSIC builds fine with:

 - https://github.com/INCF/MUSIC/commit/f007845154d21613935186d0bbd1557ad6c23728
 - https://github.com/cython/cython/commit/bbbe428ee5c52dd8fad10b0ee3bb2e33b5a8918c
 - openmpi 4

It FTBS with openmpi 5 (regardless of Cython version). I'd count this package "fixed" when we'll consider removing Cython 0.29 from Fedora.

Comment 17 Miro Hrončok 2023-12-11 16:53:04 UTC
I don't see Cython 0.29 working with Python 3.13, at least not soon.

I've opened a bugzilla to drop it and am closing this one for now.

*** This bug has been marked as a duplicate of bug 2254029 ***