Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] namespace packages as in pep 420 cannot be cimported #5335

Open
tornaria opened this issue Mar 24, 2023 · 0 comments
Open

[BUG] namespace packages as in pep 420 cannot be cimported #5335

tornaria opened this issue Mar 24, 2023 · 0 comments

Comments

@tornaria
Copy link
Contributor

Describe the bug

When PACKAGE is a namespace package, then both:

cimport PACKAGE

or

from PACKAGE cimport MODULE

fail at compilation, complaining that PACKAGE.pxd can't be found.

Presumably cython has looked for PACKAGE/__init__.* and PACKAGE.* which are not available for a namespace package.

This was discovered as part of sagemath/sage#35322.

Code to reproduce the behaviour:

  1. Patch the pep420 test in master as follows:
--- a/tests/build/cythonize_pep420_namespace.srctree
+++ b/tests/build/cythonize_pep420_namespace.srctree
@@ -31,9 +31,17 @@ cdef class A:
 
 ######## nsp/m2/b.pyx ########
 
+from nsp.m1 cimport a
 from nsp.m1.a cimport A
+from nsp.m3.c cimport d   ### BROKEN
 from nsp.m3.c.d cimport D
 
+cimport nsp.m1
+cimport nsp.m1.a
+cimport nsp.m3
+cimport nsp.m3.c  ### BROKEN
+cimport nsp.m3.c.d
+
 cdef class B(A):
     pass
 

I added several new tests for the different ways one can cimport modules. All of them work ok, except the two I've marked BROKEN which corresponds to the ones mentioned in the description.

  1. Build and run ./runtests.py cythonize_pep420_namespace, to get:
Error compiling Cython file:
------------------------------------------------------------
...

from nsp.m1 cimport a
from nsp.m1.a cimport A
from nsp.m3.c cimport d
^
------------------------------------------------------------

nsp/m2/b.pyx:4:0: 'nsp/m3/c.pxd' not found
  1. Comment out the first line marked BROKEN above and repeat the test to get:
Error compiling Cython file:
------------------------------------------------------------
...
from nsp.m3.c.d cimport D

cimport nsp.m1
cimport nsp.m1.a
cimport nsp.m3
cimport nsp.m3.c
        ^
------------------------------------------------------------

nsp/m2/b.pyx:10:8: 'nsp/m3/c.pxd' not found
  1. Comment out the second line marked BROKEN, now all tests pass.

Expected behaviour

All tests pass, including the two marked BROKEN.

OS

linux

Python version

3.11.2

Cython version

3.0.0b1+master (2ea4f96)

Additional context

In sagemath we still use 0.29.33, with #2946 backported (see https://github.com/sagemath/sage/blob/develop/build/pkgs/cython/patches/4918.patch) so other uses of namespace packages work ok.

Whatever is the solution, it'd be nice to have it backported to 0.29.x.

It would also be wonderful if 0.29.34 could include #2946.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant