Merge lp:~bac/zope.testing/newbootstrap into lp:~launchpad/zope.testing/3.9.4-fork

Proposed by Brad Crittenden on 2012-06-28
Status: Merged
Approved by: Gary Poster on 2012-06-28
Approved revision: 46
Merged at revision: 46
Proposed branch: lp:~bac/zope.testing/newbootstrap
Merge into: lp:~launchpad/zope.testing/3.9.4-fork
Diff against target: 293 lines (+236/-42)
1 file modified
bootstrap.py (+236/-42)
To merge this branch: bzr merge lp:~bac/zope.testing/newbootstrap
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve on 2012-06-28
Yellow Squad code 2012-06-28 Pending
Review via email: mp+112562@code.launchpad.net

Commit message

Replace bootstrap.py with one that doesn't try to install to /usr/local/lib.

Description of the change

The old bootstrap.py insists on installing setup tools in /usr/local/lib, which requires sudo to do, as seen here:

http://paste.ubuntu.com/1064215/

It is replaced with a different version found at:
http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py?rev=123006

The new version does not try to install anything into the system.

Here is it running on a fresh canonistack instance:
http://paste.ubuntu.com/1064265/

To post a comment you must log in.
Gary Poster (gary) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bootstrap.py'
--- bootstrap.py 2010-06-04 14:58:44 +0000
+++ bootstrap.py 2012-06-28 13:18:39 +0000
@@ -16,53 +16,247 @@
16Simply run this script in a directory containing a buildout.cfg.16Simply run this script in a directory containing a buildout.cfg.
17The script accepts buildout command-line options, so you can17The script accepts buildout command-line options, so you can
18use the -c option to specify an alternate configuration file.18use the -c option to specify an alternate configuration file.
19
20$Id: bootstrap.py 110538 2010-04-06 03:02:54Z tseaver $
21"""19"""
2220
23import os, shutil, sys, tempfile, urllib221import os, shutil, sys, tempfile, urllib, urllib2, subprocess
2422from optparse import OptionParser
25tmpeggs = tempfile.mkdtemp()23
2624if sys.platform == 'win32':
27ez = {}25 def quote(c):
28exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'26 if ' ' in c:
29 ).read() in ez27 return '"%s"' % c # work around spawn lamosity on windows
30ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)28 else:
3129 return c
32import pkg_resources30else:
31 quote = str
32
33# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
34stdout, stderr = subprocess.Popen(
35 [sys.executable, '-Sc',
36 'try:\n'
37 ' import ConfigParser\n'
38 'except ImportError:\n'
39 ' print 1\n'
40 'else:\n'
41 ' print 0\n'],
42 stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
43has_broken_dash_S = bool(int(stdout.strip()))
44
45# In order to be more robust in the face of system Pythons, we want to
46# run without site-packages loaded. This is somewhat tricky, in
47# particular because Python 2.6's distutils imports site, so starting
48# with the -S flag is not sufficient. However, we'll start with that:
49if not has_broken_dash_S and 'site' in sys.modules:
50 # We will restart with python -S.
51 args = sys.argv[:]
52 args[0:0] = [sys.executable, '-S']
53 args = map(quote, args)
54 os.execv(sys.executable, args)
55# Now we are running with -S. We'll get the clean sys.path, import site
56# because distutils will do it later, and then reset the path and clean
57# out any namespace packages from site-packages that might have been
58# loaded by .pth files.
59clean_path = sys.path[:]
60import site # imported because of its side effects
61sys.path[:] = clean_path
62for k, v in sys.modules.items():
63 if k in ('setuptools', 'pkg_resources') or (
64 hasattr(v, '__path__') and
65 len(v.__path__) == 1 and
66 not os.path.exists(os.path.join(v.__path__[0], '__init__.py'))):
67 # This is a namespace package. Remove it.
68 sys.modules.pop(k)
3369
34is_jython = sys.platform.startswith('java')70is_jython = sys.platform.startswith('java')
3571
72setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
73distribute_source = 'http://python-distribute.org/distribute_setup.py'
74
75
76# parsing arguments
77def normalize_to_url(option, opt_str, value, parser):
78 if value:
79 if '://' not in value: # It doesn't smell like a URL.
80 value = 'file://%s' % (
81 urllib.pathname2url(
82 os.path.abspath(os.path.expanduser(value))),)
83 if opt_str == '--download-base' and not value.endswith('/'):
84 # Download base needs a trailing slash to make the world happy.
85 value += '/'
86 else:
87 value = None
88 name = opt_str[2:].replace('-', '_')
89 setattr(parser.values, name, value)
90
91usage = '''\
92[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
93
94Bootstraps a buildout-based project.
95
96Simply run this script in a directory containing a buildout.cfg, using the
97Python that you want bin/buildout to use.
98
99Note that by using --setup-source and --download-base to point to
100local resources, you can keep this script from going over the network.
101'''
102
103parser = OptionParser(usage=usage)
104parser.add_option("-v", "--version", dest="version",
105 help="use a specific zc.buildout version")
106parser.add_option("-d", "--distribute",
107 action="store_true", dest="use_distribute", default=False,
108 help="Use Distribute rather than Setuptools.")
109parser.add_option("--setup-source", action="callback", dest="setup_source",
110 callback=normalize_to_url, nargs=1, type="string",
111 help=("Specify a URL or file location for the setup file. "
112 "If you use Setuptools, this will default to " +
113 setuptools_source + "; if you use Distribute, this "
114 "will default to " + distribute_source + "."))
115parser.add_option("--download-base", action="callback", dest="download_base",
116 callback=normalize_to_url, nargs=1, type="string",
117 help=("Specify a URL or directory for downloading "
118 "zc.buildout and either Setuptools or Distribute. "
119 "Defaults to PyPI."))
120parser.add_option("--eggs",
121 help=("Specify a directory for storing eggs. Defaults to "
122 "a temporary directory that is deleted when the "
123 "bootstrap script completes."))
124parser.add_option("-t", "--accept-buildout-test-releases",
125 dest='accept_buildout_test_releases',
126 action="store_true", default=False,
127 help=("Normally, if you do not specify a --version, the "
128 "bootstrap script and buildout gets the newest "
129 "*final* versions of zc.buildout and its recipes and "
130 "extensions for you. If you use this flag, "
131 "bootstrap and buildout will get the newest releases "
132 "even if they are alphas or betas."))
133parser.add_option("-c", None, action="store", dest="config_file",
134 help=("Specify the path to the buildout configuration "
135 "file to be used."))
136
137options, args = parser.parse_args()
138
139# if -c was provided, we push it back into args for buildout's main function
140if options.config_file is not None:
141 args += ['-c', options.config_file]
142
143if options.eggs:
144 eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
145else:
146 eggs_dir = tempfile.mkdtemp()
147
148if options.setup_source is None:
149 if options.use_distribute:
150 options.setup_source = distribute_source
151 else:
152 options.setup_source = setuptools_source
153
154if options.accept_buildout_test_releases:
155 args.append('buildout:accept-buildout-test-releases=true')
156args.append('bootstrap')
157
158try:
159 import pkg_resources
160 import setuptools # A flag. Sometimes pkg_resources is installed alone.
161 if not hasattr(pkg_resources, '_distribute'):
162 raise ImportError
163except ImportError:
164 ez_code = urllib2.urlopen(
165 options.setup_source).read().replace('\r\n', '\n')
166 ez = {}
167 exec ez_code in ez
168 setup_args = dict(to_dir=eggs_dir, download_delay=0)
169 if options.download_base:
170 setup_args['download_base'] = options.download_base
171 if options.use_distribute:
172 setup_args['no_fake'] = True
173 ez['use_setuptools'](**setup_args)
174 if 'pkg_resources' in sys.modules:
175 reload(sys.modules['pkg_resources'])
176 import pkg_resources
177 # This does not (always?) update the default working set. We will
178 # do it.
179 for path in sys.path:
180 if path not in pkg_resources.working_set.entries:
181 pkg_resources.working_set.add_entry(path)
182
183cmd = [quote(sys.executable),
184 '-c',
185 quote('from setuptools.command.easy_install import main; main()'),
186 '-mqNxd',
187 quote(eggs_dir)]
188
189if not has_broken_dash_S:
190 cmd.insert(1, '-S')
191
192find_links = options.download_base
193if not find_links:
194 find_links = os.environ.get('bootstrap-testing-find-links')
195if find_links:
196 cmd.extend(['-f', quote(find_links)])
197
198if options.use_distribute:
199 setup_requirement = 'distribute'
200else:
201 setup_requirement = 'setuptools'
202ws = pkg_resources.working_set
203setup_requirement_path = ws.find(
204 pkg_resources.Requirement.parse(setup_requirement)).location
205env = dict(
206 os.environ,
207 PYTHONPATH=setup_requirement_path)
208
209requirement = 'zc.buildout'
210version = options.version
211if version is None and not options.accept_buildout_test_releases:
212 # Figure out the most recent final version of zc.buildout.
213 import setuptools.package_index
214 _final_parts = '*final-', '*final'
215
216 def _final_version(parsed_version):
217 for part in parsed_version:
218 if (part[:1] == '*') and (part not in _final_parts):
219 return False
220 return True
221 index = setuptools.package_index.PackageIndex(
222 search_path=[setup_requirement_path])
223 if find_links:
224 index.add_find_links((find_links,))
225 req = pkg_resources.Requirement.parse(requirement)
226 if index.obtain(req) is not None:
227 best = []
228 bestv = None
229 for dist in index[req.project_name]:
230 distv = dist.parsed_version
231 if _final_version(distv):
232 if bestv is None or distv > bestv:
233 best = [dist]
234 bestv = distv
235 elif distv == bestv:
236 best.append(dist)
237 if best:
238 best.sort()
239 version = best[-1].version
240if version:
241 requirement = '=='.join((requirement, version))
242cmd.append(requirement)
243
36if is_jython:244if is_jython:
37 import subprocess245 import subprocess
38246 exitcode = subprocess.Popen(cmd, env=env).wait()
39cmd = 'from setuptools.command.easy_install import main; main()'247else: # Windows prefers this, apparently; otherwise we would prefer subprocess
40if sys.platform == 'win32':248 exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
41 cmd = '"%s"' % cmd # work around spawn lamosity on windows249if exitcode != 0:
42250 sys.stdout.flush()
43ws = pkg_resources.working_set251 sys.stderr.flush()
44252 print ("An error occurred when trying to install zc.buildout. "
45if is_jython:253 "Look above this message for any errors that "
46 assert subprocess.Popen(254 "were output by easy_install.")
47 [sys.executable] + ['-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout'],255 sys.exit(exitcode)
48 env = dict(os.environ,256
49 PYTHONPATH=257ws.add_entry(eggs_dir)
50 ws.find(pkg_resources.Requirement.parse('setuptools')).location258ws.require(requirement)
51 ),
52 ).wait() == 0
53
54else:
55 assert os.spawnle(
56 os.P_WAIT, sys.executable, sys.executable,
57 '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
58 dict(os.environ,
59 PYTHONPATH=
60 ws.find(pkg_resources.Requirement.parse('setuptools')).location
61 ),
62 ) == 0
63
64ws.add_entry(tmpeggs)
65ws.require('zc.buildout')
66import zc.buildout.buildout259import zc.buildout.buildout
67zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])260zc.buildout.buildout.main(args)
68shutil.rmtree(tmpeggs)261if not options.eggs: # clean up temporary egg directory
262 shutil.rmtree(eggs_dir)

Subscribers

People subscribed via source and target branches