[Import-sig] imputil

Michel Sanner sanner@scripps.edu
Wed, 14 Mar 2001 14:36:56 -0800


Hi,

I am trying to come up with a way to handle versions of packages using imputil.
I got version 1.12 from the CVS server and I try the following:

package structure:

A/
        __init__.py
                from imputil import ImportManager
                ImportManager().install()
        A_1_0/
                __init__.py
                B.py
        A_1_1/
                __init__.py
                B.py
        A_1_2/
                __init__.py
                B.py

Here is what I'd like to achieve:
>>> import A
>>> # the __init__.py file of the A package identifies A_1_0, A_1_1 and A_1_2
>>> # as sub packages and installs a special importer which will import from
>>> # A_VERSION every time that something from A should be imported
>>>
>>> A.importer.set_version("1_0")
>>> from A import B # should import A.A_1_0.B
>>>

The first problem I have is the following:

if I type:

Python 1.5.2 (#0, Apr 14 2000, 10:15:38) [C] on irix646
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import A
>>> from A import A_1_0
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ImportError: cannot import name A_1_0
>>>

if I type "from A import A_1_0" BEFORE importing the package A it works fine

Python 1.5.2 (#0, Apr 14 2000, 10:15:38) [C] on irix646
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from A import A_1_0
>>> A_1_0
<module 'A.A_1_0' from 'A/A_1_0/__init__.pyc'>
>>>

more generally, I do not understand how imputil should be used.
It seems that I should sub-class Importer and overwrite the get_code method.
How would I then make this importer the one used for my package ?

Thanks for any help with that

-Michel

-- 

-----------------------------------------------------------------------

>>>>>>>>>> AREA CODE CHANGE <<<<<<<<< we are now 858 !!!!!!!

Michel F. Sanner Ph.D.                   The Scripps Research Institute
Assistant Professor			Department of Molecular Biology
					  10550 North Torrey Pines Road
Tel. (858) 784-2341				     La Jolla, CA 92037
Fax. (858) 784-2860
sanner@scripps.edu                        http://www.scripps.edu/sanner
-----------------------------------------------------------------------