Permalink
Browse files

Update ez_setup.py to latest version

  • Loading branch information...
1 parent 75e64cf commit 02062cbb4aa89d6b0cdfe2e00c6c829c4d410cab @lck lck committed Dec 11, 2013
Showing with 28 additions and 49 deletions.
  1. +28 −49 ez_setup.py
View
@@ -1,14 +1,14 @@
#!python
"""Bootstrap setuptools installation
-If you want to use setuptools in your package's setup.py, just include this
-file in the same directory with it, and add this to the top of your setup.py::
+To use setuptools in your package's setup.py, include this
+file in the same directory and add this to the top of your setup.py::
from ez_setup import use_setuptools
use_setuptools()
-If you want to require a specific version of setuptools, set a download
-mirror, or use an alternate download directory, you can do so by supplying
+To require a specific version of setuptools, set a download
+mirror, or use an alternate download directory, simply supply
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
@@ -21,6 +21,7 @@
import optparse
import subprocess
import platform
+import textwrap
from distutils import log
@@ -29,22 +30,13 @@
except ImportError:
USER_SITE = None
-DEFAULT_VERSION = "1.4"
+DEFAULT_VERSION = "2.0"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
-def _check_call_py24(cmd, *args, **kwargs):
- res = subprocess.call(cmd, *args, **kwargs)
- class CalledProcessError(Exception):
- pass
- if not res == 0:
- msg = "Command '%s' return non-zero exit status %d" % (cmd, res)
- raise CalledProcessError(msg)
-vars(subprocess).setdefault('check_call', _check_call_py24)
-
def _install(tarball, install_args=()):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
@@ -122,34 +114,34 @@ def _do_download(version, download_base, to_dir, download_delay):
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15):
- # making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
- was_imported = 'pkg_resources' in sys.modules or \
- 'setuptools' in sys.modules
+ rep_modules = 'pkg_resources', 'setuptools'
+ imported = set(sys.modules).intersection(rep_modules)
try:
import pkg_resources
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("setuptools>=" + version)
return
- except pkg_resources.VersionConflict:
- e = sys.exc_info()[1]
- if was_imported:
- sys.stderr.write(
- "The required version of setuptools (>=%s) is not available,\n"
- "and can't be installed while this script is running. Please\n"
- "install a more recent version first, using\n"
- "'easy_install -U setuptools'."
- "\n\n(Currently using %r)\n" % (version, e.args[0]))
- sys.exit(2)
- else:
- del pkg_resources, sys.modules['pkg_resources'] # reload ok
- return _do_download(version, download_base, to_dir,
- download_delay)
except pkg_resources.DistributionNotFound:
- return _do_download(version, download_base, to_dir,
- download_delay)
+ return _do_download(version, download_base, to_dir, download_delay)
+ except pkg_resources.VersionConflict as VC_err:
+ if imported:
+ msg = textwrap.dedent("""
+ The required version of setuptools (>={version}) is not available,
+ and can't be installed while this script is running. Please
+ install a more recent version first, using
+ 'easy_install -U setuptools'.
+
+ (Currently using {VC_err.args[0]!r})
+ """).format(VC_err=VC_err, version=version)
+ sys.stderr.write(msg)
+ sys.exit(2)
+
+ # otherwise, reload ok
+ del pkg_resources, sys.modules['pkg_resources']
+ return _do_download(version, download_base, to_dir, download_delay)
def _clean_check(cmd, target):
"""
@@ -315,13 +307,7 @@ def _extractall(self, path=".", members=None):
self.extract(tarinfo, path)
# Reverse sort directories.
- if sys.version_info < (2, 4):
- def sorter(dir1, dir2):
- return cmp(dir1.name, dir2.name)
- directories.sort(sorter)
- directories.reverse()
- else:
- directories.sort(key=operator.attrgetter('name'), reverse=True)
+ directories.sort(key=operator.attrgetter('name'), reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
@@ -330,8 +316,7 @@ def sorter(dir1, dir2):
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
- except ExtractError:
- e = sys.exc_info()[1]
+ except ExtractError as e:
if self.errorlevel > 1:
raise
else:
@@ -342,13 +327,7 @@ def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package
"""
- install_args = []
- if options.user_install:
- if sys.version_info < (2, 6):
- log.warn("--user requires Python 2.6 or later")
- raise SystemExit(1)
- install_args.append('--user')
- return install_args
+ return ['--user'] if options.user_install else []
def _parse_args():
"""

0 comments on commit 02062cb

Please sign in to comment.