Browse files

Update distribute setup version.

  • Loading branch information...
1 parent 4020a92 commit c1a6c495b0c1e42c589f4e7b052ceadc0cc64561 @shyuep shyuep committed Mar 23, 2013
Showing with 56 additions and 25 deletions.
  1. +55 −24 distribute_setup.py
  2. +1 −1 setup.py
View
79 distribute_setup.py
@@ -14,11 +14,14 @@
This file can also be run as a script to install or upgrade setuptools.
"""
import os
+import shutil
import sys
import time
import fnmatch
import tempfile
import tarfile
+import optparse
+
from distutils import log
try:
@@ -46,7 +49,7 @@ def quote(arg):
args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
-DEFAULT_VERSION = "0.6.28"
+DEFAULT_VERSION = "0.6.35"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
SETUPTOOLS_FAKED_VERSION = "0.6c11"
@@ -84,8 +87,11 @@ def _install(tarball, install_args=()):
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
+ # exitcode will be 2
+ return 2
finally:
os.chdir(old_wd)
+ shutil.rmtree(tmpdir)
def _build_egg(egg, tarball, to_dir):
@@ -110,6 +116,7 @@ def _build_egg(egg, tarball, to_dir):
finally:
os.chdir(old_wd)
+ shutil.rmtree(tmpdir)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
@@ -232,7 +239,9 @@ def violation(*args):
def _patch_file(path, content):
"""Will backup the file then patch it"""
- existing_content = open(path).read()
+ f = open(path)
+ existing_content = f.read()
+ f.close()
if existing_content == content:
# already patched
log.warn('Already patched.')
@@ -250,12 +259,15 @@ def _patch_file(path, content):
def _same_content(path, content):
- return open(path).read() == content
+ f = open(path)
+ existing_content = f.read()
+ f.close()
+ return existing_content == content
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
- log.warn('Renaming %s into %s', path, new_name)
+ log.warn('Renaming %s to %s', path, new_name)
os.rename(path, new_name)
return new_name
@@ -273,7 +285,7 @@ def _remove_flat_installation(placeholder):
log.warn('Could not locate setuptools*.egg-info')
return
- log.warn('Removing elements out of the way...')
+ log.warn('Moving elements out of the way...')
pkg_info = os.path.join(placeholder, file)
if os.path.isdir(pkg_info):
patched = _patch_egg_dir(pkg_info)
@@ -314,11 +326,12 @@ def _create_fake_setuptools_pkg_info(placeholder):
log.warn('%s already exists', pkg_info)
return
- if not os.access(pkg_info, os.W_OK):
- log.warn("Don't have permissions to write %s, skipping", pkg_info)
-
log.warn('Creating %s', pkg_info)
- f = open(pkg_info, 'w')
+ try:
+ f = open(pkg_info, 'w')
+ except EnvironmentError:
+ log.warn("Don't have permissions to write %s, skipping", pkg_info)
+ return
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
@@ -432,16 +445,17 @@ def _fake_setuptools():
res = _patch_egg_dir(setuptools_location)
if not res:
return
- log.warn('Patched done.')
+ log.warn('Patching complete.')
_relaunch()
def _relaunch():
log.warn('Relaunching...')
# we have to relaunch the process
# pip marker to avoid a relaunch bug
- _cmd = ['-c', 'install', '--single-version-externally-managed']
- if sys.argv[:3] == _cmd:
+ _cmd1 = ['-c', 'install', '--single-version-externally-managed']
+ _cmd2 = ['-c', 'install', '--record']
+ if sys.argv[:3] == _cmd1 or sys.argv[:3] == _cmd2:
sys.argv[0] = 'setup.py'
args = [sys.executable] + sys.argv
sys.exit(subprocess.call(args))
@@ -494,22 +508,39 @@ def sorter(dir1, dir2):
self._dbg(1, "tarfile: %s" % e)
-def _build_install_args(argv):
+def _build_install_args(options):
+ """
+ Build the arguments to 'python setup.py install' on the distribute package
+ """
install_args = []
- user_install = '--user' in argv
- if user_install and sys.version_info < (2, 6):
- log.warn("--user requires Python 2.6 or later")
- raise SystemExit(1)
- if user_install:
+ 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
-
-def main(argv, version=DEFAULT_VERSION):
+def _parse_args():
+ """
+ Parse the command line for options
+ """
+ parser = optparse.OptionParser()
+ parser.add_option(
+ '--user', dest='user_install', action='store_true', default=False,
+ help='install in user site package (requires Python 2.6 or later)')
+ parser.add_option(
+ '--download-base', dest='download_base', metavar="URL",
+ default=DEFAULT_URL,
+ help='alternative URL from where to download the distribute package')
+ options, args = parser.parse_args()
+ # positional arguments are ignored
+ return options
+
+def main(version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
- tarball = download_setuptools()
- _install(tarball, _build_install_args(argv))
-
+ options = _parse_args()
+ tarball = download_setuptools(download_base=options.download_base)
+ return _install(tarball, _build_install_args(options))
if __name__ == '__main__':
- main(sys.argv[1:])
+ sys.exit(main())
View
2 setup.py
@@ -3,7 +3,7 @@
import sys
from distribute_setup import use_setuptools
-use_setuptools(version='0.6.10')
+use_setuptools()
from setuptools import setup, find_packages, Extension
try:

0 comments on commit c1a6c49

Please sign in to comment.