diff options
author | PJ Eby <distutils-sig@python.org> | 2008-02-14 19:47:51 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2008-02-14 19:47:51 +0000 |
commit | a0955a7e17e903248462b282acca8fd3d4a6a4a3 (patch) | |
tree | 8a433ff4f5f6daf3e6e6b562f5c2e86a62dee0aa /ez_setup.py | |
parent | 60cf2d31c8edb39b418f522ad935320c6da9c927 (diff) | |
download | external_python_setuptools-a0955a7e17e903248462b282acca8fd3d4a6a4a3.tar.gz external_python_setuptools-a0955a7e17e903248462b282acca8fd3d4a6a4a3.tar.bz2 external_python_setuptools-a0955a7e17e903248462b282acca8fd3d4a6a4a3.zip |
Allow ``ez_setup.use_setuptools()`` to upgrade existing setuptools
installations when called from a standalone ``setup.py``. (backport
from trunk)
--HG--
branch : setuptools-0.6
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4060813
Diffstat (limited to 'ez_setup.py')
-rwxr-xr-x | ez_setup.py | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/ez_setup.py b/ez_setup.py index 11def6ab..6c5d5050 100755 --- a/ez_setup.py +++ b/ez_setup.py @@ -77,31 +77,31 @@ def use_setuptools( 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, @@ -150,9 +150,43 @@ and place it in this directory before rerunning this script.) 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: @@ -167,8 +201,11 @@ def main(argv, version=DEFAULT_VERSION): 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 @@ -189,8 +226,6 @@ def main(argv, version=DEFAULT_VERSION): 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""" |