[Python-Dev] PEP 382: Namespace Packages

"Martin v. Löwis" martin at v.loewis.de
Fri Apr 3 15:55:22 EDT 2009


Chris Withers wrote:
> Martin v. Löwis wrote:
>> I propose the following PEP for inclusion to Python 3.1.
>> Please comment.
> 
> Would this support the following case:
> 
> I have a package called mortar, which defines useful stuff:
> 
> from mortar import content, ...
> 
> I now want to distribute large optional chunks separately, but ideally
> so that the following will will work:
> 
> from mortar.rbd import ...
> from mortar.zodb import ...
> from mortar.wsgi import ...
> 
> Does the PEP support this? 

That's the primary purpose of the PEP. You can do this today already
(see the zope package, and the reference to current techniques in the
PEP), but the PEP provides a cleaner way.

In each chunk (which the PEP calls portion), you had a structure like
this:

mortar/
mortar/rbd.pkg (contains just "*")
mortar/rbd.py

or

mortar/
mortar/zobd.pkg
mortar/zobd/
mortar/zobd/__init__.py
mortar/zobd/backends.py

As a site effect, you can also do "import mortar", but that would just
give you the (nearly) empty namespace package, whose only significant
contents is the variable __path__.

Regards,
Martin



More information about the Python-list mailing list