[Pyrex] Getting full package paths in extension __module__ attributes?

Eric Huss e-huss at netmeridian.com
Tue May 1 16:53:44 UTC 2007


>From the second paragraph in the language overview:

If your module is destined to live in a package, the source file name
should include the full dotted name that the module will eventually have.
For example, a module called primes that will be installed in a package
called numbers should have a source file called numbers.primes.pyx. This
will ensure that the __name__ properties of the module and any classes
defined in it are set correctly. If you don't do this, you may find that
pickling doesn't work, among other problems. It also ensures that the
Pyrex compiler has the right idea about the layout of the module
namespace, which can be important when accessing extension types defined
in other modules.

-Eric

On Tue, 1 May 2007, Alex Coventry wrote:

>
> Hi.  I have a file in evolution/hmmer/rind/_F81.pyx, corresponding to an
> extension module with package path evolution.hmmer.rind._F81.  It
> contains an extension type called F81.  The __module__ attribute of the
> F81 type is set to "_F81" rather than the full package path.  I think
> this is causing problems with my attempts to pickle instances of the
> type: The pickling machinery is looking for "_F81" in sys.modules, when
> it should be looking for evolution.hmmer.rind._F81.  I can hack around
> this by creating an empty pure-python extension to F81, which then has
> the correct value in the __module__ attribute, but I was wondering
> whether there might be a cleaner way around this problem.
>
> I am not sure where to fix this, even in the C code.  The _F81.c file
> generated by pyrecx contains a call
>
> Py_InitModule4("_F81", __pyx_methods, __pyx_mdoc,0, PYTHON_API_VERSION);
>
> But changing the "_F81" value to the full package name doesn't seem to
> change the value of the __module__ attribute.
>
> Alex
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>



More information about the Pyrex mailing list