[Python-Dev] zipimport & import hooks

Kevin Jacobs jacobs@penguin.theopalgroup.com
Fri, 6 Dec 2002 08:59:41 -0500 (EST)


On 6 Dec 2002, Martin v. [iso-8859-15] L=F6wis wrote:
> Kevin Jacobs <jacobs@penguin.theopalgroup.com> writes:
>=20
> >   for filename in os.listdir(__path__[0]):
> >     if not filename.endswith('.py') or filename.startswith('__'):
> >       continue
> [...]
> > Clearly, the above code can be redone in a much nicer way that doesn'=
t
> > depend on __path__, the qualified base package name, and __import__.
>=20
> That would break only if the package becomes part of a zipfile, right?
> And, if it is in a zipfile, it breaks no matter what mechanism we find
> for zipfile imports, since it relies on os.listdir to obtain the
> package contents, right?

Yup -- which is why I've just added an item to our task queue to avoid th=
e
filesystem entirely for this kind of code.

> >   2) They don't care if Python stores objects, strings, or bananas in
> >      sys.path, so long as=20
> >=20
> >        sys.path=3Dmap(str,sys.path)=20
> >=20
> >      results in a human-readable path and does not change how imports=
 occur.
>=20
> For Just's patch, that is only true for zipfile imports. If you would
> also provide URL, or .tgz import with his patch, then you'll loose the
> magic when converting the path back to strings.

Hmmm.  I haven't looked that closely at Just's proposal.  Why should .tgz=
 or
http://xyz be treated any differently than .zip?

> >   3) They all want ZIP archives to be a builtin feature, but don't ca=
re if
> >      they have to write an extra line of code to register a TAR/BZ2/w=
hatever
> >      import hook.
>=20
> Clearly, with Jim's patch, they'ld only get zipfile import, period.

The sentiment seemed to be that zipfiles were an 80% solution and the res=
t
was icing on the cake.  Of course, as their boss, I can overrule them and
say that I also need an import mechanism that can also gracefully support
cryptographically signed modules (native and in zipfiles) too.  ;)

-Kevin

--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19         E-mail: jacobs@theopalgroup.com
Fax:   (216) 986-0714              WWW:    http://www.theopalgroup.com