[Distutils] Setuptools: omit namespace package directories?

Jim Fulton jim at zope.com
Fri Feb 9 19:21:37 CET 2007


On Feb 9, 2007, at 12:08 PM, Phillip J. Eby wrote:

> At 09:15 AM 2/9/2007 -0500, Jim Fulton wrote:
>> The question is whether a less annoying layout can be made  
>> importable.
>
> Well, what's "annoying" is relative.  I personally find the flat  
> layout "annoying" because it's not WYSIWYG.  :)
>
> But the answer to your question is "yes".  Anything can be made  
> importable, with sufficient effort.

Yup.


> When a project that includes a namespace package is installed using  
> --single-version-externally-managed, a special .pth file for that  
> project is created that sets up empty modules in sys.modules with  
> appropriate __path__ values.

I really don't fathom --single-version-externally-managed. :)

Where is this .pth file created?

> A similar technique could be applied in setup.py develop, if a  
> project uses package_dirs.  I'm just a bit reluctant to try to  
> shoehorn something like that into 0.6.

Of course.

> But, if you'd like to experiment with creating a patch (or a  
> subclass of "develop") that would support creating and uninstalling  
> this .pth file, see the 'install_namespaces()' method of the  
> install_egg_info command in setuptools.  The code you'd need for  
> this would actually be *simpler* in some ways, because that code is  
> trying to work relative to whatever directory it's installed in,  
> but for what "develop" needs you could just bake the absolute paths  
> right in.

What would read this .pth file?

> The uninstall mode of "develop" could just remove the .pth file.   
> One possible complication, however, is that if someone didn't  
> uninstall but left the .pth file around, it would produce strange  
> results (if e.g., they installed an egg for the project without  
> uninstalling the develop mode).  So, the code in the .pth should  
> probably check that the original project is still on sys.path  
> before creating dummy modules.

I kinda doubt I understand this enough to pursue it.  In any case, I  
won't have time until after PyCon.  I may ask you more about  this  
there (assuming that you'll be there.)

Jim

--
Jim Fulton			mailto:jim at zope.com		Python Powered!
CTO 				(540) 361-1714			http://www.python.org
Zope Corporation	http://www.zope.com		http://www.zope.org





More information about the Distutils-SIG mailing list