

import pkg_resources

pkg_resources.declare_namespace('zope')





namespace_packages=['zope']





namespace_packages=['zope', 'zope.app'],



Better grouping for projects/community/companies Better name for packages and don't worry about a name conflict Re-use package name in different namespaces Easy distribution as eggs

Zope project and the community in general use lots of namespacespackages. Though, we have some non-namespace packages likeZODB3,ZConfig etc. Zope community has created many namespacesfor packages like `zope`, `zope.app`, `zc`, `z3c`, `lovely` etc. Here`zc` stands for Zope Corporation, `z3c` for Zope 3 Community andlovely for Lovely Systems' packages.Python is a language with namespace support at many levels.Remember, the last line of Zen of Python reads like this: "Namespacesare one honking great idea -- let's do more of those!"Take it positively, don't interpret it more ;)A namespace package will not have any method,class or any otherobjects defined in that level. So a normal namespace package will beonly having an empty `__init__.py` file. Eggs and setuptools providessome new advantages for the distribution of namespace packages. So,normally a namespace package's `__init__.py` file will containsomething like this:That's all you required to put in your namespace package's`__init__.py` file. But you also will be required to add one morekeyword argument for `setup` function in your `setup.py` script likethis:You can even have nested namespace packages, in that case you have toadd it like this:Remember, Zen of Python also says: "Flat is better than nested." .Even though Zope use `zope.app` nested namespace package, Zopecommunity discourage nested namespace packages. The `zope.app`namespace may be consider as a mistake of Zope project.The `zope` and `zope.app` were the first namespace packages used byZope. I still remember the appraisal I got from Jim Fulton afterimplementing his proposal for making `zope.app` a pure namespacepackage.Here I will list some advantages of namespace packages. Feel free toadd/explain anything you found. :)I think the last point requires bit explanation. Consider twopackages in same namespace, `zope.interface` and `zope.testbrowser`.In Python, package name is tied to directory structure. So, in normaldistutils based distribution both `interface` and `testbrowser` shouldbe under `zope` directory. But setuptools and eggs allows you toinstall both separately and still use both.Let's save some names for new generation smart Python programmers !Don't pollute top-level names, use namespace packages !!