[Python-Dev] Re: Christmas Wishlist

Fred L. Drake, Jr. fred at zope.com
Mon Dec 15 15:51:27 EST 2003

Barry Warsaw writes:
 > Jim uses the term "pure container package" to describe top-level
 > packages that contain no real content in the package except
 > subpackages.  "zope" and "zodb" are examples of this in Zope 3.  IWBNI
 > Python had better/easier support for weaving together pure container
 > package contents where subdirectories live in different locations on the
 > file system.


The .pth files processed by site.py support two interesting kinds of

- directories that should be added to sys.path, and

- import statements

The later alone is interesting enough, since it allows arbitrary
initialization code to run when the import is executed.  This still
happens before all the .pth files have been processed; I suspect we
really want the container package to be a little more flexible than
that, at least allowing their __path__ to be computed after all .pth
files have been processed.

Perhaps it would be nice to have a hook (probably in sys) that gets
called after site/sitecustomize are done?  A "pure container package"
could use a .pth file using "import mypackage", and the package's
__init__.py would register a hook function in sys that searches
sys.path for whatever directories should be used in
mypackage.__path__.  This also avoids the code being too specific to
one way of thinking about packages.


Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation

More information about the Python-Dev mailing list