1##############################################################################
3# Copyright (c) 2006 Zope Foundation and Contributors.
6# This software is subject to the provisions of the Zope Public License,
7# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11# FOR A PARTICULAR PURPOSE.
13##############################################################################
14"""Bootstrap a buildout-based project
16Simply run this script in a directory containing a buildout.cfg.
17The script accepts buildout command-line options, so you can
18use the -c option to specify an alternate configuration file.
21import os, shutil, sys, tempfile, urllib, urllib2, subprocess
22from optparse import OptionParser
24if sys.platform == 'win32':
27 return '"%s"' % c # work around spawn lamosity on windows
33# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
34stdout, stderr = subprocess.Popen(
35 [sys.executable, '-Sc',
37 ' import ConfigParser\n'
38 'except ImportError:\n'
42 stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
43has_broken_dash_S = bool(int(stdout.strip()))
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.
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.
70is_jython = sys.platform.startswith('java')
72setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
73distribute_source = 'http://python-distribute.org/distribute_setup.py'
74distribute_source = 'https://bitbucket.org/pypa/setuptools/raw/f657df1f1ed46596d236376649c99a470662b4ba/distribute_setup.py'
77def normalize_to_url(option, opt_str, value, parser):
79 if '://' not in value: # It doesn't smell like a URL.
80 value = 'file://%s' % (
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.
88 name = opt_str[2:].replace('-', '_')
89 setattr(parser.values, name, value)
92[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
94Bootstraps a buildout-based project.
96Simply run this script in a directory containing a buildout.cfg, using the
97Python that you want bin/buildout to use.
99Note that by using --setup-source and --download-base to point to
100local resources, you can keep this script from going over the network.
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 "
137options, args = parser.parse_args()
140 eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
142 eggs_dir = tempfile.mkdtemp()
144if options.setup_source is None:
145 if options.use_distribute:
146 options.setup_source = distribute_source
148 options.setup_source = setuptools_source
150if options.accept_buildout_test_releases:
151 args.insert(0, 'buildout:accept-buildout-test-releases=true')
155 import setuptools # A flag. Sometimes pkg_resources is installed alone.
156 if not hasattr(pkg_resources, '_distribute'):
159 ez_code = urllib2.urlopen(
160 options.setup_source).read().replace('\r\n', '\n')
163 setup_args = dict(to_dir=eggs_dir, download_delay=0)
164 if options.download_base:
165 setup_args['download_base'] = options.download_base
166 if options.use_distribute:
167 setup_args['no_fake'] = True
168 if sys.version_info[:2] == (2, 4):
169 setup_args['version'] = '0.6.32'
170 ez['use_setuptools'](**setup_args)
171 if 'pkg_resources' in sys.modules:
172 reload(sys.modules['pkg_resources'])
174 # This does not (always?) update the default working set. We will
176 for path in sys.path:
177 if path not in pkg_resources.working_set.entries:
178 pkg_resources.working_set.add_entry(path)
180cmd = [quote(sys.executable),
182 quote('from setuptools.command.easy_install import main; main()'),
186if not has_broken_dash_S:
189find_links = options.download_base
191 find_links = os.environ.get('bootstrap-testing-find-links')
192if not find_links and options.accept_buildout_test_releases:
193 find_links = 'http://downloads.buildout.org/'
195 cmd.extend(['-f', quote(find_links)])
197if options.use_distribute:
198 setup_requirement = 'distribute'
200 setup_requirement = 'setuptools'
201ws = pkg_resources.working_set
202setup_requirement_path = ws.find(
203 pkg_resources.Requirement.parse(setup_requirement)).location
206 PYTHONPATH=setup_requirement_path)
208requirement = 'zc.buildout'
209version = options.version
210if version is None and not options.accept_buildout_test_releases:
211 # Figure out the most recent final version of zc.buildout.
212 import setuptools.package_index
213 _final_parts = '*final-', '*final'
215 def _final_version(parsed_version):
216 for part in parsed_version:
217 if (part[:1] == '*') and (part not in _final_parts):
220 index = setuptools.package_index.PackageIndex(
221 search_path=[setup_requirement_path])
223 index.add_find_links((find_links,))
224 req = pkg_resources.Requirement.parse(requirement)
225 if index.obtain(req) is not None:
228 for dist in index[req.project_name]:
229 distv = dist.parsed_version
230 if distv >= pkg_resources.parse_version('2dev'):
232 if _final_version(distv):
233 if bestv is None or distv > bestv:
240 version = best[-1].version
243 requirement += '=='+version
245 requirement += '<2dev'
247cmd.append(requirement)
251 exitcode = subprocess.Popen(cmd, env=env).wait()
252else: # Windows prefers this, apparently; otherwise we would prefer subprocess
253 exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
257 print ("An error occurred when trying to install zc.buildout. "
258 "Look above this message for any errors that "
259 "were output by easy_install.")
262ws.add_entry(eggs_dir)
263ws.require(requirement)
264import zc.buildout.buildout
266# If there isn't already a command in the args, add bootstrap
267if not [a for a in args if '=' not in a]:
268 args.append('bootstrap')
271# if -c was provided, we push it back into args for buildout's main function
272if options.config_file is not None:
273 args[0:0] = ['-c', options.config_file]
275zc.buildout.buildout.main(args)
276if not options.eggs: # clean up temporary egg directory
277 shutil.rmtree(eggs_dir)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list