Merge lp:~frankban/lpsetup/add-buildout into lp:lpsetup

Proposed by Francesco Banconi on 2012-03-14
Status: Merged
Merged at revision: 3
Proposed branch: lp:~frankban/lpsetup/add-buildout
Merge into: lp:lpsetup
Diff against target: 299 lines (+282/-0)
3 files modified
.bzrignore (+7/-0)
bootstrap.py (+262/-0)
buildout.cfg (+13/-0)
To merge this branch: bzr merge lp:~frankban/lpsetup/add-buildout
Reviewer Review Type Date Requested Status
Gary Poster (community) 2012-03-14 Approve on 2012-03-14
Review via email: mp+97466@code.launchpad.net

Description of the Change

Added buildout files with testing support.

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

Good, Francesco.

My biggest concern is that ./bin/test doesn't find any tests, at least when I tried it. Hooking up testrunners can be tricky.

Potentially, you could add pinning your versions, and protecting yourself from the system Python. I'd be happy to help with that, or you could look into it, or you could push it off for later/never.

I don't *think* that buildout is a Canonical technology, and pip and nose have more steam AFAIK. If you wanted to throw that together instead that would be fine with me.

Approving conditionally on getting the testing to work.

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: