Commit 0bbcd2d3 authored by tarek's avatar tarek

hooked the patching code into setup.py

--HG--
branch : distribute
extra : rebase_source : 8e77b3c98ea725103494ee55ec403dc967dbb3a6
parent 96cecd18
...@@ -153,24 +153,32 @@ Description: xxx ...@@ -153,24 +153,32 @@ Description: xxx
""" """
def fake_setuptools(): def fake_setuptools():
from distutils import log
log.warn('Scanning installed packages')
try: try:
import pkg_resources import pkg_resources
except ImportError: except ImportError:
# we're cool # we're cool
log.warn('Setuptools or Distribute does not seem to be installed.')
return return
ws = pkg_resources.working_set ws = pkg_resources.working_set
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
if setuptools_dist is None: if setuptools_dist is None:
log.warn('No setuptools distribution found')
return return
# detecting if it was already faked # detecting if it was already faked
setuptools_location = setuptools_dist.location setuptools_location = setuptools_dist.location
log.warn('Setuptools installation detected at %s' % setuptools_location)
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
if os.path.exists(pkg_info): if os.path.exists(pkg_info):
content = open(pkg_info).read() content = open(pkg_info).read()
if SETUPTOOLS_PKG_INFO == content: if SETUPTOOLS_PKG_INFO == content:
# already patched # already patched
log.warn('Already patched.')
return return
log.warn('Patching...')
# let's create a fake egg replacing setuptools one # let's create a fake egg replacing setuptools one
os.rename(setuptools_location, setuptools_location+'.OLD.%s' % time.time()) os.rename(setuptools_location, setuptools_location+'.OLD.%s' % time.time())
os.mkdir(setuptools_location) os.mkdir(setuptools_location)
...@@ -181,7 +189,8 @@ def fake_setuptools(): ...@@ -181,7 +189,8 @@ def fake_setuptools():
f.write(SETUPTOOLS_PKG_INFO) f.write(SETUPTOOLS_PKG_INFO)
finally: finally:
f.close() f.close()
log.warn('Patched done.')
log.warn('Relaunching...')
# we have to relaunch the process # we have to relaunch the process
args = [sys.executable] + sys.argv args = [sys.executable] + sys.argv
if is_jython: if is_jython:
......
...@@ -13,6 +13,12 @@ from setuptools import setup, find_packages ...@@ -13,6 +13,12 @@ from setuptools import setup, find_packages
import sys import sys
scripts = [] scripts = []
# 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 ez_setup import fake_setuptools
fake_setuptools()
setup( setup(
name="distribute", name="distribute",
version=VERSION, version=VERSION,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment