[Zope3-dev] directory hierarchy proposal
holger krekel
pyth@devel.trillke.net
Mon, 16 Dec 2002 15:28:14 +0100
Jim Fulton wrote:
> holger krekel wrote:
> > Jim Fulton wrote:
> >>>What about the convention that namespace package __init__.py say something
> >>>like this:
> >>>
> >>># this is a namespace package, please keep __init__.py empty of code
> >>>
> >>>This way anybody tempted to add stuff to an __init__.py where they shouldn't
> >>>will be made aware immediately that they shouldn't do that.
> >>>
> >>This is a good idea, It will need to be modified slightly, since it will
> >>contain some boilerplate code to knit all directories of the same name on the
> >>Python path into a single logical module.
> >>
> >
> > I am bit uneasy about implicitly collecting modules from several places into
> > one namespace package.
>
> Why? The point is to separate physical organization, directories, from logical
> organization, the package.
My main concern is basically that in a more complex (e.g. developer's setup)
you have two modules with the same name in your pythonpath.
PYTHONPATH ordering are a source for many problems on c.l.py.
The namespace-collecting mechanism would make it worse, i suspect.
> > In which places would a namespace package look?
>
> This is described above. I'll give a detailed example.
> Now, suppose my Python path was something like:
>
>
> [''
> '/usr/local/python/latest/lib/python2.2',
> '/usr/local/python/latest/lib/python2.2/plat-linux2',
> '/usr/local/python/latest/lib/python2.2/lib-tk',
> '/usr/local/python/latest/lib/python2.2/lib-dynload',
> '/usr/local/python/latest/lib/python2.2/site-packages']
>
> Now, I could install a zope package in in
> '/usr/local/python/latest/lib/python2.2/site-packages'
>
> that contained, say, zope.pagetemplates.
>
> I could also have a zope package in the current directory that contained
> zope.security.
>
> From Python, I'd be able to:
>
> from zope.pagetemplates import PageTemplate
> from zope.security.checker import ProxyFactory
>
> because the two physical zope directories would be merged
> into a single package.
>
> > How is this configured?
>
> First, note that packages can define their own package-specific
> paths. By default, a package path contains only the package directory,
> but it can be changed to include additional directories.
>
> Each zope package __init__ file would have a bit of boilerplate code
> that would include all zope directories in sys.path:
>
> # Boilerplate code that combines all zope directories in sys.path
> import sys, os
> __path__ = [os.path.join(p, 'zope') for p in sys.path]
thanks for the explanation. IMO without further checks (e.g. warnings for
duplicate names in different locations) this can be very confusing
especially if you are remotely analyzing a customer problem who might
have installed lots of stuff and has a path with many items.
regards,
holger