[Distutils] pkg_resources.declare_namespace vs pkgutil.extend_path

Phillip J. Eby pje at telecommunity.com
Fri Aug 11 21:38:31 CEST 2006

At 02:07 PM 8/11/2006 -0400, Jim Fulton wrote:

>We currently have two ways of implementing namespace packages,
>    pkg_resources.declare_namespace vs pkgutil.extend_path
>Do we need 2?

Um, maybe?  :)

>What does pkg_resources.declare_namespace do that pkgutil.extend_path
>does, other than provide zip file support?

It provides open-ended extensible support for arbitrary importers, not just 
zip files.  It also tracks which packages are namespace packages so that 
when new items are added to sys.path, the existing packages can be "fixed 
up" to include the appropriate variant of the new path.

>   Can we consolidate them

Not in any way that I know of.  You should use declare_namespace() unless 
you need .pkg files, because declare_namespace() supports PEP 302, while 
extend_path() assumes all sys.path entries are directories.  I don't really 
understand what .pkg files are for, so declare_namespace() doesn't support 
them at this time.

More information about the Distutils-SIG mailing list