External cython cimports fail in Sage 10.2.beta8

56 views
Skip to first unread message

Edgar Costa

unread,
Oct 29, 2023, 8:00:08 PM10/29/23
to sage-...@googlegroups.com
Hello,

Cythonizing a package, via setuptools, that uses a `from sage.foo cimport bar` seems to no longer work with Sage 10.2.beta8

Here is a minimal example:
sage -pip install git+https://github.com/edgarcosta/pyfib.git@main

Note, that one can also try to install the package without the `from sage.rings.integer cimport Integer`, via
sage -pip install git+https://github.com/edgarcosta/pyfib.git@nosage
and then everything works as expected.

I believe this has something to do with  PEP-420 and the recent upgrade to Cython3.0
https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html#namespace-packages

it gives me the idea that there is something to do with relative imports, but I am not sure.

Any insight would be appreciated, as all my Cython pip installable packages fail exactly the same way.

Cheers,
Edgar

Matthias Koeppe

unread,
Oct 29, 2023, 8:08:19 PM10/29/23
to sage-devel
You'll need sage.misc.package_dir.cython_namespace_package_support

Edgar Costa

unread,
Oct 30, 2023, 12:20:51 PM10/30/23
to sage-...@googlegroups.com
In case someone else stumbles on this, this was my fix:

from Cython.Build import cythonize as cython_cythonize

try:
    from sage.misc.package_dir import cython_namespace_package_support
    def cythonize(*args, **kwargs):
        with cython_namespace_package_support():
            return cython_cythonize(*args, **kwargs)
except ImportError:
    cythonize = cython_cythonize

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/80033da2-a3dd-4aa9-b52d-f0272ab5c5cbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages