[Zope3-dev] Zip import and sys.path manipulation (was Re:
directory hierarchy proposal)
Phillip J. Eby
pje@telecommunity.com
Mon, 16 Dec 2002 11:23:47 -0500
(Summary: good plan for name and place, issues exist w/sketched implementation)
At 10:47 AM 12/16/02 -0500, Guido van Rossum wrote:
>Time's running short (we're close to releasing Python 2.3 alpha 1);
>we should decide on a name and a specific policy ASAP. I propose the
>following:
>
> from pkgutil import extended_path
> __path__ = extended_path(__path__, __name__)
How would that work for say, 'zope.app'?
>Where pkgutil.py could be something like this:
>
> import sys.path
>
> def extended_path(path, name):
> """Extend a package's path. (XXX more.)"""
> path = path[:]
> for dir in sys.path:
> if isinstance(dir, (str, unicode)):
> dir = os.path.join(dir, name)
> if dir not in path and os.path.isdir(dir):
> path.append(dir)
> return path
>
>--Guido van Rossum (home page: http://www.python.org/~guido/)
The 'isdir()' part isn't going to work on zipfiles... unless os.path is
going to have zipfile support in 2.3. :)