[Numpy-discussion] Controlling the way a module is imported

Lisandro Dalcin dalcinl at gmail.com
Mon May 26 16:21:00 EDT 2008


David, I've implemented something like this for petsc4py.

Basically, I want to be able to build extension modules accessing
PETSc for different configuration options (for example, optimized
versus debug), when using PETSc, it is normal to select the build
variant by a $PETSC_ARCH environ var.

All this is implemented in pure Python code, and tanking advantage of
the built-in 'imp' module. I believe it is robust enough, I had never
received any report of this causing trouble from petsc4py users out
there.

If you think this fits your needs, then I'll help you. Buth then I'll
need to know a bit more about the directory tree structure of your
package and your extension modules.



On 5/25/08, David Cournapeau <david at ar.media.kyoto-u.ac.jp> wrote:
> Hi,
>
>     This is not numpy specific, but I need it for numpy/scipy. More
>  specifically, I would like to be able to have one module interface which
>  load imp1, imp2, imp3, etc... depending on some options. I see two
>  obvious solutions: monkey patching, and file configuration, but I try to
>  avoid the former, and there is no mechanism for the later in scipy. I
>  read that import hooks could be used for this purpose, but I don't quite
>  understand the pep:
>
>  http://www.python.org/dev/peps/pep-0302/
>
>  Has anyone played with it ?
>
>  cheers,
>
>  David
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion at scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>


-- 
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



More information about the NumPy-Discussion mailing list