versioning schemes in package imports (was Re: [Import-sig] imputil)

Peter Funk
Thu, 15 Mar 2001 08:34:28 +0100 (MET)


sorry for jumping in on this thread that late.

> Michel Sanner wrote:
> > I am trying to come up with a way to handle versions of packages
> > package structure:
> > A/
> >         A_1_0/
> >         A_1_1/
> >         A_1_2/
> > >>> A.importer.set_version("1_0")
> > >>> from A import B # should import A.A_1_0.B

Gordon McMillan answered:
> Actually, in this case you don't really *need* imputil.

What I want to add is: The package Pmw (Python Mega Widgets,
see <>.) written by Greg McFarlane
<> contains a versioning mechanism comparable
to what Michel Saner seems to want.

BTW: Pmw is a Python extension very useful for everybody interested
in programming X-platform portable GUIs.

After 'import Pmw' the Pmw/ file replaces the Pmw module with 
an instance of a very interesting class 'PmwLoader', which fullfills 
two purposes:

1. Select a specific version of Pmw from a subdirectory called
   for example Pmw_0_8_3 or Pmw_0_8_4 or so.
2. Implement a "lazy importer" which delays actual importing of
   submodules contained in the package until a feature contained
   in it is actually used by the application which increases startup 

I personally never understood, why people bother with versioning
schemes and focussed on the second idea, which I found very smart.
It was easy for me to rip the versioning stuff out of the PmwLoader
class and to build a my own simplified lazy importer class for use
in my own packages.

May be Michel could use the same approach to implement his own
loader class doing this kind of version selection, he outlined 
above?  The basic idea to do all such things is outlined in the 
last three lines of Pmw/ which I quote here:

  # Create the dynamic loader and install it into sys.modules.
  sys.modules['_Pmw'] = sys.modules['Pmw']
  sys.modules['Pmw'] = _mod.PmwLoader(_dir, _instdirs, _listdir)

But this approach (replacing the module in sys.modules with a class
instance after import) has some disadvantages: For example: The
new documentation tool written by Ping (now in the standard
library) breaks down when encountering such a "module", because it
has no __file__ attribute.

Regards, Peter
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)