[Distutils] requiring python 2.5

Rick Ratzel rlratzel at enthought.com
Fri Jun 15 23:49:46 CEST 2007

>    Date: Fri, 15 Jun 2007 14:57:17 -0400
>    From: "Phillip J. Eby" <pje at telecommunity.com>
>    At 12:59 PM 6/15/2007 -0500, Rick Ratzel wrote:
>    >    Yes, I see now that it does get imported, but unfortunately not 
>    > by my code.
>    >It's imported as a result of importing pkg_resources, since 
>    >enthought.traits is
>    >a namespace package.
>    Does it *need* to be a namespace package?

   Yes, I think it does.  enthought.traits is our package for adding manifestly
typed attributes to Python classes, and enthought.traits.ui.wx contributes to
the enthought.traits.ui namespace by adding a wxPython backend for creating UIs
out of classes with traits using wxPython.  We don't want to require wxPython
(we have a wxPython egg) when users may never use the UI features of traits, so
we broke it out as an extra.  So naturally, enthought.traits is bundled in the
enstaller egg, and enthought.traits.ui is in the enstaller.gui egg.

>    >    Grasping at straws, I set enthought.__path__ in enstaller-script.py
>    >immediately before and after pkg_resources is imported, only to get the same
>    >results both times.
>    >
>    >    But when I switch to setuptools 0.7 there are no enthought.traits modules
>    >loaded at all (in fact, the only enthought. modules loaded are the enstaller
>    >ones)...this must have been one of the changes you mentioned.
>    Yes, that's exactly the change I'm talking about; in 0.7, namespace 
>    packages are always loaded lazily.
>    >    Phillip, I really appreciate the time you're taking to look at this.  I'm
>    >going to release a version which simply requires setuptools 0.7...unless you
>    >think that's a terrible idea, or you discover that I'm doing something wrong
>    >that I can fix.
>    The only things I can think of would be removing traits as a 
>    namespace package, or manually setting its __path__ also.  That is, 
>    first set enthought.__path__, then 
>    enthought.traits.__path__.  However, this will only work right if no 
>    traits.__init__ module does anything but declare the namespace.

   Ah, of course...enthought.traits being a namespace package means it needs the
same treatment.  I fixed up the enthought.traits and enthought.traits.ui
__path__ vars and it seems to be working with both versions of setuptools, with
and without various conflicting enthought.* eggs installed.  This should be OK
since we've made an effort to move all code (except for namespace decls) from
__init__.py to api.py for all of our packages.

  I'm going to do a formal build which "re-bundles" the enstaller egg and
install it again for a more thorough test, but I think I'm in the clear (famous
last words).

   My code looks like this now (it's actually in a "main" file which is
basically imported first, and not __init__.py):

enthought_path = path.dirname( path.dirname( __file__ ) )
import enthought
enthought.__path__ = [enthought_path]

enthought_traits_path = path.join( enthought_path, "traits" )
import enthought.traits
enthought.traits.__path__ = [enthought_traits_path]

import enthought.traits.ui
enthought.traits.ui.__path__ = [path.join( enthought_traits_path, "ui" )]

   Basically, I have to keep an eye out for any other namespace packages that I
use and make sure I do the same for them.  Thanks again for all your help,

Rick Ratzel - Enthought, Inc.
515 Congress Avenue, Suite 2100 - Austin, Texas 78701
512-536-1057 x229 - Fax: 512-536-1059

More information about the Distutils-SIG mailing list