Commit d3ba8f0b authored by tarek's avatar tarek

making ez_setup removing an existing setuptools distribution out of the way

--HG--
branch : distribute
extra : rebase_source : a97ad8f22e698747b81a097215b8ebffdf7edae6
parent 45ae6fb6
......@@ -14,7 +14,7 @@ the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import sys
import sys, os
import os
try:
from hashlib import md5
except ImportError:
......@@ -133,6 +133,34 @@ def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
try:
import setuptools
# we need to check if the installed setuptools
# is from Distribute or from setuptools
if not hasattr(setuptools, '_distribute'):
# we have a setuptools distribution, we need to get out
# of our way. This is done by removing all references
# of setuptools egg from .pth files.
# removing setuptools distribution from easy_install.pth
# using the --multi-version option seems like the safest
# way to do this.
from setuptools.command.easy_install import main
main(['-q', '-m', 'setuptools'])
# now removing setuptool.pth manually so installing
# 'distribute' will re-create it. Notice that a -U call
# will have the same effect.
from setuptools.command.easy_install import easy_install
from setuptools.dist import Distribution
dist = Distribution()
cmd = easy_install(dist)
cmd.args = ['setuptools']
cmd.ensure_finalized()
pth_file = os.path.join(cmd.install_dir, 'setuptools.pth')
if os.path.exists(pth_file):
os.remove(pth_file)
# now we are ready to install distribute
raise ImportError
except ImportError:
egg = None
try:
......
......@@ -13,6 +13,15 @@ __all__ = [
'find_packages'
]
# This marker is used to simplify the process that checks is the
# setuptools package was installed by the Setuptools project
# or by the Distribute project, in case Setuptools creates
# a distribution with the same version.
#
# The ez_setup script for instance, will check if this
# attribute is present to decide wether to reinstall the package
_distribute = True
bootstrap_install_from = None
def find_packages(where='.', exclude=()):
......
......@@ -969,8 +969,7 @@ See the setuptools documentation for the "develop" command for more info.
if not self.dry_run:
self.pth_file.save()
if dist.key=='setuptools':
if dist.key=='distribute':
# Ensure that setuptools itself never becomes unavailable!
# XXX should this check for latest version?
filename = os.path.join(self.install_dir,'setuptools.pth')
......
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