PEP: import version
Manlio Perillo
NOmanlio_perilloSPAM at libero.it
Sat May 15 02:51:19 EDT 2004
On Thu, 13 May 2004 18:07:27 +1000, Andrew Bennetts
<andrew-pythonlist at puzzling.org> wrote:
>On Thu, May 13, 2004 at 07:46:51AM +0000, Manlio Perillo wrote:
>[...]
>> A possible syntax is this:
>> import wxPython version '2.4'
>
>I'd like to see versioned imports too, but it looks like a tricky problem to
>me. Some questions that immediately spring to mind reading your proposal:
>
>How would this work with from X import Y? How would this work with packages
>(e.g. import X.Y.Z)?
>
>e.g. how would you add version requirements to these statements:
>
> from gtk import main
>
I see a simple solution:
from gtk version '2.0' import main
It should be up to gtk root module (ex __init__.py) to decide what
version of sub modules to load.
>But what about the second one -- can only top-level modules/packages have
>versions? e.g. what if the "twisted.web" package has a version that's
>independent of the top-level "twisted" container package? Would "from
>twisted.web version '1.3.0'" mean Twisted version 1.3.0, or Twisted Web
>version 1.3.0?
>
The sub-level packages have version too.
In example:
twisted version 1.3.0 -> web version 1.1
twisted version 1.3.5 -> web version 1.1
twisted version 1.4.0 -> vew version 1.2
The right sub module version to load is decided by the top level
module.
In detail (using a single file for all versions):
__init__.py
if __version__ == '1.4.0':
__all__ = [ ('web', '1.2'),
...
]
elif __version__ == '1.3.5':
_all = [ ('web', '1.1'),
...
]
That is, the items of __all__ should be tuples.
>What happens if the same program tries to import different (and possibly
>conflicting) versions of the same module, e.g.:
>
> import gtk version '2.0'
> import gtk version '1.2'
>
>Should an ImportError be raised? Should it succeed (assuming both versions
>are available)? Is it even possible to have two different versions of the
>same library/module installed in parallel, and if so, how?
It should unload gtk version 2.0 and load the version 1.0
Regards Manlio Perillo
More information about the Python-list
mailing list