Commit 4ee48f30349138fede6fda66f047164625fc5ab5

Authored by selurvedu
1 parent 76c35558

Update bootstrap.py (version 2015-07-01)

Showing 1 changed file with 36 additions and 15 deletions
@@ -25,7 +25,10 @@ import tempfile @@ -25,7 +25,10 @@ import tempfile
25 25
26 from optparse import OptionParser 26 from optparse import OptionParser
27 27
28 -tmpeggs = tempfile.mkdtemp() 28 +__version__ = '2015-07-01'
  29 +# See zc.buildout's changelog if this version is up to date.
  30 +
  31 +tmpeggs = tempfile.mkdtemp(prefix='bootstrap-')
29 32
30 usage = '''\ 33 usage = '''\
31 [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] 34 [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
@@ -40,8 +43,9 @@ this script from going over the network. @@ -40,8 +43,9 @@ this script from going over the network.
40 ''' 43 '''
41 44
42 parser = OptionParser(usage=usage) 45 parser = OptionParser(usage=usage)
43 -parser.add_option("-v", "--version", help="use a specific zc.buildout version")  
44 - 46 +parser.add_option("--version",
  47 + action="store_true", default=False,
  48 + help=("Return bootstrap.py version."))
45 parser.add_option("-t", "--accept-buildout-test-releases", 49 parser.add_option("-t", "--accept-buildout-test-releases",
46 dest='accept_buildout_test_releases', 50 dest='accept_buildout_test_releases',
47 action="store_true", default=False, 51 action="store_true", default=False,
@@ -59,25 +63,33 @@ parser.add_option("-f", "--find-links", @@ -59,25 +63,33 @@ parser.add_option("-f", "--find-links",
59 parser.add_option("--allow-site-packages", 63 parser.add_option("--allow-site-packages",
60 action="store_true", default=False, 64 action="store_true", default=False,
61 help=("Let bootstrap.py use existing site packages")) 65 help=("Let bootstrap.py use existing site packages"))
  66 +parser.add_option("--buildout-version",
  67 + help="Use a specific zc.buildout version")
62 parser.add_option("--setuptools-version", 68 parser.add_option("--setuptools-version",
63 - help="use a specific setuptools version")  
64 - 69 + help="Use a specific setuptools version")
  70 +parser.add_option("--setuptools-to-dir",
  71 + help=("Allow for re-use of existing directory of "
  72 + "setuptools versions"))
65 73
66 options, args = parser.parse_args() 74 options, args = parser.parse_args()
  75 +if options.version:
  76 + print("bootstrap.py version %s" % __version__)
  77 + sys.exit(0)
  78 +
67 79
68 ###################################################################### 80 ######################################################################
69 # load/install setuptools 81 # load/install setuptools
70 82
71 try: 83 try:
72 - if options.allow_site_packages:  
73 - import setuptools  
74 - import pkg_resources  
75 from urllib.request import urlopen 84 from urllib.request import urlopen
76 except ImportError: 85 except ImportError:
77 from urllib2 import urlopen 86 from urllib2 import urlopen
78 87
79 ez = {} 88 ez = {}
80 -exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) 89 +if os.path.exists('ez_setup.py'):
  90 + exec(open('ez_setup.py').read(), ez)
  91 +else:
  92 + exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
81 93
82 if not options.allow_site_packages: 94 if not options.allow_site_packages:
83 # ez_setup imports site, which adds site packages 95 # ez_setup imports site, which adds site packages
@@ -88,12 +100,19 @@ if not options.allow_site_packages: @@ -88,12 +100,19 @@ if not options.allow_site_packages:
88 # We can't remove these reliably 100 # We can't remove these reliably
89 if hasattr(site, 'getsitepackages'): 101 if hasattr(site, 'getsitepackages'):
90 for sitepackage_path in site.getsitepackages(): 102 for sitepackage_path in site.getsitepackages():
91 - sys.path[:] = [x for x in sys.path if sitepackage_path not in x] 103 + # Strip all site-packages directories from sys.path that
  104 + # are not sys.prefix; this is because on Windows
  105 + # sys.prefix is a site-package directory.
  106 + if sitepackage_path != sys.prefix:
  107 + sys.path[:] = [x for x in sys.path
  108 + if sitepackage_path not in x]
92 109
93 setup_args = dict(to_dir=tmpeggs, download_delay=0) 110 setup_args = dict(to_dir=tmpeggs, download_delay=0)
94 111
95 if options.setuptools_version is not None: 112 if options.setuptools_version is not None:
96 setup_args['version'] = options.setuptools_version 113 setup_args['version'] = options.setuptools_version
  114 +if options.setuptools_to_dir is not None:
  115 + setup_args['to_dir'] = options.setuptools_to_dir
97 116
98 ez['use_setuptools'](**setup_args) 117 ez['use_setuptools'](**setup_args)
99 import setuptools 118 import setuptools
@@ -110,7 +129,12 @@ for path in sys.path: @@ -110,7 +129,12 @@ for path in sys.path:
110 129
111 ws = pkg_resources.working_set 130 ws = pkg_resources.working_set
112 131
  132 +setuptools_path = ws.find(
  133 + pkg_resources.Requirement.parse('setuptools')).location
  134 +
  135 +# Fix sys.path here as easy_install.pth added before PYTHONPATH
113 cmd = [sys.executable, '-c', 136 cmd = [sys.executable, '-c',
  137 + 'import sys; sys.path[0:0] = [%r]; ' % setuptools_path +
114 'from setuptools.command.easy_install import main; main()', 138 'from setuptools.command.easy_install import main; main()',
115 '-mZqNxd', tmpeggs] 139 '-mZqNxd', tmpeggs]
116 140
@@ -123,11 +147,8 @@ find_links = os.environ.get( @@ -123,11 +147,8 @@ find_links = os.environ.get(
123 if find_links: 147 if find_links:
124 cmd.extend(['-f', find_links]) 148 cmd.extend(['-f', find_links])
125 149
126 -setuptools_path = ws.find(  
127 - pkg_resources.Requirement.parse('setuptools')).location  
128 -  
129 requirement = 'zc.buildout' 150 requirement = 'zc.buildout'
130 -version = options.version 151 +version = options.buildout_version
131 if version is None and not options.accept_buildout_test_releases: 152 if version is None and not options.accept_buildout_test_releases:
132 # Figure out the most recent final version of zc.buildout. 153 # Figure out the most recent final version of zc.buildout.
133 import setuptools.package_index 154 import setuptools.package_index
@@ -167,7 +188,7 @@ if version: @@ -167,7 +188,7 @@ if version:
167 cmd.append(requirement) 188 cmd.append(requirement)
168 189
169 import subprocess 190 import subprocess
170 -if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: 191 +if subprocess.call(cmd) != 0:
171 raise Exception( 192 raise Exception(
172 "Failed to execute command:\n%s" % repr(cmd)[1:-1]) 193 "Failed to execute command:\n%s" % repr(cmd)[1:-1])
173 194
Please register or login to post a comment