[Cython] distutils extension pxd problem

Dimitri Tcaciuc dtcaciuc at gmail.com
Thu Feb 2 08:12:23 CET 2012


Ok, so I narrowed the problem down to
https://github.com/cython/cython/blob/master/Cython/Compiler/Main.py#L223.
At this point, it looks like if target extension name is `x.y.z`, the
pxd must either be called `x.y.z.pxd` and be located in project root
(I believe this is Pyrex convention?) or be in the exact x/y/z.pxd
directory structure, and each of the parents have to be a package (ie.
contain __init__.[py,pyx,pyd]).

Again, this looks like a problem only if module name is nested. If
this is along the right lines, I'd be happy to make some
clarifications to
http://docs.cython.org/src/userguide/sharing_declarations.html#search-paths-for-definition-files.

It looks like there's a conflict between the Extension name parameter
(which also says where the module gets installed in package tree) and
the name of the actual .so file, which sometimes one needs to
customize (eg. I need to compile x/y/z.pyx to x/y/_z.so since I'd like
to have z.py with some extra bits in them. In this case `cythonize`
seems to ignore the extension name, goes ahead and names the output
`z.so`)

I recon you guys probably had plenty of discussions on this topic. Is
there a general direction where you're taking the whole include/pxd
discovery system or is it staying where it is right now?


Dimitri.


On Wed, Feb 1, 2012 at 4:53 PM, Dimitri Tcaciuc <dtcaciuc at gmail.com> wrote:
> Hey everyone,
>
> I bumped into an issue where my .pyx file doesn't see its matching
> .pxd file. Here's a build test to show the problem If I change my
> target package from `b.a` to just `a`, it works as expected. Running
> `cython src/a.pyx` works as expected as well, but not the Extension.
>
> ----
>
> PYTHON setup.py build_ext --inplace
> PYTHON -c "from b import a"
>
> ######## setup.py ########
>
> from distutils.core import setup
> from distutils.extension import Extension
> from Cython.Distutils import build_ext
>
> ext_modules = [
>    Extension("b.a", ["src/a.pyx"])
> ]
>
> setup(
>    cmdclass = {'build_ext': build_ext},
>    ext_modules = ext_modules
> )
>
> ######## b/__init__.py ########
>
> ######## src/a.pxd ########
>
> cdef class X:
>    cdef object foo
>
> ######## src/a.pyx ########
>
> cdef class X:
>
>    def __cinit__(self):
>        self.foo = 1
>
> x = X()
>
> ----
>
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "a.pyx", line 7, in init b.a (src/a.c:793)
>  File "a.pyx", line 5, in b.a.X.__cinit__ (src/a.c:488)
> AttributeError: 'b.a.X' object has no attribute 'foo'
>
> ----
>
> Any idea what's going on here?
>
> Thanks,
>
>
> Dimitri.


More information about the cython-devel mailing list