If all you can accept some vile hackery, see the attached tarball ;-) .

Python recognizes a PKGNAME directory as a pakage if '__init__.py' is
there, if not, no way. BUT  if '__init__.so' is also there, it loads
'__init__.so' !!! But then the exported module init function in the
dynlib needs to be named initPKGNAME, and "PKGNAME" needs to be passed
to Py_InitModule()

So, Greg, here you have the rules if you want to implement it ;-).

PS: tried only in Py 2.5, this is surely undocumented, and probably it
is in fact some bugy code in CPython's  'import.c' .



On Thu, Oct 30, 2008 at 9:21 PM, Jason Evans <[EMAIL PROTECTED]> wrote:
> Greg Ewing wrote:
>> The idea of allowing __init__.pyx was so that the main
>> code of a package could be written in Pyrex.
>>
>> However, I've never actually tested whether Python
>> recognises an __init__.so file as a package main
>> file, so I'm not sure if this works.
>
> This is an issue for me, since I would like to be able to structure my
> packages/modules something like the following (incomplete) tree:
>
>   Parsing.so
>   Crux/
>        __init__.so (Cythonized Crux)
>        Config.py
>        DistMatrix.so
>        Tree/
>             __init__.so (Cythonized Crux.Tree)
>             Parsimony.so
>
> If it were possible to get Python to load __init__.so, everything would
> be great, but Python reports:
>
>   ImportError: No module named Crux
>
> I tried using the dotted file naming convention instead of the directory
> hierarchy:
>
>   Parsing.pyx
>   Crux.pyx
>   Crux.Config.py
>   Crux.DistMatrix.pyx
>   Crux.Tree.pyx
>
> Unfortunately, distutils turns that into:
>
>   Parsing.so
>   Crux.so
>   Crux/
>        Config.py
>        DistMatrix.so
>        Tree.so
>
> This doesn't work because the Crux directory is not a package directory.
>  If I add a Crux/__init__.py, then Crux.so is ignored.
>
> In fact, I haven't been able to find *any* way to get Crux to be a
> Cythonized package.  As a data point, Sage apparently uses a combination
> of empty __init__.py files and all.py files, but never creates
> Cythonized packages.  Also, http://wiki.cython.org/PackageHierarchy
> narrowly avoids what I'm trying to do.  My searches for other examples
> hasn't turned up anything more useful than this email thread.
>
> Is there a way to nest Cythonized modules?  To be clear, I would like to
> be able to create all of the following as Cythonized loadable
> packages/modules:
>
>   Crux
>   Crux.Tree
>   Crux.Tree.Parsimony
>
> Thanks,
> Jason
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to