Advertisement

Previous Entry | Next Entry

Why Zope community use namespace packages ?

  • Sep. 25th, 2007 at 4:46 PM

Zope project and the community in general use lots of namespaces
packages. Though, we have some non-namespace packages like
ZODB3,ZConfig etc. Zope community has created many namespaces
for packages like `zope`, `zope.app`, `zc`, `z3c`, `lovely` etc. Here
`zc` stands for Zope Corporation, `z3c` for Zope 3 Community and
lovely 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: "Namespaces
are 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 other
objects defined in that level. So a normal namespace package will be
only having an empty `__init__.py` file. Eggs and setuptools provides
some new advantages for the distribution of namespace packages. So,
normally a namespace package's `__init__.py` file will contain
something like this:

import pkg_resources
pkg_resources.declare_namespace('zope')

That's all you required to put in your namespace package's
`__init__.py` file. But you also will be required to add one more
keyword argument for `setup` function in your `setup.py` script like
this:

namespace_packages=['zope']

You can even have nested namespace packages, in that case you have to
add it like this:

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

Remember, Zen of Python also says: "Flat is better than nested." .
Even though Zope use `zope.app` nested namespace package, Zope
community 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 by
Zope. I still remember the appraisal I got from Jim Fulton after
implementing his proposal for making `zope.app` a pure namespace
package.

Here I will list some advantages of namespace packages. Feel free to
add/explain anything you found. :)


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

I think the last point requires bit explanation. Consider two
packages in same namespace, `zope.interface` and `zope.testbrowser`.
In Python, package name is tied to directory structure. So, in normal
distutils based distribution both `interface` and `testbrowser` should
be under `zope` directory. But setuptools and eggs allows you to
install 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 !!

Tags:

Comments

(Anonymous) wrote:
Sep. 26th, 2007 07:00 am (UTC)
Yes but they make import slow
I can't find the mailing list thread, but in matplotlib, using enthought.traits packaged with setuptools and namespace packages, the use of setuptools has been shown quite clearly by Fernando Perez to make the start up time much slower. Now people say this is fixed in setuptools 0.7, but I am going to stay clear of this until I am real damn sure it is fixed.
[info]baijum81 wrote:
Sep. 27th, 2007 07:40 am (UTC)
Re: Yes but they make import slow
Well, from your comment I can't judge how much slow it is. In Zope we use lots of namespace packages. And we never felt import is slow. Anyway, this is fixable thing.
[info]arunsubru wrote:
Sep. 29th, 2007 05:27 am (UTC)
Good Techie Blog
I have gone through your blog, there are lots of technical stuff in it which i am findiing it hard to understand.

regards

simple way of life
[info]rent_a_website wrote:
Jun. 16th, 2008 03:58 pm (UTC)
Re: Good Techie Blog
Me too. Any pointers on decoding the techie stuff?

Bob
Rent-a-Website

Latest Month

April 2009
S M T W T F S
   1234
567891011
12131415161718
19202122232425
2627282930  
Powered by LiveJournal.com
Designed by Tiffany Chow