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

Proposed by Brad Crittenden
Status: Merged
Approved by: Gary Poster
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
Yellow Squad code 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.
Revision history for this message
Gary Poster (gary) :
review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches