[Python-Dev] Import redesign [LONG]

Fredrik Lundh fredrik@pythonware.com
Tue, 7 Dec 1999 14:25:54 +0100


Greg Stein <gstein@lyra.org> wrote:
> > The "single dictionary of names" is in the single archive importer
> > instance and has nothing to do with creating the archive.  It
> > is currently programmed this way.
> 
> Ah. There is the problem. In Guido's suggestion for the "next path of
> inquiry" :-), there is no "single dictionary of names". Instead, you have
> Importer instances as items in sys.path. Each instance maintains its
> dictionary, and they are not (necessarily) combined.

so the "sys.path contains importers (or strings)" strategy
is now officially sanctioned?  cool!!!

(a quick look in our code base says that this will cause
some trouble, unless os.path.isdir() is modified to reject
non-strings...  after all, if it's not a string, it cannot be
a valid directory path, so this does make some sense ;-)

another aside: can we have a standard mechanism for
listing the contents of a given archive, please?  we have
a lot of "path scanning" stuff (PIL and PST, among others),
and it would be great if things didn't break down if you
stuff it all in an archive.

something like:

    for path in sys.path:
        if os.path.isdir(path):
            files = os.listdir(path)
        else:
            try:
                files = path.listdir()
            except AttributeError:
                files = None
        if files is None:
            # no idea what's in here
        else:
            # path provides (at least) these modules

would be really useful.

and yes, it shouldn't have to be mentioned, since squeeze
have done it since early 1997, but archive importers should
provide a standard way to include non-module resources in
the archive, and a standard way to access such resources
as ordinary python streams.

e.g:

    file = path.open(name, "rb")

or something...

</F>