[Pyrex] Test case for Pyrex and Cython

David McNab rebirth at orcon.net.nz
Sun Nov 25 21:58:35 CET 2007


On Sun, 2007-11-25 at 10:11 -0800, Jim Kleckner wrote:
> This test case showcases two problems, one with Pyrex and one
> with Cython.  I'm motivated by a problem that is causing a
> segfault and wanted to compare the behavior of Pyrex vs. Cython
> to try to narrow down the source of it.  I'm finding it
> difficult to switch between them.

Use of package hierarchies does make it difficult to switch.

I downloaded and tried your example, and (as with my own code before)
found it impossible to get the Cython version to build, import and work
UNLESS I put the .pyx and .pxd files into their respective places into
the module directory tree, and skipped out on the fully qualified module
names in the filenames.

I hacked your example, so that I now have:

testcimport/
   __init__.py
   module.pxd
   module.pyx

Also, changed setup.py accordingly, and added 'packages=["testcimport"]'
to the final setup() call, and everything works great.

This whole problem of module hierarchy layout, and (IMHO) Cython's more
elegant approach, and especially Pyrex's segfaults and stack corruption
when loading three or more modules from a package hierarchy, have pushed
me into using Cython full-time, at least on this project.

What I find is that Cython is not backward compatible with Pyrex with
respect to dotted-name-filenames. Take out the dotted names, rename the
files to their leaf names, stick 'em in a directory tree just like you
would with regular python files, commit to using Cython, and you
shouldn't have any problems.

Hope this helps. If not, study the wiki page more carefully, maybe even
download DVEdit and look at the layout. If you get really stuck, give me
another yell.

Good luck.

Cheers
David


> 
> To run the test, change directory to pathtest and type ./runtest
> from the prompt.  This script will attempt to build the
> testcimport extension with both Pyrex and Cython and run a
> trivial test of it.
> 
> The pyx and pxd file conventions use the recommendation of Pyrex
> of including the package name ("testcimport") in the file name.
> Cython could relax those restrictions but here I'm trying to
> sort out other issues.
> 
> Note that using Pyrex, the testcimport/module.dll appears to be
> created properly and testit.py is able to "import module" and
> invoke the functions.  However, "import testcimport.module"
> fails.
> 
> Note that using Cython, the type name is not found and the
> extension fails to compile.
> 
> These tests were performed with versions:
>      Pyrex 0.9.6.3 with a setup.py patch from the email list
>      Cython 0.9.6.9
> 
> David, given your foray into the wilds of hierarchy and
> packaging of Cython, would you mind taking a look at this?
> 
> I've uploaded the test case as a zip attachment to the wiki page
> that David created here:
>   http://wiki.cython.org/PackageHierarchy
> 
> 
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex




More information about the Pyrex mailing list