[Distutils] Setuptools: omit namespace package directories?

Thomas Lotze thomas at thomas-lotze.de
Mon Feb 12 00:15:39 CET 2007


Am Fri, 09 Feb 2007 23:01:20 +0100 schrieb Thomas Lotze:

> But - what prevents the
> __init__.py file in this directory from setting up any intermediate
> namespaces in sys.modules and causing the real package to be looked for in
> some convenient place that avoids directory jumping in the source tree?

Nothing does. A proof-of-concept example can be found at
<http://www.thomas-lotze.de/Misc/foo.bar.baz-dev.tar.gz>. The source tree
contains foo/__init__.py and baz/__init__.py, the former setting up some
stuff in sys.modules using pkg_resources._handle_ns, the latter just
printing out __file__ for proof that it has been imported. You can use
this project both in develop mode and as an egg; I installed it using
easy_install.

Right now, a lot of os.path manipulation on __file__ is being done by
foo/__init__.py; if this was replaced by a call to some appropriate
pkg_resources function, the package_dir information could be used instead
in a clean way.

Also, the modules stuff gets set up all at once instead of recursively as
declare_namespace does. Thus the intermediate namespace package foo.bar
doesn't need an __init__.py, and it fact it doesn't even need a directory
in the source tree. I can't see anything bad about that right now, but
maybe a missing __init__.py does cause trouble somewhere.

-- 
Viele Grüße,
Thomas




More information about the Distutils-SIG mailing list