aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrlacko <backup.rlacko@gmail.com>2013-12-11 08:39:49 +0100
committerrlacko <backup.rlacko@gmail.com>2013-12-11 08:39:49 +0100
commit02062cbb4aa89d6b0cdfe2e00c6c829c4d410cab (patch)
treebf9290e89d2a6012f42bf1fe9c38c597f16c4bb0
parent75e64cfad8c6c8f9d0fd8ac3209fd1e6e250e140 (diff)
Update ez_setup.py to latest version
-rw-r--r--ez_setup.py77
1 files changed, 28 insertions, 49 deletions
diff --git a/ez_setup.py b/ez_setup.py
index 72d35a5b4..2aa994b33 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -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 tarfile
import optparse
import subprocess
import platform
+import textwrap
from distutils import log
@@ -29,22 +30,13 @@ try:
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,10 +114,9 @@ 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:
@@ -133,23 +124,24 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
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 _extractall(self, path=".", members=None):
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():
"""