[Distutils] modules in different folders but under same namespace

P.J. Eby pje at telecommunity.com
Thu Feb 4 18:56:55 CET 2010

At 05:53 PM 2/4/2010 +0100, Riccardo-Maria BIANCHI wrote:
>I have a package structured like this:
>    src/ __init__.py
>           mod1.py
>    share/__init__.py
>             mod2.py
>Now I can import them as:
>How can I use Distutils to be able to import both of them under the 
>same "package" namespace as:
>import package.mod1
>import package.mod2

Move mod1.py and mod2.py under package/, and delete the 
subdirectories.  If you need backward compatibility, leave the old 
subdirectories and files in place, but have them import the new ones 
instead of containing any code.  Then delete them later.

Munging __path__ or using the package_dir options to setup() are both 
bad ideas in this case, unless there are other requirements you haven't stated.

If you use the  __path__ approach, you're going to make it more 
difficult for the distutils to figure out what to include in your 
source and binary distributions and installs, and if you use 
package_dir, you're going to end up with a different installation 
layout than your source layout.  Both will likely lead to hassles 
down the road, even if they appear to work in the short term.

More information about the Distutils-SIG mailing list