On Wed, Jun 10, 2009 at 12:13 AM, Robert Bradshaw<[email protected]> wrote: > On Jun 9, 2009, at 11:03 AM, Ondrej Certik wrote: > >> Hi, >> >> I have the following problem -- I have a package hermes2d, with the >> structure: >> >> hermes2d/__init__.py >> hermes2d/_hermes2d.pyx + .pxd >> hermes2d/_forms.pyx >> >> and sometimes (depending on what the users tells cmake) I want to >> build the .so libraries out of the tree and put their paths to >> PYTHONPATH. Things just work as long as remove the file >> hermes2d/__init__.py during the cython compilation. The reason is that >> if I do: >> >> cd hermes2d >> cython _forms.pyx >> >> it produces _forms.c with lines like: >> >> __pyx_ptype_8hermes2d_9_hermes2d_LinSystem = >> __Pyx_ImportType("hermes2d._hermes2d", "LinSystem", sizeof(struct >> __pyx_obj_8hermes2d_9_hermes2d_LinSystem)); if >> (unlikely(!__pyx_ptype_8hermes2d_9_hermes2d_LinSystem)) >> {__pyx_filename = __pyx_f[1]; __pyx_lineno = 292; __pyx_clineno = >> __LINE__; goto __pyx_L1_error;} >> >> Notice the import "hermes2d._hermes2d", which fails if _hermes2d.so is >> out of the tree (e..g somewhere else on the filesystem, even if it's >> in the search path!). If, however I remove the __init__.py, then >> cython generates: >> >> __pyx_ptype_9_hermes2d_LinSystem = __Pyx_ImportType("_hermes2d", >> "LinSystem", sizeof(struct __pyx_obj_9_hermes2d_LinSystem)); if >> (unlikely(!__pyx_ptype_9_hermes2d_LinSystem)) {__pyx_filename = >> __pyx_f[1]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto >> __pyx_L1_error;} >> >> and everything just works, no matter where the file _hermes2d.so >> actually is. >> >> Now my question is -- if I want those .so libraries not to be in the >> tree, am I doing things the right way? E.g. I just have a line: >> >> from _forms import * >> >> in the hermes2d/forms.py >> >> and then people just do "from hermes2d import forms" and things work, >> no matter where the .so files are. But I need some way to force cython >> to just pretend there is no __init__.py in there. Why is cython doing >> this check at all? Does it have any advantages? > > One advantage I see is that you may have two modules named _hermes2d > in different packages that it might have to distinguish. (OK, rare > with that name, but it could happen with more common names). Also, > this way the module path is fully qualified as one would expect.
Ok. So how do you propose I should fix the problem, if I need those .so libraries at different place than the rest of the python source files? Ondrej _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
