Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update distribute_setup version.

  • Loading branch information...
commit 14c54e76cb92740a7636cd5cd46841b460900b0c 1 parent 57f8ac4
Shyue Ping Ong shyuep authored

Showing 1 changed file with 55 additions and 24 deletions. Show diff stats Hide diff stats

  1. +55 24 distribute_setup.py
79 distribute_setup.py
@@ -14,11 +14,14 @@
14 14 This file can also be run as a script to install or upgrade setuptools.
15 15 """
16 16 import os
  17 +import shutil
17 18 import sys
18 19 import time
19 20 import fnmatch
20 21 import tempfile
21 22 import tarfile
  23 +import optparse
  24 +
22 25 from distutils import log
23 26
24 27 try:
@@ -46,7 +49,7 @@ def quote(arg):
46 49 args = [quote(arg) for arg in args]
47 50 return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
48 51
49   -DEFAULT_VERSION = "0.6.28"
  52 +DEFAULT_VERSION = "0.6.35"
50 53 DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
51 54 SETUPTOOLS_FAKED_VERSION = "0.6c11"
52 55
@@ -84,8 +87,11 @@ def _install(tarball, install_args=()):
84 87 if not _python_cmd('setup.py', 'install', *install_args):
85 88 log.warn('Something went wrong during the installation.')
86 89 log.warn('See the error message above.')
  90 + # exitcode will be 2
  91 + return 2
87 92 finally:
88 93 os.chdir(old_wd)
  94 + shutil.rmtree(tmpdir)
89 95
90 96
91 97 def _build_egg(egg, tarball, to_dir):
@@ -110,6 +116,7 @@ def _build_egg(egg, tarball, to_dir):
110 116
111 117 finally:
112 118 os.chdir(old_wd)
  119 + shutil.rmtree(tmpdir)
113 120 # returning the result
114 121 log.warn(egg)
115 122 if not os.path.exists(egg):
@@ -232,7 +239,9 @@ def violation(*args):
232 239
233 240 def _patch_file(path, content):
234 241 """Will backup the file then patch it"""
235   - existing_content = open(path).read()
  242 + f = open(path)
  243 + existing_content = f.read()
  244 + f.close()
236 245 if existing_content == content:
237 246 # already patched
238 247 log.warn('Already patched.')
@@ -250,12 +259,15 @@ def _patch_file(path, content):
250 259
251 260
252 261 def _same_content(path, content):
253   - return open(path).read() == content
  262 + f = open(path)
  263 + existing_content = f.read()
  264 + f.close()
  265 + return existing_content == content
254 266
255 267
256 268 def _rename_path(path):
257 269 new_name = path + '.OLD.%s' % time.time()
258   - log.warn('Renaming %s into %s', path, new_name)
  270 + log.warn('Renaming %s to %s', path, new_name)
259 271 os.rename(path, new_name)
260 272 return new_name
261 273
@@ -273,7 +285,7 @@ def _remove_flat_installation(placeholder):
273 285 log.warn('Could not locate setuptools*.egg-info')
274 286 return
275 287
276   - log.warn('Removing elements out of the way...')
  288 + log.warn('Moving elements out of the way...')
277 289 pkg_info = os.path.join(placeholder, file)
278 290 if os.path.isdir(pkg_info):
279 291 patched = _patch_egg_dir(pkg_info)
@@ -314,11 +326,12 @@ def _create_fake_setuptools_pkg_info(placeholder):
314 326 log.warn('%s already exists', pkg_info)
315 327 return
316 328
317   - if not os.access(pkg_info, os.W_OK):
318   - log.warn("Don't have permissions to write %s, skipping", pkg_info)
319   -
320 329 log.warn('Creating %s', pkg_info)
321   - f = open(pkg_info, 'w')
  330 + try:
  331 + f = open(pkg_info, 'w')
  332 + except EnvironmentError:
  333 + log.warn("Don't have permissions to write %s, skipping", pkg_info)
  334 + return
322 335 try:
323 336 f.write(SETUPTOOLS_PKG_INFO)
324 337 finally:
@@ -432,7 +445,7 @@ def _fake_setuptools():
432 445 res = _patch_egg_dir(setuptools_location)
433 446 if not res:
434 447 return
435   - log.warn('Patched done.')
  448 + log.warn('Patching complete.')
436 449 _relaunch()
437 450
438 451
@@ -440,8 +453,9 @@ def _relaunch():
440 453 log.warn('Relaunching...')
441 454 # we have to relaunch the process
442 455 # pip marker to avoid a relaunch bug
443   - _cmd = ['-c', 'install', '--single-version-externally-managed']
444   - if sys.argv[:3] == _cmd:
  456 + _cmd1 = ['-c', 'install', '--single-version-externally-managed']
  457 + _cmd2 = ['-c', 'install', '--record']
  458 + if sys.argv[:3] == _cmd1 or sys.argv[:3] == _cmd2:
445 459 sys.argv[0] = 'setup.py'
446 460 args = [sys.executable] + sys.argv
447 461 sys.exit(subprocess.call(args))
@@ -494,22 +508,39 @@ def sorter(dir1, dir2):
494 508 self._dbg(1, "tarfile: %s" % e)
495 509
496 510
497   -def _build_install_args(argv):
  511 +def _build_install_args(options):
  512 + """
  513 + Build the arguments to 'python setup.py install' on the distribute package
  514 + """
498 515 install_args = []
499   - user_install = '--user' in argv
500   - if user_install and sys.version_info < (2, 6):
501   - log.warn("--user requires Python 2.6 or later")
502   - raise SystemExit(1)
503   - if user_install:
  516 + if options.user_install:
  517 + if sys.version_info < (2, 6):
  518 + log.warn("--user requires Python 2.6 or later")
  519 + raise SystemExit(1)
504 520 install_args.append('--user')
505 521 return install_args
506 522
507   -
508   -def main(argv, version=DEFAULT_VERSION):
  523 +def _parse_args():
  524 + """
  525 + Parse the command line for options
  526 + """
  527 + parser = optparse.OptionParser()
  528 + parser.add_option(
  529 + '--user', dest='user_install', action='store_true', default=False,
  530 + help='install in user site package (requires Python 2.6 or later)')
  531 + parser.add_option(
  532 + '--download-base', dest='download_base', metavar="URL",
  533 + default=DEFAULT_URL,
  534 + help='alternative URL from where to download the distribute package')
  535 + options, args = parser.parse_args()
  536 + # positional arguments are ignored
  537 + return options
  538 +
  539 +def main(version=DEFAULT_VERSION):
509 540 """Install or upgrade setuptools and EasyInstall"""
510   - tarball = download_setuptools()
511   - _install(tarball, _build_install_args(argv))
512   -
  541 + options = _parse_args()
  542 + tarball = download_setuptools(download_base=options.download_base)
  543 + return _install(tarball, _build_install_args(options))
513 544
514 545 if __name__ == '__main__':
515   - main(sys.argv[1:])
  546 + sys.exit(main())

0 comments on commit 14c54e7

Please sign in to comment.
Something went wrong with that request. Please try again.