[Python-Dev] New and Improved Import Hooks

Just van Rossum just@letterror.com
Thu, 5 Dec 2002 15:50:37 +0100


Gordon McMillan wrote:

> Here's what iu.py does:
>  
> The first time an entry on sys.path requires
> examination, the list of importers is traversed
> until one accepts it. That importer is associated
> with the name, so subsequent imports are only
> one dict lookup away from the importer.
> 
> Search order is as expected (sys.path.insert(0, ...)
> works). If your app only uses stuff from sys.path[0],
> no time is wasted finding the right importers for
> sys.path[1:].  

Ok, that's is a much clearer picture than I ever got from reading the code,
thanks. (And sorry Paul, you've been saying this all along; it's been an
entertaining and very educating trip for me ;-)

At the cost of some complexity this indeed solves all our problems:
- importers can be associated with sys.path elements matching a pattern
- adds a high level import hook mechanism
- makes plugging in a zipimporter a snap
- doesn't muck with sys.path

I'll have a whack at integrating this in import.c.

Just