[Python-Dev] Another approach for the import mechanism

Gustavo Niemeyer niemeyer@conectiva.com
Fri, 6 Dec 2002 00:17:36 -0200


> > Yes, it is addressed. My propose is to allow the importer mechanism to
> > check if there's something importable with the given name in the given
> > path, instead of telling him what to import. With that in mind,
> > importing foobar.py.bz2 is just a matter of checking for
> > <modulename>.py.bz2 in the given path.
> 
> It appears that this can't be really done with the proposed mechanism,
> as you want to have a multiple hooks for a single source "URL".

As you have mentioned below, all hooks registered are called, if
the previous ones failed. So there shouldn't be any problem.

> If you *only* want to have a .py.bz2 importer, you could replace every
> directory on sys.path with the pybz2importer, which would check for
> .py.bz2 files in the directory, and, if that fails, calls
> imp.find_module.
> 
> Of course, if somebody wants to provide a crypt importer (which
> decrypts the source before importing it) in addition to the
> pybz2importer, then you get the same coordination problem as with all
> prior import hooks.

Yes, that's the idea behind all proposes after all.

> So you are back to calling all registered hooks for all items on
> sys.path, which might be expensive.

Agreed. But further hooks are only called if the default one failed.

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]