Commits

Anonymous committed c0fa807

added a post install function that ensures setuptools is faked even if not previously present

Comments (0)

Files changed (2)

                      'Setuptools distribution' % element)
     return True
 
+def after_install(dist):
+    log.warn('After install bootstrap.')
+    placeholder = dist.get_command_obj('install').install_purelib
+    if not os.path.exists(placeholder):
+        log.warn('Could not find the install location')
+        return
+    pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
+    setuptools_file = 'setuptools-0.6c9-py%s.egg' % pyver
+    pkg_info = os.path.join(placeholder, setuptools_file)
+    if os.path.exists(pkg_info):
+        log.warn('%s already exists' % pkg_info)
+        return
+    log.warn('Creating %s' % pkg_info)
+    f = open(pkg_info, 'w')
+    try:
+        f.write(SETUPTOOLS_PKG_INFO)
+    finally:
+        f.close()
+    pth_file = os.path.join(placeholder, 'setuptools.pth')
+    log.warn('Creating %s' % pth_file)
+    f = open(pth_file, 'w')
+    try:
+        f.write(os.path.join(os.curdir, setuptools_file))
+    finally:
+        f.close()
+
 def _patch_egg_dir(path):
     # let's check if it's already patched
     pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
         f.close()
     return True
 
+def before_install():
+    log.warn('Before install bootstrap.')
+    fake_setuptools()
+
 def fake_setuptools():
     log.warn('Scanning installed packages')
     try:
         # we're cool
         log.warn('Setuptools or Distribute does not seem to be installed.')
         return
-    ws  = pkg_resources.working_set
+    ws = pkg_resources.working_set
     setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
     if setuptools_dist is None:
         log.warn('No setuptools distribution found')
     setuptools_location = setuptools_dist.location
     log.warn('Setuptools installation detected at %s' % setuptools_location)
 
-    # let's see if its an egg until this supports non-egg installation
+    # let's see if its an egg
     if not setuptools_location.endswith('.egg'):
         log.warn('Non-egg installation')
         res = _remove_flat_installation(setuptools_location)
 # if we are installing Distribute using "python setup.py install"
 # we need to get setuptools out of the way
 if 'install' in sys.argv[1:]:
-    from bootstrap import fake_setuptools
-    fake_setuptools()
+    from bootstrap import before_install
+    before_install()
 
-setup(
+dist = setup(
     name="distribute",
     version=VERSION,
     description="Download, build, install, upgrade, and uninstall Python "
     Topic :: Utilities""".splitlines() if f.strip()],
     scripts = scripts,
 )
+if 'install' in sys.argv[1:]:
+    from bootstrap import after_install
+    after_install(dist)
+
+