-
-
Couldn't load subscription status.
- Fork 1.6k
Description
Describe the bug
When PACKAGE is a namespace package, then both:
cimport PACKAGEor
from PACKAGE cimport MODULEfail 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:
- 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.
- 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
- 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
- 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.