[Distutils] patch: solving the two major things that people dislike about setuptools, part 1

Mark Sienkiewicz sienkiew at stsci.edu
Tue Nov 25 16:56:33 CET 2008

Phillip J. Eby wrote:
> At 05:46 PM 11/24/2008 -0500, Mark Sienkiewicz wrote:
>> As far as I can tell, the *only* purpose of __egginsert is to permit 
>> the incorrect behaviour that your patch is intended to fix.
> The behavior isn't incorrect; it's by design. 

Here is my reasoning for saying it is broken:

[banana:~] sienkiew% which python
[banana:~] sienkiew% ls -l ~/py/lib/python
total 8
drwxr-xr-x   38 sienkiew  ststaff  1292 Nov 25 10:07 nose
-rw-r--r--    1 sienkiew  ststaff  2102 Nov 25 10:07 
[banana:~] sienkiew% ls -l  
total 680
...unrelated files here...
-rw-r--r--    1 iraf  sienkiew     238 Nov 25 10:06 easy-install.pth
drwxr-xr-x    5 iraf  sienkiew     170 Nov 25 10:06 nose-0.10.0-py2.5.egg
-rwxr-xr-x    1 iraf  sienkiew  328025 Oct  7 14:57 
-rw-r--r--    1 iraf  sienkiew      29 Nov 25 10:06 setuptools.pth
[banana:~] sienkiew% setenv PYTHONPATH ~/py/lib/python
[banana:~] sienkiew% python
Python 2.5.1 (r251:54863, Mar 18 2008, 11:29:59)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import nose
 >>> nose.__version__
 >>> nose.__file__

Look what happened:  When I imported "nose",  it chose the nose from the 
system site-packages directory, even though I have a different version 
that occurs earlier on PYTHONPATH.

At this time, I would like to draw your attention to 
http://www.python.org/doc/2.5.2/tut/node8.html section 6.1.2, where it 
describes PYTHONPATH.  "When PYTHONPATH is not set, or when the file is 
not found there, the search continues in an installation-dependent 
default path".   That does not appear to be what happened here.  It 
should have found the module that was on PYTHONPATH, not the module that 
is in the system site-packages.

Please explain why you consider this to be the desired behaviour.

In a later message, you said:

 >For example, in this case, if someone wanted to offer a patch that 
changed the behavior in such a way that the added eggs came directly 
before the sys.path directory in which they were contained, but not 
pushed all the way to the beginning of sys.path, that would be an 
acceptable way to change the behavior.

In my comments on zooko's patch:

 >I think the correct behaviour is to insert the .egg file either just 
before or just after the directory where we found the .pth file.
 >So, instead of

 >we want

Does this meet your criterion without breaking anything else?

IMHO, this is actually not a great patch because it depends on knowledge 
that should be private to distutils, but setuptools is already violating 
that information hiding.  (For example, it assumes that it is safe to 
alter sys.path while distutils is loading the .pth file; I didn't see 
that documented anywhere, but we can see that it works.)

b.t.w. You could make easy_install.pth read:

    import setuptools; setuptools.prep_sys_path()
    import setuptools; setuptools.alter_sys_path()

and then patches to the first/last line would be easier -- they would 
just happen when you install a new setuptools.

Mark S.

More information about the Distutils-SIG mailing list