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
16 Simply run this script in a directory containing a buildout.cfg.
17 The script accepts buildout command-line options, so you can
18 use the -c option to specify an alternate configuration file.
26 from optparse
import OptionParser
28 tmpeggs
= tempfile
.mkdtemp()
31 [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
33 Bootstraps a buildout-based project.
35 Simply run this script in a directory containing a buildout.cfg, using the
36 Python that you want bin/buildout to use.
38 Note that by using --find-links to point to local resources, you can keep
39 this script from going over the network.
42 parser
= OptionParser(usage
=usage
)
43 parser
.add_option("-v", "--version", help="use a specific zc.buildout version")
45 parser
.add_option("-t", "--accept-buildout-test-releases",
46 dest
='accept_buildout_test_releases',
47 action
="store_true", default
=False,
48 help=("Normally, if you do not specify a --version, the "
49 "bootstrap script and buildout gets the newest "
50 "*final* versions of zc.buildout and its recipes and "
51 "extensions for you. If you use this flag, "
52 "bootstrap and buildout will get the newest releases "
53 "even if they are alphas or betas."))
54 parser
.add_option("-c", "--config-file",
55 help=("Specify the path to the buildout configuration "
57 parser
.add_option("-f", "--find-links",
58 help=("Specify a URL to search for buildout releases"))
61 options
, args
= parser
.parse_args()
63 ######################################################################
64 # load/install setuptools
74 from urllib
.request
import urlopen
76 from urllib2
import urlopen
78 # XXX use a more permanent ez_setup.py URL when available.
79 exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
81 setup_args
= dict(to_dir
=tmpeggs
, download_delay
=0)
82 ez
['use_setuptools'](**setup_args
)
87 # This does not (always?) update the default working set. We will
90 if path
not in pkg_resources
.working_set
.entries
:
91 pkg_resources
.working_set
.add_entry(path
)
93 ######################################################################
96 ws
= pkg_resources
.working_set
98 cmd
= [sys
.executable
, '-c',
99 'from setuptools.command.easy_install import main; main()',
102 find_links
= os
.environ
.get(
103 'bootstrap-testing-find-links',
104 options
.find_links
or
105 ('http://downloads.buildout.org/'
106 if options
.accept_buildout_test_releases
else None)
109 cmd
.extend(['-f', find_links
])
111 setuptools_path
= ws
.find(
112 pkg_resources
.Requirement
.parse('setuptools')).location
114 requirement
= 'zc.buildout'
115 version
= options
.version
116 if version
is None and not options
.accept_buildout_test_releases
:
117 # Figure out the most recent final version of zc.buildout.
118 import setuptools
.package_index
119 _final_parts
= '*final-', '*final'
121 def _final_version(parsed_version
):
122 for part
in parsed_version
:
123 if (part
[:1] == '*') and (part
not in _final_parts
):
126 index
= setuptools
.package_index
.PackageIndex(
127 search_path
=[setuptools_path
])
129 index
.add_find_links((find_links
,))
130 req
= pkg_resources
.Requirement
.parse(requirement
)
131 if index
.obtain(req
) is not None:
134 for dist
in index
[req
.project_name
]:
135 distv
= dist
.parsed_version
136 if _final_version(distv
):
137 if bestv
is None or distv
> bestv
:
144 version
= best
[-1].version
146 requirement
= '=='.join((requirement
, version
))
147 cmd
.append(requirement
)
150 if subprocess
.call(cmd
, env
=dict(os
.environ
, PYTHONPATH
=setuptools_path
)) != 0:
152 "Failed to execute command:\n%s",
155 ######################################################################
156 # Import and run buildout
158 ws
.add_entry(tmpeggs
)
159 ws
.require(requirement
)
160 import zc
.buildout
.buildout
162 if not [a
for a
in args
if '=' not in a
]:
163 args
.append('bootstrap')
165 # if -c was provided, we push it back into args for buildout' main function
166 if options
.config_file
is not None:
167 args
[0:0] = ['-c', options
.config_file
]
169 zc
.buildout
.buildout
.main(args
)
170 shutil
.rmtree(tmpeggs
)