[Python-checkins] r60812 - sandbox/trunk/setuptools/ez_setup.py
phillip.eby
python-checkins at python.org
Thu Feb 14 20:35:28 CET 2008
Author: phillip.eby
Date: Thu Feb 14 20:35:28 2008
New Revision: 60812
Modified:
sandbox/trunk/setuptools/ez_setup.py
Log:
Support upgrading existing setuptools when run from a setup.py
script (but not during easy_install, unfortunately).
Modified: sandbox/trunk/setuptools/ez_setup.py
==============================================================================
--- sandbox/trunk/setuptools/ez_setup.py (original)
+++ sandbox/trunk/setuptools/ez_setup.py Thu Feb 14 20:35:28 2008
@@ -54,31 +54,31 @@
this routine will print a message to ``sys.stderr`` and raise SystemExit in
an attempt to abort the calling script.
"""
- try:
- import setuptools
- if setuptools.__version__ == '0.0.1':
- print >>sys.stderr, (
- "You have an obsolete version of setuptools installed. Please\n"
- "remove it from your system entirely before rerunning this script."
- )
- sys.exit(2)
- except ImportError:
+ was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
+ def do_download():
egg = download_setuptools(version, download_base, to_dir, download_delay)
sys.path.insert(0, egg)
import setuptools; setuptools.bootstrap_install_from = egg
-
- import pkg_resources
try:
- pkg_resources.require("setuptools>="+version)
-
+ import pkg_resources
+ except ImportError:
+ return do_download()
+ try:
+ pkg_resources.require("setuptools>="+version); return
except pkg_resources.VersionConflict, e:
- # XXX could we install in a subprocess here?
- print >>sys.stderr, (
+ if was_imported:
+ print >>sys.stderr, (
"The required version of setuptools (>=%s) is not available, and\n"
"can't be installed while this script is running. Please install\n"
- " a more recent version first.\n\n(Currently using %r)"
- ) % (version, e.args[0])
- sys.exit(2)
+ " a more recent version first, using 'easy_install -U setuptools'."
+ "\n\n(Currently using %r)"
+ ) % (version, e.args[0])
+ sys.exit(2)
+ else:
+ del pkg_resources, sys.modules['pkg_resources'] # reload ok
+ return do_download()
+ except pkg_resources.DistributionNotFound:
+ return do_download()
def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
@@ -127,9 +127,43 @@
if dst: dst.close()
return os.path.realpath(saveto)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
-
try:
import setuptools
except ImportError:
@@ -144,8 +178,11 @@
os.unlink(egg)
else:
if setuptools.__version__ == '0.0.1':
- # tell the user to uninstall obsolete version
- use_setuptools(version)
+ print >>sys.stderr, (
+ "You have an obsolete version of setuptools installed. Please\n"
+ "remove it from your system entirely before rerunning this script."
+ )
+ sys.exit(2)
req = "setuptools>="+version
import pkg_resources
@@ -166,8 +203,6 @@
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
-
-
def update_md5(filenames):
"""Update our built-in md5 registry"""
More information about the Python-checkins
mailing list