[Python-Dev] Zip imports, PEP 273, and the .zip extension

Just van Rossum just@letterror.com
Sat, 7 Dec 2002 18:56:10 +0100


Martin v. L=F6wis wrote:

> That's quite expensive. Unless I'm mistaken, it causes an additional
> stat call per sys.path item (to find out that it is a directory).
>=20
> If Just's patch is accepted, you get that feature for free
>=20
> import zipimport,sys
> sys.path.append(zipimport.zipimporter(sys.argv[0]))
>=20
> does what you want. For Jim's patch, I'd say you lose: We should
> tighten the PEP saying that only items in sys.path are treated as
> zipfiles that have ".zip" in their name (with a yet-to-be-specified
> separator for putting directory in the zipfile into sys.path).

Note that I'm currently working on a variation of the patch that implemen=
ts a
subset of iu.py (I think I mentioned this a few times already ;-). For ea=
ch path
item, each item in a list of hooks is asked whether it can handle the pat=
h item;
the first one that can is used. This is done *once* per path item, the re=
sults
are cached in a dict (iu's shadowpath): {path_item: path_handler, ...}. T=
his
gives the zipimporter a chance no matter what the extension is and it's s=
till
cheap as it's only done once.

Just