Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.py
More file actions
Latest commit
260 lines (234 loc) · 9.83 KB
/
Copy pathbootstrap.py
File metadata and controls
260 lines (234 loc) · 9.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bootstrap a buildout-based project
Simply run this script in a directory containing a buildout.cfg.
The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
"""
importos, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
fromoptparseimportOptionParser
ifsys.platform=='win32':
defquote(c):
if' 'inc:
return'"%s"'%c# work around spawn lamosity on windows
else:
returnc
else:
quote=str
# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
stdout, stderr=subprocess.Popen(
[sys.executable, '-Sc',
'try:\n'
' import ConfigParser\n'
'except ImportError:\n'
' print 1\n'
'else:\n'
' print 0\n'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
has_broken_dash_S=bool(int(stdout.strip()))
# In order to be more robust in the face of system Pythons, we want to
# run without site-packages loaded. This is somewhat tricky, in
# particular because Python 2.6's distutils imports site, so starting
# with the -S flag is not sufficient. However, we'll start with that:
ifnothas_broken_dash_Sand'site'insys.modules:
# We will restart with python -S.
args=sys.argv[:]
args[0:0] = [sys.executable, '-S']
args=map(quote, args)
os.execv(sys.executable, args)
# Now we are running with -S. We'll get the clean sys.path, import site
# because distutils will do it later, and then reset the path and clean
# out any namespace packages from site-packages that might have been
# loaded by .pth files.
clean_path=sys.path[:]
importsite
sys.path[:] =clean_path
fork, vinsys.modules.items():
ifkin ('setuptools', 'pkg_resources') or (
hasattr(v, '__path__') and
len(v.__path__)==1and
notos.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
# This is a namespace package. Remove it.
sys.modules.pop(k)
is_jython=sys.platform.startswith('java')
setuptools_source='http://peak.telecommunity.com/dist/ez_setup.py'
distribute_source='http://python-distribute.org/distribute_setup.py'
# parsing arguments
defnormalize_to_url(option, opt_str, value, parser):
ifvalue:
if'://'notinvalue: # It doesn't smell like a URL.
value='file://%s'% (
urllib.pathname2url(
os.path.abspath(os.path.expanduser(value))),)
ifopt_str=='--download-base'andnotvalue.endswith('/'):
# Download base needs a trailing slash to make the world happy.
value+='/'
else:
value=None
name=opt_str[2:].replace('-', '_')
setattr(parser.values, name, value)
usage='''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
Bootstraps a buildout-based project.
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --setup-source and --download-base to point to
local resources, you can keep this script from going over the network.
'''
parser=OptionParser(usage=usage)
parser.add_option("-v", "--version", dest="version",
help="use a specific zc.buildout version")
parser.add_option("-d", "--distribute",
action="store_true", dest="use_distribute", default=False,
help="Use Distribute rather than Setuptools.")
parser.add_option("--setup-source", action="callback", dest="setup_source",
callback=normalize_to_url, nargs=1, type="string",
help=("Specify a URL or file location for the setup file. "
"If you use Setuptools, this will default to "+
setuptools_source+"; if you use Distribute, this "
"will default to "+distribute_source+"."))
parser.add_option("--download-base", action="callback", dest="download_base",
callback=normalize_to_url, nargs=1, type="string",
help=("Specify a URL or directory for downloading "
"zc.buildout and either Setuptools or Distribute. "
"Defaults to PyPI."))
parser.add_option("--eggs",
help=("Specify a directory for storing eggs. Defaults to "
"a temporary directory that is deleted when the "
"bootstrap script completes."))
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", None, action="store", dest="config_file",
help=("Specify the path to the buildout configuration "
"file to be used."))
options, args=parser.parse_args()
# if -c was provided, we push it back into args for buildout's main function
ifoptions.config_fileisnotNone:
args+= ['-c', options.config_file]
ifoptions.eggs:
eggs_dir=os.path.abspath(os.path.expanduser(options.eggs))
else:
eggs_dir=tempfile.mkdtemp()
ifoptions.setup_sourceisNone:
ifoptions.use_distribute:
options.setup_source=distribute_source
else:
options.setup_source=setuptools_source
ifoptions.accept_buildout_test_releases:
args.append('buildout:accept-buildout-test-releases=true')
args.append('bootstrap')
try:
importpkg_resources
importsetuptools# A flag. Sometimes pkg_resources is installed alone.
ifnothasattr(pkg_resources, '_distribute'):
raiseImportError
exceptImportError:
ez_code=urllib2.urlopen(
options.setup_source).read().replace('\r\n', '\n')
ez= {}
execez_codeinez
setup_args=dict(to_dir=eggs_dir, download_delay=0)
ifoptions.download_base:
setup_args['download_base'] =options.download_base
ifoptions.use_distribute:
setup_args['no_fake'] =True
ez['use_setuptools'](**setup_args)
if'pkg_resources'insys.modules:
reload(sys.modules['pkg_resources'])
importpkg_resources
# This does not (always?) update the default working set. We will
# do it.
forpathinsys.path:
ifpathnotinpkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
cmd= [quote(sys.executable),
'-c',
quote('from setuptools.command.easy_install import main; main()'),
'-mqNxd',
quote(eggs_dir)]
ifnothas_broken_dash_S:
cmd.insert(1, '-S')
find_links=options.download_base
ifnotfind_links:
find_links=os.environ.get('bootstrap-testing-find-links')
iffind_links:
cmd.extend(['-f', quote(find_links)])
ifoptions.use_distribute:
setup_requirement='distribute'
else:
setup_requirement='setuptools'
ws=pkg_resources.working_set
setup_requirement_path=ws.find(
pkg_resources.Requirement.parse(setup_requirement)).location
env=dict(
os.environ,
PYTHONPATH=setup_requirement_path)
requirement='zc.buildout'
version=options.version
ifversionisNoneandnotoptions.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
importsetuptools.package_index
_final_parts='*final-', '*final'
def_final_version(parsed_version):
forpartinparsed_version:
if (part[:1] =='*') and (partnotin_final_parts):
returnFalse
returnTrue
index=setuptools.package_index.PackageIndex(
search_path=[setup_requirement_path])
iffind_links:
index.add_find_links((find_links,))
req=pkg_resources.Requirement.parse(requirement)
ifindex.obtain(req) isnotNone:
best= []
bestv=None
fordistinindex[req.project_name]:
distv=dist.parsed_version
if_final_version(distv):
ifbestvisNoneordistv>bestv:
best= [dist]
bestv=distv
elifdistv==bestv:
best.append(dist)
ifbest:
best.sort()
version=best[-1].version
ifversion:
requirement='=='.join((requirement, version))
cmd.append(requirement)
ifis_jython:
importsubprocess
exitcode=subprocess.Popen(cmd, env=env).wait()
else: # Windows prefers this, apparently; otherwise we would prefer subprocess
exitcode=os.spawnle(*([os.P_WAIT, sys.executable] +cmd+ [env]))
ifexitcode!=0:
sys.stdout.flush()
sys.stderr.flush()
print ("An error occurred when trying to install zc.buildout. "
"Look above this message for any errors that "
"were output by easy_install.")
sys.exit(exitcode)
ws.add_entry(eggs_dir)
ws.require(requirement)
importzc.buildout.buildout
zc.buildout.buildout.main(args)
ifnotoptions.eggs: # clean up temporary egg directory
shutil.rmtree(eggs_dir)