[Python-Dev] New and Improved Import Hooks
Just van Rossum
just@letterror.com
Tue, 3 Dec 2002 17:39:36 +0100
Moore, Paul wrote:
> That's great news, as I've said before. Can I ask that you
> consider a few issues, though. I don't have particular use cases
> in mind, but I believe that PEP 273 had a number of implicit
> assumptions, which your proposal does not incorporate. I'd like
> to make the differences explicit, just so that people get a
> chance to comment on whether they care.
>
> 1. Your import hooks seem to act at a level "above" sys.path,
> in the sense that the normal sys.path search becomes just
> another hook. With that in mind, I don't see a way for a user
> to add a zipfile in the *middle* of sys.path.
True. There would be ways around that, but it's currently not easy. I don't feel
this is a particularly important feature, though.
> 2. The syntax needed to add a zipfile search is different from
> the familiar one for sys.path additions. This isn't an issue
> as such, but may make the feature a little less accessible.
The way I see it: sys.path is for file system imports. It's a list of
directories, nothing else.
> 3. By using a non-sys.path approach, you make it impossible for
> users to set PYTHONPATH to include zipfiles.
This could be fixed by site.py: it could remove any .zip files from sys.path and
add hooks for them in sys.import_hooks. Or it could be fixed in the C code that
adds the script's directory to sys.path. Or we could add a tiny change to
import.c that invokes the zipimport module if a zip file is encountered.
[ snip ]
> > It adds
> > a whole directory listing caching scheme that is a) totally
> > unneeded and b) has (IMO) _nothing_ to do with zip importing
> > per se. That ExternalNames/External names stuff? I don't
> > understand why it is needed just to enable zip imports. It's a
> > lot of stuff!
>
> I've explained this a couple of times now. Please read the PEP
> for details, but Jim claims that zipfile imports need this if
> they are not to be too slow.
Well, I am not going to need it: upon reading the zip contents table I build a
dict, mapping (full) module names to toc info. One dict lookup will be enough to
get at the right data.
Let's discuss the rest when my implementation actually works.
Just