[Python-Dev] imputil and modulefinder replacements

Thomas Heller thomas.heller@ion-tof.com
Fri, 5 Oct 2001 11:58:12 +0200


From: "Gordon McMillan" <gmcm@hypernet.com>
> Dev-er's
> 
> After numerous false-starts and dead-ends, I've come up with 
> two modules that do what imputil and modulefinder do, but 
> better.
> 
> Code and detailed descriptions are available here:
> 
> http://www.mcmillan-inc.com/importhooks.html
> 
Gordon, I've read your descriptions and IMO this is a great design
for a new import-utility and a new module-finder.

Some comments:
To fully simulate python's behaviour for import, the case of the
filename must be checked on windows. I found only two possibilities
to do this - the first one is to use os.listdir() which is probably 
expensive, but it returns filenames with the actual case. Second would
be to use Mark's win32api.FindFiles(), but this may not be available.

Your metapath models Python's import policy. One part of the policy
is that already loaded modules are fetched from sys.modules instead
of imported again. Should this behaviour also be modeled by a
SysModulesCacheDirector on your metapath?

What about reload? Shouldn't a new import-util module also implement
a reload-replacement?

> I would like to propose these (or something quite like them) as 
> replacements for the official versions. The code is quite similar 
> (in fact, the modulefinder code could have been written by 
> subclassing the imputil stuff, but I wrote them the other way 
> 'round). 
> 
It seems noone cares about this. imputil is in the distribution,
but is it really 'official'?

> If the charter of the Import-SIG is not as dead as the list is, I 
> would promote the basic structure as a potential model for a 
> reformed import.
> 
> For now, though, it's enough to consider the code. The 
> differences are too extreme to consider these patches, but the 
> subject hardly seems PEPable so I bring it up here.
> 
> 
> - Gordon
> 
Thomas