[Python-Dev] New Import Hooks PEP, a first draft (and req. for
PEP #)
Paul Moore
lists@morpheus.demon.co.uk
Fri, 20 Dec 2002 23:32:26 +0000
"James C. Ahlstrom" <jim@interet.com> writes:
> It would look like this:
>
> suffix = [(".exe", "rb", 0)]
> file, path, descr = imp.find_module("wininst", __path__, suffix)
> data = file.read()
> file.close()
> return data
It's an interesting idea, but like others, I think that it's not going
to work right in practice. The main problem is that you don't explain
how to implement this version of imp.find_module in terms of the
importer protocol defined in the hooks PEP.
> Note that for a zip file, __file__ is something like
> C:/Python/lib/zarchive.zip/subdir/mymod.pyc
> and nothing is going to make code using __file__ Just Work.
That's not true. Under your patch, sure that's what __file__
is. Offhand, I'm not sure what Just's zipimporter code puts in there,
and I certainly wouldn't guarantee it for an arbitrary implementation
of zip imports. Frozen and builtin modules don't have usable __file__
attributes, and for something like a hook loading modules from a
database, there is no meaningful __file__ value.
> Well, maybe you could strip the last component "mymod.pyc" and
> use it as __path__ in a call to imp.find_module(). Not too
> hard, and it works with files and zip archives. But maybe not
> with future ftp:// imported modules.
And of course only with zip archives if you make imp.find_module()
support that usage. This is a circular argument.
> Your code knows the directory. My version would search in your
> package __path__ for it. But you only have one wininst.exe per
> package, right? And maybe putting it on package path is a feature.
That's what the get_data(name) method Just is proposing is supposed to
address. The only difficulty with it is pinning down what the "name"
argument means. At the lowest level, it's an arbitrary cookie which
identifies a chunk of data. The trick is to avoid making that cookie
*too* unrelated to how things work in the filesystem...
Paul.
--
This signature intentionally left blank