[Distutils] namespace packages ok to contain code?

P.J. Eby pje at telecommunity.com
Tue Dec 14 02:21:38 CET 2010


At 05:11 PM 12/13/2010 -0600, Brad Allen wrote:
>Where I work we're considering a change to moving a group of packages
>to using namespaces. We want the namespace paths to reflect a
>dependency hierarchy,

Note that you don't *need* to use namespace paths to reflect 
dependencies; the main purpose of namespace packages is to allow you 
to separately distribute parts of a larger package, and to avoid 
naming conflicts with code produced by other organizations.

(In other words, it's a rare use case that really needs even *two* 
levels of namespace package; the common use is simply to make one 
parent namespace package for your organization. In general, the "flat 
is better than nested" rule of Python still applies.  ;-) )


>Some have warned this is not usually done, but no specific problems
>with this approach have been identified. Any guidance on this would be
>appreciated.

As Martin said, don't put code in the __init__.py of a namespace 
package.  (And parent packages of namespace packages count as 
namespace packages.)



More information about the Distutils-SIG mailing list