On Wed, Jul 28, 2010 at 10:03 AM, Josh Allen <[email protected]> wrote: > Hello again, > > I'm working on a Python/Cython project with a large number of modules, > several of which I have Cythonized. I have collected all of the modules into > a single package. Attempting to compile these modules has revealed a couple > of potential issues, which I will outline below for a small test case. > > First, the directory layout for the test case, which contains two modules > "foo" and "bar" in a package "bug": > > /bug/__init__.py > /bug/bar.pxd > /bug/bar.py > /bug/foo.pxd > /bug/foo.py > /setup.py > /test.py > > Next, the contents of the files: > > # /bug/foo.py: > class Foo: > def hello(self): > print 'Hello from foo.Foo.hello()' > > # /bug/foo.pxd: > cdef class Foo: > cpdef hello(self) > > # /bug/bar.pxd: > from foo cimport Foo > cdef class Bar: > cdef public Foo foo > cpdef hello(self) > > # /bug/bar.py: > import cython > from foo import Foo > class Bar: > def hello(self): > cython.declare(f=Foo) > f = Foo() > print 'Hello from bar.Bar.hello()' > > # setup.py > from distutils.core import setup > from distutils.extension import Extension > from Cython.Distutils import build_ext > setup( > cmdclass={'build_ext': build_ext}, > ext_modules=[Extension('bug.foo', ['bug/foo.py']), Extension('bug.bar', > ['bug/bar.py'])] > ) > > # test.py > from bug.foo import Foo > from bug.bar import Bar > f = Foo() > f.hello() # Should print 'Hello from Foo.hello()' > b = Bar() > b.hello() # Should print 'Hello from Bar.hello()' > > If I try to compile as is -- by running "python setup.py build_ext > --inplace" from the top-level directory --, Cython fails at the line "from > foo import Foo" in bar.py with the error "Assignment to non-lvalue 'Foo'". > If I remove this line, then everything compiles and runs properly. However, > I need this line to exist in order to run the file in pure Python mode. > > I also tried moving the setup.py file within the bug package, adjusting its > content accordingly, and running from within the bug folder. (This is > probably not a good location for the setup.py file, but I was trying to see > if anything would work.) This also causes Cython to fail, but this time at > the line "cython.declare(f=Foo)" in bar.py with the error "Unknown type". > However, running cython from the console on bar.py while within the bug > directory does produce a valid C file. > > Both of these cases are for Python 2.6.5 and Cython 0.12.1 on Ubuntu 10.04. > I also attempted to try it for the Cython 0.13 beta, but the problem seems > to persist. (Incidentally, is running "cython -V" with the 0.13 beta > supposed to print "Cython version 0.12.1"?)
Hmm... no. Sounds like you're still picking up the old one. > Let me know if there's any other info you need. To help us diagnose the problem, does it persist if you change the extension to .pyx? - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
