[Distutils] setuptools and site.py

Ian Bicking ianb at colorstudy.com
Wed Apr 19 23:18:16 CEST 2006


I'm trying to resolve a few issues in working-env.py 
(http://svn.colorstudy.com/home/ianb/working-env.py) and I'm running 
into some conflicts with setuptools.

working-env.py basically works by creating another site.py, which 
doesn't add site-packages and other directories that I don't care for. 
Without setuptools this works pretty well.  But because of changes in 
setuptools, added right around the time I wrote working-env.py, 
setuptools now wants to write its own site.py and doesn't like mine.

One option is to integrate setuptools' changes into my own customized 
site.py, and then add __boot to the top to fake setuptools out.  I think 
that would be bothersome.

Another option would be if setuptools looked for something ahead of 
site.  Like, say, siteoverride.  Then I could put my siteoverride in 
place instead of site.py, let setuptools have site.py, and avoid the 
system site.py entirely.


Also, and this is related to a request Jim made a while ago, I'm 
monkeypatching setuptools currently to change the way it creates 
scripts, and it would be nice if this wasn't necessary.  Or was easier. 
  The monkeypatch is basically changing the script generated so that it 
sets sys.path before importing site.

Here's what I'm doing (in setuptools/__init__):

import setuptools.command.easy_install as easy_install

def get_script_header(script_text, executable=easy_install.sys_executable):
     from distutils.command.build_scripts import first_line_re
     first, rest = (script_text+'\n').split('\n',1)
     match = first_line_re.match(first)
     options = ''
     if match:
         script_text = rest
         options = match.group(1) or ''
         if options:
             options = ' '+options
     if options.find('-S') == -1:
         options += ' -S'
     shbang = "#!%(executable)s%(options)s\n" % locals()
     shbang += ("import sys, os\n"
                "join, dirname = os.path.join, os.path.dirname\n"
                "lib_dir = join(dirname(dirname(__file__)), 'lib', 
'python%s.%s' % tuple(sys.version_info[:2]))\n"
                "sys.path.insert(0, lib_dir)\n"
                "import site\n")
     return shbang

easy_install.get_script_header = get_script_header






-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the Distutils-SIG mailing list