[Python-Dev] Another approach for the import mechanism
Martin v. Löwis
martin@v.loewis.de
06 Dec 2002 00:33:41 +0100
Gustavo Niemeyer <niemeyer@conectiva.com> writes:
> 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".
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.
So you are back to calling all registered hooks for all items on
sys.path, which might be expensive.
Regards,
Martin