[Distutils] separate distribution of arbitrary submodules?

PJ Eby pje at telecommunity.com
Sat Dec 8 07:57:03 CET 2012


On Fri, Dec 7, 2012 at 11:13 AM, Václav Šmilauer <eu at doxos.eu> wrote:
> Hello,
>
> I am using setuptools to package module A. I would like to separately
> package also modules A.* such that those submodules are discoverable (using
> pkgutil.iter_modules preferrably) from within A, provided their names are
> unknown to A. Can this be done with some clever __path__ manipulation
> perhaps?

What you want is called a namespace package.  If you declare A as a
namespace package, then you can ship as many separate projects
containing A.* modules, and pkgutil.iter_modules() will work on them
once installed.

(What you cannot do is put any code in A/__init__.py for those
projects, except the code that declares it a namespace package.
Please see the setuptools and pkg_resources documentation on namespace
packages for more info.)


More information about the Distutils-SIG mailing list