Merge lp:~sidnei/lazr-js/newer-buildout into lp:lazr-js
- newer-buildout
- Merge into toolchain
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Gary Poster | ||||
Approved revision: | 173 | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~sidnei/lazr-js/newer-buildout | ||||
Merge into: | lp:lazr-js | ||||
Diff against target: |
1085 lines (+610/-384) 6 files modified
Makefile (+3/-2) bootstrap.py (+126/-103) distribute_setup.py (+477/-0) ez_setup.py (+0/-275) setup.py (+2/-2) versions.cfg (+2/-2) |
||||
To merge this branch: | bzr merge lp:~sidnei/lazr-js/newer-buildout | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster (community) | Approve | ||
Graham Binns (community) | Abstain | ||
Review via email: mp+21417@code.launchpad.net |
Commit message
Description of the change
- Update zc.buildout to 1.4.3
- Replace setuptools by distribute, since the former doesn't work for
me anymore on Lucid.
- 172. By Sidnei da Silva
-
- Revert unwanted change
Gary Poster (gary) wrote : | # |
Hi Sidnei. Looks good, but there's a practical problem in that it doesn't work for me on Karmic. Interesting that setuptools doesn't work for you on Lucid. More below.
The Makefile fails for me on Karmic like this:
bzr checkout lp:lazr-source-dependencies download-cache
mkdir eggs
if test ! -h src-py/lazrjs ; then \
ln -s ../src-js/lazrjs src-py/lazrjs;\
fi
python -S bootstrap.py \
--distribute_
--download-
Downloading file://
Extracting in /tmp/tmpTmz0tV
Now working in /tmp/tmpTmz0tV/
Building a Distribute egg in /home/gary/
/home/gary/
Traceback (most recent call last):
File "bootstrap.py", line 147, in <module>
PYTHONPATH=
AttributeError: 'NoneType' object has no attribute 'location'
make: *** [bin/buildout] Error 1
This is a general problem with buildout and a system Python. I see we are using a hacked version of my old bootstrap.py. I've fixed this particular problem in my buildout branch for Jim. However, when I copy over my new bootstrap.py, I get a new error.
gary@garybuntu:
if test ! -h src-py/lazrjs ; then \
ln -s ../src-js/lazrjs src-py/lazrjs;\
fi
python -S bootstrap.py \
--distribute \
--download-
Downloading file://
Extracting in /tmp/tmpBtweFh
Now working in /tmp/tmpBtweFh/
Building a Distribute egg in /home/gary/
/home/gary/
/home/gary/
pkg_resources
/home/gary/
pkg_resources
Traceback (most recent call last):
File "bootstrap.py", line 179, in <module>
ws.
File "/usr/lib/
needed = self.resolve(
File "/usr/lib/
raise DistributionNot
pkg_resources.
make: *** [bin/buildout] Error 1
That's...
- 173. By Sidnei da Silva
-
- Merge from gary's branch
Gary Poster (gary) wrote : | # |
You reported my changes continued to work for you on lucid.
Heh, ok, I don't like my sys.modules thing but I don't know anything better, so sure, approved. :-)
Preview Diff
1 | === modified file 'Makefile' | |||
2 | --- Makefile 2009-12-04 17:55:51 +0000 | |||
3 | +++ Makefile 2010-03-16 15:59:22 +0000 | |||
4 | @@ -44,8 +44,9 @@ | |||
5 | 44 | ln -s ../src-js/lazrjs src-py/lazrjs;\ | 44 | ln -s ../src-js/lazrjs src-py/lazrjs;\ |
6 | 45 | fi | 45 | fi |
7 | 46 | 46 | ||
10 | 47 | $(SHHH) $(PYTHON) -S bootstrap.py\ | 47 | $(SHHH) $(PYTHON) -S bootstrap.py \ |
11 | 48 | --ez_setup-source=ez_setup.py \ | 48 | --distribute \ |
12 | 49 | --setup-source=distribute_setup.py \ | ||
13 | 49 | --download-base=download-cache/dist --eggs=eggs | 50 | --download-base=download-cache/dist --eggs=eggs |
14 | 50 | 51 | ||
15 | 51 | $(PY): bin/buildout buildout.cfg setup.py | 52 | $(PY): bin/buildout buildout.cfg setup.py |
16 | 52 | 53 | ||
17 | === modified file 'bootstrap.py' | |||
18 | --- bootstrap.py 2009-10-21 21:43:07 +0000 | |||
19 | +++ bootstrap.py 2010-03-16 15:59:22 +0000 | |||
20 | @@ -17,106 +17,121 @@ | |||
21 | 17 | The script accepts buildout command-line options, so you can | 17 | The script accepts buildout command-line options, so you can |
22 | 18 | use the -c option to specify an alternate configuration file. | 18 | use the -c option to specify an alternate configuration file. |
23 | 19 | 19 | ||
25 | 20 | $Id: bootstrap.py 101930 2009-07-15 18:34:35Z gary $ | 20 | $Id$ |
26 | 21 | """ | 21 | """ |
27 | 22 | 22 | ||
84 | 23 | import os, re, shutil, sys, tempfile, textwrap, urllib, urllib2 | 23 | import os, shutil, sys, tempfile, textwrap, urllib, urllib2 |
85 | 24 | 24 | from optparse import OptionParser | |
86 | 25 | # We have to manually parse our options rather than using one of the stdlib | 25 | |
87 | 26 | # tools because we want to pass the ones we don't recognize along to | 26 | clean_path = sys.path[:] |
88 | 27 | # zc.buildout.buildout.main. | 27 | import site |
89 | 28 | 28 | sys.path[:] = clean_path | |
90 | 29 | configuration = { | 29 | for k, v in sys.modules.items(): |
91 | 30 | '--ez_setup-source': 'http://peak.telecommunity.com/dist/ez_setup.py', | 30 | if (hasattr(v, '__path__') and |
92 | 31 | '--version': '', | 31 | len(v.__path__)==1 and |
93 | 32 | '--download-base': None, | 32 | not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))): |
94 | 33 | '--eggs': None} | 33 | # This is a namespace package. Remove it. |
95 | 34 | 34 | sys.modules.pop(k) | |
96 | 35 | helpstring = __doc__ + textwrap.dedent(''' | 35 | |
97 | 36 | This script recognizes the following options itself. The first option it | 36 | is_jython = sys.platform.startswith('java') |
98 | 37 | encounters that is not one of these will cause the script to stop parsing | 37 | |
99 | 38 | options and pass the rest on to buildout. Therefore, if you want to use | 38 | setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py' |
100 | 39 | any of the following options *and* buildout command-line options like | 39 | distribute_source = 'http://python-distribute.org/distribute_setup.py' |
101 | 40 | -c, first use the following options, and then use the buildout options. | 40 | |
102 | 41 | 41 | # parsing arguments | |
103 | 42 | Options: | 42 | def normalize_to_url(option, opt_str, value, parser): |
104 | 43 | --version=ZC_BUILDOUT_VERSION | 43 | if value: |
105 | 44 | Specify a version number of the zc.buildout to use | 44 | if '://' not in value: # It doesn't smell like a URL. |
106 | 45 | --ez_setup-source=URL_OR_FILE | 45 | value = 'file://%s' % ( |
107 | 46 | Specify a URL or file location for the ez_setup file. | 46 | urllib.pathname2url( |
108 | 47 | Defaults to | 47 | os.path.abspath(os.path.expanduser(value))),) |
109 | 48 | %(--ez_setup-source)s | 48 | if opt_str == '--download-base' and not value.endswith('/'): |
110 | 49 | --download-base=URL_OR_DIRECTORY | 49 | # Download base needs a trailing slash to make the world happy. |
111 | 50 | Specify a URL or directory for downloading setuptools and | 50 | value += '/' |
56 | 51 | zc.buildout. Defaults to PyPI. | ||
57 | 52 | --eggs=DIRECTORY | ||
58 | 53 | Specify a directory for storing eggs. Defaults to a temporary | ||
59 | 54 | directory that is deleted when the bootstrap script completes. | ||
60 | 55 | |||
61 | 56 | By using --ez_setup-source and --download-base to point to local resources, | ||
62 | 57 | you can keep this script from going over the network. | ||
63 | 58 | ''' % configuration) | ||
64 | 59 | match_equals = re.compile(r'(%s)=(.*)' % ('|'.join(configuration),)).match | ||
65 | 60 | args = sys.argv[1:] | ||
66 | 61 | if args == ['--help']: | ||
67 | 62 | print helpstring | ||
68 | 63 | sys.exit(0) | ||
69 | 64 | |||
70 | 65 | # If we end up using a temporary directory for storing our eggs, this will | ||
71 | 66 | # hold the path of that directory. On the other hand, if an explicit directory | ||
72 | 67 | # is specified in the argv, this will remain None. | ||
73 | 68 | tmpeggs = None | ||
74 | 69 | |||
75 | 70 | while args: | ||
76 | 71 | val = args[0] | ||
77 | 72 | if val in configuration: | ||
78 | 73 | del args[0] | ||
79 | 74 | if not args or args[0].startswith('-'): | ||
80 | 75 | print "ERROR: %s requires an argument." | ||
81 | 76 | print helpstring | ||
82 | 77 | sys.exit(1) | ||
83 | 78 | configuration[val] = args[0] | ||
112 | 79 | else: | 51 | else: |
133 | 80 | match = match_equals(val) | 52 | value = None |
134 | 81 | if match and match.group(1) in configuration: | 53 | name = opt_str[2:].replace('-', '_') |
135 | 82 | configuration[match.group(1)] = match.group(2) | 54 | setattr(parser.values, name, value) |
136 | 83 | else: | 55 | |
137 | 84 | break | 56 | usage = '''\ |
138 | 85 | del args[0] | 57 | [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] |
139 | 86 | 58 | ||
140 | 87 | for name in ('--ez_setup-source', '--download-base'): | 59 | Bootstraps a buildout-based project. |
141 | 88 | val = configuration[name] | 60 | |
142 | 89 | if val is not None and '://' not in val: # We're being lazy. | 61 | Simply run this script in a directory containing a buildout.cfg, using the |
143 | 90 | configuration[name] = 'file://%s' % ( | 62 | Python that you want bin/buildout to use. |
144 | 91 | urllib.pathname2url(os.path.abspath(os.path.expanduser(val))),) | 63 | |
145 | 92 | 64 | Note that by using --setup-source and --download-base to point to | |
146 | 93 | if (configuration['--download-base'] and | 65 | local resources, you can keep this script from going over the network. |
147 | 94 | not configuration['--download-base'].endswith('/')): | 66 | ''' |
148 | 95 | # Download base needs a trailing slash to make the world happy. | 67 | |
149 | 96 | configuration['--download-base'] += '/' | 68 | parser = OptionParser(usage=usage) |
150 | 97 | 69 | parser.add_option("-v", "--version", dest="version", | |
151 | 98 | if not configuration['--eggs']: | 70 | help="use a specific zc.buildout version") |
152 | 99 | configuration['--eggs'] = tmpeggs = tempfile.mkdtemp() | 71 | parser.add_option("-d", "--distribute", |
153 | 72 | action="store_true", dest="use_distribute", default=False, | ||
154 | 73 | help="Use Distribute rather than Setuptools.") | ||
155 | 74 | parser.add_option("--setup-source", action="callback", dest="setup_source", | ||
156 | 75 | callback=normalize_to_url, nargs=1, type="string", | ||
157 | 76 | help=("Specify a URL or file location for the setup file. " | ||
158 | 77 | "If you use Setuptools, this will default to " + | ||
159 | 78 | setuptools_source + "; if you use Distribute, this " | ||
160 | 79 | "will default to " + distribute_source +".")) | ||
161 | 80 | parser.add_option("--download-base", action="callback", dest="download_base", | ||
162 | 81 | callback=normalize_to_url, nargs=1, type="string", | ||
163 | 82 | help=("Specify a URL or directory for downloading " | ||
164 | 83 | "zc.buildout and either Setuptools or Distribute. " | ||
165 | 84 | "Defaults to PyPI.")) | ||
166 | 85 | parser.add_option("--eggs", | ||
167 | 86 | help=("Specify a directory for storing eggs. Defaults to " | ||
168 | 87 | "a temporary directory that is deleted when the " | ||
169 | 88 | "bootstrap script completes.")) | ||
170 | 89 | parser.add_option("-c", None, action="store", dest="config_file", | ||
171 | 90 | help=("Specify the path to the buildout configuration " | ||
172 | 91 | "file to be used.")) | ||
173 | 92 | |||
174 | 93 | options, args = parser.parse_args() | ||
175 | 94 | |||
176 | 95 | # if -c was provided, we push it back into args for buildout' main function | ||
177 | 96 | if options.config_file is not None: | ||
178 | 97 | args += ['-c', options.config_file] | ||
179 | 98 | |||
180 | 99 | if options.eggs: | ||
181 | 100 | eggs_dir = os.path.abspath(os.path.expanduser(options.eggs)) | ||
182 | 100 | else: | 101 | else: |
190 | 101 | configuration['--eggs'] = os.path.abspath( | 102 | eggs_dir = tempfile.mkdtemp() |
191 | 102 | os.path.expanduser(configuration['--eggs'])) | 103 | |
192 | 103 | 104 | if options.setup_source is None: | |
193 | 104 | # The requirement is what we will pass to setuptools to specify zc.buildout. | 105 | if options.use_distribute: |
194 | 105 | requirement = 'zc.buildout' | 106 | options.setup_source = distribute_source |
195 | 106 | if configuration['--version']: | 107 | else: |
196 | 107 | requirement += '==' + configuration['--version'] | 108 | options.setup_source = setuptools_source |
197 | 109 | |||
198 | 110 | args = args + ['bootstrap'] | ||
199 | 111 | |||
200 | 108 | 112 | ||
201 | 109 | try: | 113 | try: |
202 | 114 | to_reload = False | ||
203 | 115 | import pkg_resources | ||
204 | 116 | to_reload = True | ||
205 | 117 | if not hasattr(pkg_resources, '_distribute'): | ||
206 | 118 | raise ImportError | ||
207 | 110 | import setuptools # A flag. Sometimes pkg_resources is installed alone. | 119 | import setuptools # A flag. Sometimes pkg_resources is installed alone. |
208 | 111 | import pkg_resources | ||
209 | 112 | except ImportError: | 120 | except ImportError: |
210 | 121 | ez_code = urllib2.urlopen( | ||
211 | 122 | options.setup_source).read().replace('\r\n', '\n') | ||
212 | 113 | ez = {} | 123 | ez = {} |
219 | 114 | exec urllib2.urlopen(configuration['--ez_setup-source']).read() in ez | 124 | exec ez_code in ez |
220 | 115 | setuptools_args = dict(to_dir=configuration['--eggs'], download_delay=0) | 125 | setup_args = dict(to_dir=eggs_dir, download_delay=0) |
221 | 116 | if configuration['--download-base']: | 126 | if options.download_base: |
222 | 117 | setuptools_args['download_base'] = configuration['--download-base'] | 127 | setup_args['download_base'] = options.download_base |
223 | 118 | ez['use_setuptools'](**setuptools_args) | 128 | if options.use_distribute: |
224 | 119 | import pkg_resources | 129 | setup_args['no_fake'] = True |
225 | 130 | ez['use_setuptools'](**setup_args) | ||
226 | 131 | if to_reload: | ||
227 | 132 | reload(pkg_resources) | ||
228 | 133 | else: | ||
229 | 134 | import pkg_resources | ||
230 | 120 | # This does not (always?) update the default working set. We will | 135 | # This does not (always?) update the default working set. We will |
231 | 121 | # do it. | 136 | # do it. |
232 | 122 | for path in sys.path: | 137 | for path in sys.path: |
233 | @@ -132,39 +147,47 @@ | |||
234 | 132 | else: | 147 | else: |
235 | 133 | def quote (c): | 148 | def quote (c): |
236 | 134 | return c | 149 | return c |
237 | 150 | |||
238 | 135 | cmd = [quote(sys.executable), | 151 | cmd = [quote(sys.executable), |
239 | 136 | '-c', | 152 | '-c', |
240 | 137 | quote('from setuptools.command.easy_install import main; main()'), | 153 | quote('from setuptools.command.easy_install import main; main()'), |
241 | 138 | '-mqNxd', | 154 | '-mqNxd', |
247 | 139 | quote(configuration['--eggs'])] | 155 | quote(eggs_dir)] |
248 | 140 | 156 | ||
249 | 141 | if configuration['--download-base']: | 157 | if options.download_base: |
250 | 142 | cmd.extend(['-f', quote(configuration['--download-base'])]) | 158 | cmd.extend(['-f', quote(options.download_base)]) |
251 | 143 | 159 | ||
252 | 160 | requirement = 'zc.buildout' | ||
253 | 161 | if options.version: | ||
254 | 162 | requirement = '=='.join((requirement, options.version)) | ||
255 | 144 | cmd.append(requirement) | 163 | cmd.append(requirement) |
256 | 145 | 164 | ||
257 | 165 | if options.use_distribute: | ||
258 | 166 | setup_requirement = 'distribute' | ||
259 | 167 | else: | ||
260 | 168 | setup_requirement = 'setuptools' | ||
261 | 146 | ws = pkg_resources.working_set | 169 | ws = pkg_resources.working_set |
262 | 147 | env = dict( | 170 | env = dict( |
263 | 148 | os.environ, | 171 | os.environ, |
265 | 149 | PYTHONPATH=ws.find(pkg_resources.Requirement.parse('setuptools')).location) | 172 | PYTHONPATH=ws.find( |
266 | 173 | pkg_resources.Requirement.parse(setup_requirement)).location) | ||
267 | 150 | 174 | ||
268 | 151 | is_jython = sys.platform.startswith('java') | ||
269 | 152 | if is_jython: | 175 | if is_jython: |
270 | 153 | import subprocess | 176 | import subprocess |
271 | 154 | exitcode = subprocess.Popen(cmd, env=env).wait() | 177 | exitcode = subprocess.Popen(cmd, env=env).wait() |
273 | 155 | else: # Windows needs this, apparently; otherwise we would prefer subprocess | 178 | else: # Windows prefers this, apparently; otherwise we would prefer subprocess |
274 | 156 | exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env])) | 179 | exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env])) |
275 | 157 | if exitcode != 0: | 180 | if exitcode != 0: |
276 | 158 | sys.stdout.flush() | 181 | sys.stdout.flush() |
277 | 182 | sys.stderr.flush() | ||
278 | 159 | print ("An error occured when trying to install zc.buildout. " | 183 | print ("An error occured when trying to install zc.buildout. " |
279 | 160 | "Look above this message for any errors that " | 184 | "Look above this message for any errors that " |
280 | 161 | "were output by easy_install.") | 185 | "were output by easy_install.") |
281 | 162 | sys.exit(exitcode) | 186 | sys.exit(exitcode) |
282 | 163 | 187 | ||
284 | 164 | ws.add_entry(configuration['--eggs']) | 188 | ws.add_entry(eggs_dir) |
285 | 165 | ws.require(requirement) | 189 | ws.require(requirement) |
286 | 166 | import zc.buildout.buildout | 190 | import zc.buildout.buildout |
287 | 167 | args.append('bootstrap') | ||
288 | 168 | zc.buildout.buildout.main(args) | 191 | zc.buildout.buildout.main(args) |
291 | 169 | if tmpeggs is not None: | 192 | if not options.eggs: # clean up temporary egg directory |
292 | 170 | shutil.rmtree(tmpeggs) | 193 | shutil.rmtree(eggs_dir) |
293 | 171 | 194 | ||
294 | === added file 'distribute_setup.py' | |||
295 | --- distribute_setup.py 1970-01-01 00:00:00 +0000 | |||
296 | +++ distribute_setup.py 2010-03-16 15:59:22 +0000 | |||
297 | @@ -0,0 +1,477 @@ | |||
298 | 1 | #!python | ||
299 | 2 | """Bootstrap distribute installation | ||
300 | 3 | |||
301 | 4 | If you want to use setuptools in your package's setup.py, just include this | ||
302 | 5 | file in the same directory with it, and add this to the top of your setup.py:: | ||
303 | 6 | |||
304 | 7 | from distribute_setup import use_setuptools | ||
305 | 8 | use_setuptools() | ||
306 | 9 | |||
307 | 10 | If you want to require a specific version of setuptools, set a download | ||
308 | 11 | mirror, or use an alternate download directory, you can do so by supplying | ||
309 | 12 | the appropriate options to ``use_setuptools()``. | ||
310 | 13 | |||
311 | 14 | This file can also be run as a script to install or upgrade setuptools. | ||
312 | 15 | """ | ||
313 | 16 | import os | ||
314 | 17 | import sys | ||
315 | 18 | import time | ||
316 | 19 | import fnmatch | ||
317 | 20 | import tempfile | ||
318 | 21 | import tarfile | ||
319 | 22 | from distutils import log | ||
320 | 23 | |||
321 | 24 | try: | ||
322 | 25 | from site import USER_SITE | ||
323 | 26 | except ImportError: | ||
324 | 27 | USER_SITE = None | ||
325 | 28 | |||
326 | 29 | try: | ||
327 | 30 | import subprocess | ||
328 | 31 | |||
329 | 32 | def _python_cmd(*args): | ||
330 | 33 | args = (sys.executable,) + args | ||
331 | 34 | return subprocess.call(args) == 0 | ||
332 | 35 | |||
333 | 36 | except ImportError: | ||
334 | 37 | # will be used for python 2.3 | ||
335 | 38 | def _python_cmd(*args): | ||
336 | 39 | args = (sys.executable,) + args | ||
337 | 40 | # quoting arguments if windows | ||
338 | 41 | if sys.platform == 'win32': | ||
339 | 42 | def quote(arg): | ||
340 | 43 | if ' ' in arg: | ||
341 | 44 | return '"%s"' % arg | ||
342 | 45 | return arg | ||
343 | 46 | args = [quote(arg) for arg in args] | ||
344 | 47 | return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 | ||
345 | 48 | |||
346 | 49 | DEFAULT_VERSION = "0.6.10" | ||
347 | 50 | DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" | ||
348 | 51 | SETUPTOOLS_FAKED_VERSION = "0.6c11" | ||
349 | 52 | |||
350 | 53 | SETUPTOOLS_PKG_INFO = """\ | ||
351 | 54 | Metadata-Version: 1.0 | ||
352 | 55 | Name: setuptools | ||
353 | 56 | Version: %s | ||
354 | 57 | Summary: xxxx | ||
355 | 58 | Home-page: xxx | ||
356 | 59 | Author: xxx | ||
357 | 60 | Author-email: xxx | ||
358 | 61 | License: xxx | ||
359 | 62 | Description: xxx | ||
360 | 63 | """ % SETUPTOOLS_FAKED_VERSION | ||
361 | 64 | |||
362 | 65 | |||
363 | 66 | def _install(tarball): | ||
364 | 67 | # extracting the tarball | ||
365 | 68 | tmpdir = tempfile.mkdtemp() | ||
366 | 69 | log.warn('Extracting in %s', tmpdir) | ||
367 | 70 | old_wd = os.getcwd() | ||
368 | 71 | try: | ||
369 | 72 | os.chdir(tmpdir) | ||
370 | 73 | tar = tarfile.open(tarball) | ||
371 | 74 | _extractall(tar) | ||
372 | 75 | tar.close() | ||
373 | 76 | |||
374 | 77 | # going in the directory | ||
375 | 78 | subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) | ||
376 | 79 | os.chdir(subdir) | ||
377 | 80 | log.warn('Now working in %s', subdir) | ||
378 | 81 | |||
379 | 82 | # installing | ||
380 | 83 | log.warn('Installing Distribute') | ||
381 | 84 | if not _python_cmd('setup.py', 'install'): | ||
382 | 85 | log.warn('Something went wrong during the installation.') | ||
383 | 86 | log.warn('See the error message above.') | ||
384 | 87 | finally: | ||
385 | 88 | os.chdir(old_wd) | ||
386 | 89 | |||
387 | 90 | |||
388 | 91 | def _build_egg(egg, tarball, to_dir): | ||
389 | 92 | # extracting the tarball | ||
390 | 93 | tmpdir = tempfile.mkdtemp() | ||
391 | 94 | log.warn('Extracting in %s', tmpdir) | ||
392 | 95 | old_wd = os.getcwd() | ||
393 | 96 | try: | ||
394 | 97 | os.chdir(tmpdir) | ||
395 | 98 | tar = tarfile.open(tarball) | ||
396 | 99 | _extractall(tar) | ||
397 | 100 | tar.close() | ||
398 | 101 | |||
399 | 102 | # going in the directory | ||
400 | 103 | subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) | ||
401 | 104 | os.chdir(subdir) | ||
402 | 105 | log.warn('Now working in %s', subdir) | ||
403 | 106 | |||
404 | 107 | # building an egg | ||
405 | 108 | log.warn('Building a Distribute egg in %s', to_dir) | ||
406 | 109 | _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) | ||
407 | 110 | |||
408 | 111 | finally: | ||
409 | 112 | os.chdir(old_wd) | ||
410 | 113 | # returning the result | ||
411 | 114 | log.warn(egg) | ||
412 | 115 | if not os.path.exists(egg): | ||
413 | 116 | raise IOError('Could not build the egg.') | ||
414 | 117 | |||
415 | 118 | |||
416 | 119 | def _do_download(version, download_base, to_dir, download_delay): | ||
417 | 120 | egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' | ||
418 | 121 | % (version, sys.version_info[0], sys.version_info[1])) | ||
419 | 122 | if not os.path.exists(egg): | ||
420 | 123 | tarball = download_setuptools(version, download_base, | ||
421 | 124 | to_dir, download_delay) | ||
422 | 125 | _build_egg(egg, tarball, to_dir) | ||
423 | 126 | sys.path.insert(0, egg) | ||
424 | 127 | import setuptools | ||
425 | 128 | setuptools.bootstrap_install_from = egg | ||
426 | 129 | |||
427 | 130 | |||
428 | 131 | def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | ||
429 | 132 | to_dir=os.curdir, download_delay=15, no_fake=True): | ||
430 | 133 | # making sure we use the absolute path | ||
431 | 134 | to_dir = os.path.abspath(to_dir) | ||
432 | 135 | was_imported = 'pkg_resources' in sys.modules or \ | ||
433 | 136 | 'setuptools' in sys.modules | ||
434 | 137 | try: | ||
435 | 138 | try: | ||
436 | 139 | import pkg_resources | ||
437 | 140 | if not hasattr(pkg_resources, '_distribute'): | ||
438 | 141 | if not no_fake: | ||
439 | 142 | _fake_setuptools() | ||
440 | 143 | raise ImportError | ||
441 | 144 | except ImportError: | ||
442 | 145 | return _do_download(version, download_base, to_dir, download_delay) | ||
443 | 146 | try: | ||
444 | 147 | pkg_resources.require("distribute>="+version) | ||
445 | 148 | return | ||
446 | 149 | except pkg_resources.VersionConflict: | ||
447 | 150 | e = sys.exc_info()[1] | ||
448 | 151 | if was_imported: | ||
449 | 152 | sys.stderr.write( | ||
450 | 153 | "The required version of distribute (>=%s) is not available,\n" | ||
451 | 154 | "and can't be installed while this script is running. Please\n" | ||
452 | 155 | "install a more recent version first, using\n" | ||
453 | 156 | "'easy_install -U distribute'." | ||
454 | 157 | "\n\n(Currently using %r)\n" % (version, e.args[0])) | ||
455 | 158 | sys.exit(2) | ||
456 | 159 | else: | ||
457 | 160 | del pkg_resources, sys.modules['pkg_resources'] # reload ok | ||
458 | 161 | return _do_download(version, download_base, to_dir, | ||
459 | 162 | download_delay) | ||
460 | 163 | except pkg_resources.DistributionNotFound: | ||
461 | 164 | return _do_download(version, download_base, to_dir, | ||
462 | 165 | download_delay) | ||
463 | 166 | finally: | ||
464 | 167 | if not no_fake: | ||
465 | 168 | _create_fake_setuptools_pkg_info(to_dir) | ||
466 | 169 | |||
467 | 170 | def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | ||
468 | 171 | to_dir=os.curdir, delay=15): | ||
469 | 172 | """Download distribute from a specified location and return its filename | ||
470 | 173 | |||
471 | 174 | `version` should be a valid distribute version number that is available | ||
472 | 175 | as an egg for download under the `download_base` URL (which should end | ||
473 | 176 | with a '/'). `to_dir` is the directory where the egg will be downloaded. | ||
474 | 177 | `delay` is the number of seconds to pause before an actual download | ||
475 | 178 | attempt. | ||
476 | 179 | """ | ||
477 | 180 | # making sure we use the absolute path | ||
478 | 181 | to_dir = os.path.abspath(to_dir) | ||
479 | 182 | try: | ||
480 | 183 | from urllib.request import urlopen | ||
481 | 184 | except ImportError: | ||
482 | 185 | from urllib2 import urlopen | ||
483 | 186 | tgz_name = "distribute-%s.tar.gz" % version | ||
484 | 187 | url = download_base + tgz_name | ||
485 | 188 | saveto = os.path.join(to_dir, tgz_name) | ||
486 | 189 | src = dst = None | ||
487 | 190 | if not os.path.exists(saveto): # Avoid repeated downloads | ||
488 | 191 | try: | ||
489 | 192 | log.warn("Downloading %s", url) | ||
490 | 193 | src = urlopen(url) | ||
491 | 194 | # Read/write all in one block, so we don't create a corrupt file | ||
492 | 195 | # if the download is interrupted. | ||
493 | 196 | data = src.read() | ||
494 | 197 | dst = open(saveto, "wb") | ||
495 | 198 | dst.write(data) | ||
496 | 199 | finally: | ||
497 | 200 | if src: | ||
498 | 201 | src.close() | ||
499 | 202 | if dst: | ||
500 | 203 | dst.close() | ||
501 | 204 | return os.path.realpath(saveto) | ||
502 | 205 | |||
503 | 206 | |||
504 | 207 | def _patch_file(path, content): | ||
505 | 208 | """Will backup the file then patch it""" | ||
506 | 209 | existing_content = open(path).read() | ||
507 | 210 | if existing_content == content: | ||
508 | 211 | # already patched | ||
509 | 212 | log.warn('Already patched.') | ||
510 | 213 | return False | ||
511 | 214 | log.warn('Patching...') | ||
512 | 215 | _rename_path(path) | ||
513 | 216 | f = open(path, 'w') | ||
514 | 217 | try: | ||
515 | 218 | f.write(content) | ||
516 | 219 | finally: | ||
517 | 220 | f.close() | ||
518 | 221 | return True | ||
519 | 222 | |||
520 | 223 | |||
521 | 224 | def _same_content(path, content): | ||
522 | 225 | return open(path).read() == content | ||
523 | 226 | |||
524 | 227 | def _no_sandbox(function): | ||
525 | 228 | def __no_sandbox(*args, **kw): | ||
526 | 229 | try: | ||
527 | 230 | from setuptools.sandbox import DirectorySandbox | ||
528 | 231 | def violation(*args): | ||
529 | 232 | pass | ||
530 | 233 | DirectorySandbox._old = DirectorySandbox._violation | ||
531 | 234 | DirectorySandbox._violation = violation | ||
532 | 235 | patched = True | ||
533 | 236 | except ImportError: | ||
534 | 237 | patched = False | ||
535 | 238 | |||
536 | 239 | try: | ||
537 | 240 | return function(*args, **kw) | ||
538 | 241 | finally: | ||
539 | 242 | if patched: | ||
540 | 243 | DirectorySandbox._violation = DirectorySandbox._old | ||
541 | 244 | del DirectorySandbox._old | ||
542 | 245 | |||
543 | 246 | return __no_sandbox | ||
544 | 247 | |||
545 | 248 | @_no_sandbox | ||
546 | 249 | def _rename_path(path): | ||
547 | 250 | new_name = path + '.OLD.%s' % time.time() | ||
548 | 251 | log.warn('Renaming %s into %s', path, new_name) | ||
549 | 252 | os.rename(path, new_name) | ||
550 | 253 | return new_name | ||
551 | 254 | |||
552 | 255 | def _remove_flat_installation(placeholder): | ||
553 | 256 | if not os.path.isdir(placeholder): | ||
554 | 257 | log.warn('Unkown installation at %s', placeholder) | ||
555 | 258 | return False | ||
556 | 259 | found = False | ||
557 | 260 | for file in os.listdir(placeholder): | ||
558 | 261 | if fnmatch.fnmatch(file, 'setuptools*.egg-info'): | ||
559 | 262 | found = True | ||
560 | 263 | break | ||
561 | 264 | if not found: | ||
562 | 265 | log.warn('Could not locate setuptools*.egg-info') | ||
563 | 266 | return | ||
564 | 267 | |||
565 | 268 | log.warn('Removing elements out of the way...') | ||
566 | 269 | pkg_info = os.path.join(placeholder, file) | ||
567 | 270 | if os.path.isdir(pkg_info): | ||
568 | 271 | patched = _patch_egg_dir(pkg_info) | ||
569 | 272 | else: | ||
570 | 273 | patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) | ||
571 | 274 | |||
572 | 275 | if not patched: | ||
573 | 276 | log.warn('%s already patched.', pkg_info) | ||
574 | 277 | return False | ||
575 | 278 | # now let's move the files out of the way | ||
576 | 279 | for element in ('setuptools', 'pkg_resources.py', 'site.py'): | ||
577 | 280 | element = os.path.join(placeholder, element) | ||
578 | 281 | if os.path.exists(element): | ||
579 | 282 | _rename_path(element) | ||
580 | 283 | else: | ||
581 | 284 | log.warn('Could not find the %s element of the ' | ||
582 | 285 | 'Setuptools distribution', element) | ||
583 | 286 | return True | ||
584 | 287 | |||
585 | 288 | |||
586 | 289 | def _after_install(dist): | ||
587 | 290 | log.warn('After install bootstrap.') | ||
588 | 291 | placeholder = dist.get_command_obj('install').install_purelib | ||
589 | 292 | _create_fake_setuptools_pkg_info(placeholder) | ||
590 | 293 | |||
591 | 294 | @_no_sandbox | ||
592 | 295 | def _create_fake_setuptools_pkg_info(placeholder): | ||
593 | 296 | if not placeholder or not os.path.exists(placeholder): | ||
594 | 297 | log.warn('Could not find the install location') | ||
595 | 298 | return | ||
596 | 299 | pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) | ||
597 | 300 | setuptools_file = 'setuptools-%s-py%s.egg-info' % \ | ||
598 | 301 | (SETUPTOOLS_FAKED_VERSION, pyver) | ||
599 | 302 | pkg_info = os.path.join(placeholder, setuptools_file) | ||
600 | 303 | if os.path.exists(pkg_info): | ||
601 | 304 | log.warn('%s already exists', pkg_info) | ||
602 | 305 | return | ||
603 | 306 | |||
604 | 307 | log.warn('Creating %s', pkg_info) | ||
605 | 308 | f = open(pkg_info, 'w') | ||
606 | 309 | try: | ||
607 | 310 | f.write(SETUPTOOLS_PKG_INFO) | ||
608 | 311 | finally: | ||
609 | 312 | f.close() | ||
610 | 313 | |||
611 | 314 | pth_file = os.path.join(placeholder, 'setuptools.pth') | ||
612 | 315 | log.warn('Creating %s', pth_file) | ||
613 | 316 | f = open(pth_file, 'w') | ||
614 | 317 | try: | ||
615 | 318 | f.write(os.path.join(os.curdir, setuptools_file)) | ||
616 | 319 | finally: | ||
617 | 320 | f.close() | ||
618 | 321 | |||
619 | 322 | def _patch_egg_dir(path): | ||
620 | 323 | # let's check if it's already patched | ||
621 | 324 | pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') | ||
622 | 325 | if os.path.exists(pkg_info): | ||
623 | 326 | if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): | ||
624 | 327 | log.warn('%s already patched.', pkg_info) | ||
625 | 328 | return False | ||
626 | 329 | _rename_path(path) | ||
627 | 330 | os.mkdir(path) | ||
628 | 331 | os.mkdir(os.path.join(path, 'EGG-INFO')) | ||
629 | 332 | pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') | ||
630 | 333 | f = open(pkg_info, 'w') | ||
631 | 334 | try: | ||
632 | 335 | f.write(SETUPTOOLS_PKG_INFO) | ||
633 | 336 | finally: | ||
634 | 337 | f.close() | ||
635 | 338 | return True | ||
636 | 339 | |||
637 | 340 | |||
638 | 341 | def _before_install(): | ||
639 | 342 | log.warn('Before install bootstrap.') | ||
640 | 343 | _fake_setuptools() | ||
641 | 344 | |||
642 | 345 | |||
643 | 346 | def _under_prefix(location): | ||
644 | 347 | if 'install' not in sys.argv: | ||
645 | 348 | return True | ||
646 | 349 | args = sys.argv[sys.argv.index('install')+1:] | ||
647 | 350 | for index, arg in enumerate(args): | ||
648 | 351 | for option in ('--root', '--prefix'): | ||
649 | 352 | if arg.startswith('%s=' % option): | ||
650 | 353 | top_dir = arg.split('root=')[-1] | ||
651 | 354 | return location.startswith(top_dir) | ||
652 | 355 | elif arg == option: | ||
653 | 356 | if len(args) > index: | ||
654 | 357 | top_dir = args[index+1] | ||
655 | 358 | return location.startswith(top_dir) | ||
656 | 359 | elif option == '--user' and USER_SITE is not None: | ||
657 | 360 | return location.startswith(USER_SITE) | ||
658 | 361 | return True | ||
659 | 362 | |||
660 | 363 | |||
661 | 364 | def _fake_setuptools(): | ||
662 | 365 | log.warn('Scanning installed packages') | ||
663 | 366 | try: | ||
664 | 367 | import pkg_resources | ||
665 | 368 | except ImportError: | ||
666 | 369 | # we're cool | ||
667 | 370 | log.warn('Setuptools or Distribute does not seem to be installed.') | ||
668 | 371 | return | ||
669 | 372 | ws = pkg_resources.working_set | ||
670 | 373 | try: | ||
671 | 374 | setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', | ||
672 | 375 | replacement=False)) | ||
673 | 376 | except TypeError: | ||
674 | 377 | # old distribute API | ||
675 | 378 | setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) | ||
676 | 379 | |||
677 | 380 | if setuptools_dist is None: | ||
678 | 381 | log.warn('No setuptools distribution found') | ||
679 | 382 | return | ||
680 | 383 | # detecting if it was already faked | ||
681 | 384 | setuptools_location = setuptools_dist.location | ||
682 | 385 | log.warn('Setuptools installation detected at %s', setuptools_location) | ||
683 | 386 | |||
684 | 387 | # if --root or --preix was provided, and if | ||
685 | 388 | # setuptools is not located in them, we don't patch it | ||
686 | 389 | if not _under_prefix(setuptools_location): | ||
687 | 390 | log.warn('Not patching, --root or --prefix is installing Distribute' | ||
688 | 391 | ' in another location') | ||
689 | 392 | return | ||
690 | 393 | |||
691 | 394 | # let's see if its an egg | ||
692 | 395 | if not setuptools_location.endswith('.egg'): | ||
693 | 396 | log.warn('Non-egg installation') | ||
694 | 397 | res = _remove_flat_installation(setuptools_location) | ||
695 | 398 | if not res: | ||
696 | 399 | return | ||
697 | 400 | else: | ||
698 | 401 | log.warn('Egg installation') | ||
699 | 402 | pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') | ||
700 | 403 | if (os.path.exists(pkg_info) and | ||
701 | 404 | _same_content(pkg_info, SETUPTOOLS_PKG_INFO)): | ||
702 | 405 | log.warn('Already patched.') | ||
703 | 406 | return | ||
704 | 407 | log.warn('Patching...') | ||
705 | 408 | # let's create a fake egg replacing setuptools one | ||
706 | 409 | res = _patch_egg_dir(setuptools_location) | ||
707 | 410 | if not res: | ||
708 | 411 | return | ||
709 | 412 | log.warn('Patched done.') | ||
710 | 413 | _relaunch() | ||
711 | 414 | |||
712 | 415 | |||
713 | 416 | def _relaunch(): | ||
714 | 417 | log.warn('Relaunching...') | ||
715 | 418 | # we have to relaunch the process | ||
716 | 419 | args = [sys.executable] + sys.argv | ||
717 | 420 | sys.exit(subprocess.call(args)) | ||
718 | 421 | |||
719 | 422 | |||
720 | 423 | def _extractall(self, path=".", members=None): | ||
721 | 424 | """Extract all members from the archive to the current working | ||
722 | 425 | directory and set owner, modification time and permissions on | ||
723 | 426 | directories afterwards. `path' specifies a different directory | ||
724 | 427 | to extract to. `members' is optional and must be a subset of the | ||
725 | 428 | list returned by getmembers(). | ||
726 | 429 | """ | ||
727 | 430 | import copy | ||
728 | 431 | import operator | ||
729 | 432 | from tarfile import ExtractError | ||
730 | 433 | directories = [] | ||
731 | 434 | |||
732 | 435 | if members is None: | ||
733 | 436 | members = self | ||
734 | 437 | |||
735 | 438 | for tarinfo in members: | ||
736 | 439 | if tarinfo.isdir(): | ||
737 | 440 | # Extract directories with a safe mode. | ||
738 | 441 | directories.append(tarinfo) | ||
739 | 442 | tarinfo = copy.copy(tarinfo) | ||
740 | 443 | tarinfo.mode = 448 # decimal for oct 0700 | ||
741 | 444 | self.extract(tarinfo, path) | ||
742 | 445 | |||
743 | 446 | # Reverse sort directories. | ||
744 | 447 | if sys.version_info < (2, 4): | ||
745 | 448 | def sorter(dir1, dir2): | ||
746 | 449 | return cmp(dir1.name, dir2.name) | ||
747 | 450 | directories.sort(sorter) | ||
748 | 451 | directories.reverse() | ||
749 | 452 | else: | ||
750 | 453 | directories.sort(key=operator.attrgetter('name'), reverse=True) | ||
751 | 454 | |||
752 | 455 | # Set correct owner, mtime and filemode on directories. | ||
753 | 456 | for tarinfo in directories: | ||
754 | 457 | dirpath = os.path.join(path, tarinfo.name) | ||
755 | 458 | try: | ||
756 | 459 | self.chown(tarinfo, dirpath) | ||
757 | 460 | self.utime(tarinfo, dirpath) | ||
758 | 461 | self.chmod(tarinfo, dirpath) | ||
759 | 462 | except ExtractError: | ||
760 | 463 | e = sys.exc_info()[1] | ||
761 | 464 | if self.errorlevel > 1: | ||
762 | 465 | raise | ||
763 | 466 | else: | ||
764 | 467 | self._dbg(1, "tarfile: %s" % e) | ||
765 | 468 | |||
766 | 469 | |||
767 | 470 | def main(argv, version=DEFAULT_VERSION): | ||
768 | 471 | """Install or upgrade setuptools and EasyInstall""" | ||
769 | 472 | tarball = download_setuptools() | ||
770 | 473 | _install(tarball) | ||
771 | 474 | |||
772 | 475 | |||
773 | 476 | if __name__ == '__main__': | ||
774 | 477 | main(sys.argv[1:]) | ||
775 | 0 | 478 | ||
776 | === removed file 'ez_setup.py' | |||
777 | --- ez_setup.py 2009-10-21 21:43:07 +0000 | |||
778 | +++ ez_setup.py 1970-01-01 00:00:00 +0000 | |||
779 | @@ -1,275 +0,0 @@ | |||
780 | 1 | #!python | ||
781 | 2 | """Bootstrap setuptools installation | ||
782 | 3 | |||
783 | 4 | If you want to use setuptools in your package's setup.py, just include this | ||
784 | 5 | file in the same directory with it, and add this to the top of your setup.py:: | ||
785 | 6 | |||
786 | 7 | from ez_setup import use_setuptools | ||
787 | 8 | use_setuptools() | ||
788 | 9 | |||
789 | 10 | If you want to require a specific version of setuptools, set a download | ||
790 | 11 | mirror, or use an alternate download directory, you can do so by supplying | ||
791 | 12 | the appropriate options to ``use_setuptools()``. | ||
792 | 13 | |||
793 | 14 | This file can also be run as a script to install or upgrade setuptools. | ||
794 | 15 | """ | ||
795 | 16 | import sys | ||
796 | 17 | DEFAULT_VERSION = "0.6c9" | ||
797 | 18 | DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] | ||
798 | 19 | |||
799 | 20 | md5_data = { | ||
800 | 21 | 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', | ||
801 | 22 | 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', | ||
802 | 23 | 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', | ||
803 | 24 | 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', | ||
804 | 25 | 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', | ||
805 | 26 | 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', | ||
806 | 27 | 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', | ||
807 | 28 | 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', | ||
808 | 29 | 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', | ||
809 | 30 | 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', | ||
810 | 31 | 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', | ||
811 | 32 | 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', | ||
812 | 33 | 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', | ||
813 | 34 | 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', | ||
814 | 35 | 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', | ||
815 | 36 | 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', | ||
816 | 37 | 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', | ||
817 | 38 | 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', | ||
818 | 39 | 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', | ||
819 | 40 | 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', | ||
820 | 41 | 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', | ||
821 | 42 | 'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20', | ||
822 | 43 | 'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab', | ||
823 | 44 | 'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53', | ||
824 | 45 | 'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2', | ||
825 | 46 | 'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e', | ||
826 | 47 | 'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372', | ||
827 | 48 | 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', | ||
828 | 49 | 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', | ||
829 | 50 | 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', | ||
830 | 51 | 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', | ||
831 | 52 | 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', | ||
832 | 53 | 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', | ||
833 | 54 | 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', | ||
834 | 55 | } | ||
835 | 56 | |||
836 | 57 | import sys, os | ||
837 | 58 | try: from hashlib import md5 | ||
838 | 59 | except ImportError: from md5 import md5 | ||
839 | 60 | |||
840 | 61 | def _validate_md5(egg_name, data): | ||
841 | 62 | if egg_name in md5_data: | ||
842 | 63 | digest = md5(data).hexdigest() | ||
843 | 64 | if digest != md5_data[egg_name]: | ||
844 | 65 | print >>sys.stderr, ( | ||
845 | 66 | "md5 validation of %s failed! (Possible download problem?)" | ||
846 | 67 | % egg_name | ||
847 | 68 | ) | ||
848 | 69 | sys.exit(2) | ||
849 | 70 | return data | ||
850 | 71 | |||
851 | 72 | def use_setuptools( | ||
852 | 73 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, | ||
853 | 74 | download_delay=15 | ||
854 | 75 | ): | ||
855 | 76 | """Automatically find/download setuptools and make it available on sys.path | ||
856 | 77 | |||
857 | 78 | `version` should be a valid setuptools version number that is available | ||
858 | 79 | as an egg for download under the `download_base` URL (which should end with | ||
859 | 80 | a '/'). `to_dir` is the directory where setuptools will be downloaded, if | ||
860 | 81 | it is not already available. If `download_delay` is specified, it should | ||
861 | 82 | be the number of seconds that will be paused before initiating a download, | ||
862 | 83 | should one be required. If an older version of setuptools is installed, | ||
863 | 84 | this routine will print a message to ``sys.stderr`` and raise SystemExit in | ||
864 | 85 | an attempt to abort the calling script. | ||
865 | 86 | """ | ||
866 | 87 | was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules | ||
867 | 88 | def do_download(): | ||
868 | 89 | egg = download_setuptools(version, download_base, to_dir, download_delay) | ||
869 | 90 | sys.path.insert(0, egg) | ||
870 | 91 | import setuptools; setuptools.bootstrap_install_from = egg | ||
871 | 92 | try: | ||
872 | 93 | import pkg_resources | ||
873 | 94 | except ImportError: | ||
874 | 95 | return do_download() | ||
875 | 96 | try: | ||
876 | 97 | pkg_resources.require("setuptools>="+version); return | ||
877 | 98 | except pkg_resources.VersionConflict, e: | ||
878 | 99 | if was_imported: | ||
879 | 100 | print >>sys.stderr, ( | ||
880 | 101 | "The required version of setuptools (>=%s) is not available, and\n" | ||
881 | 102 | "can't be installed while this script is running. Please install\n" | ||
882 | 103 | " a more recent version first, using 'easy_install -U setuptools'." | ||
883 | 104 | "\n\n(Currently using %r)" | ||
884 | 105 | ) % (version, e.args[0]) | ||
885 | 106 | sys.exit(2) | ||
886 | 107 | else: | ||
887 | 108 | del pkg_resources, sys.modules['pkg_resources'] # reload ok | ||
888 | 109 | return do_download() | ||
889 | 110 | except pkg_resources.DistributionNotFound: | ||
890 | 111 | return do_download() | ||
891 | 112 | |||
892 | 113 | def download_setuptools( | ||
893 | 114 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, | ||
894 | 115 | delay = 15 | ||
895 | 116 | ): | ||
896 | 117 | """Download setuptools from a specified location and return its filename | ||
897 | 118 | |||
898 | 119 | `version` should be a valid setuptools version number that is available | ||
899 | 120 | as an egg for download under the `download_base` URL (which should end | ||
900 | 121 | with a '/'). `to_dir` is the directory where the egg will be downloaded. | ||
901 | 122 | `delay` is the number of seconds to pause before an actual download attempt. | ||
902 | 123 | """ | ||
903 | 124 | import urllib2, shutil | ||
904 | 125 | egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) | ||
905 | 126 | url = download_base + egg_name | ||
906 | 127 | saveto = os.path.join(to_dir, egg_name) | ||
907 | 128 | src = dst = None | ||
908 | 129 | if not os.path.exists(saveto): # Avoid repeated downloads | ||
909 | 130 | try: | ||
910 | 131 | from distutils import log | ||
911 | 132 | if delay: | ||
912 | 133 | log.warn(""" | ||
913 | 134 | --------------------------------------------------------------------------- | ||
914 | 135 | This script requires setuptools version %s to run (even to display | ||
915 | 136 | help). I will attempt to download it for you (from | ||
916 | 137 | %s), but | ||
917 | 138 | you may need to enable firewall access for this script first. | ||
918 | 139 | I will start the download in %d seconds. | ||
919 | 140 | |||
920 | 141 | (Note: if this machine does not have network access, please obtain the file | ||
921 | 142 | |||
922 | 143 | %s | ||
923 | 144 | |||
924 | 145 | and place it in this directory before rerunning this script.) | ||
925 | 146 | ---------------------------------------------------------------------------""", | ||
926 | 147 | version, download_base, delay, url | ||
927 | 148 | ); from time import sleep; sleep(delay) | ||
928 | 149 | log.warn("Downloading %s", url) | ||
929 | 150 | src = urllib2.urlopen(url) | ||
930 | 151 | # Read/write all in one block, so we don't create a corrupt file | ||
931 | 152 | # if the download is interrupted. | ||
932 | 153 | data = _validate_md5(egg_name, src.read()) | ||
933 | 154 | dst = open(saveto,"wb"); dst.write(data) | ||
934 | 155 | finally: | ||
935 | 156 | if src: src.close() | ||
936 | 157 | if dst: dst.close() | ||
937 | 158 | return os.path.realpath(saveto) | ||
938 | 159 | |||
939 | 160 | |||
940 | 161 | |||
941 | 162 | |||
942 | 163 | |||
943 | 164 | |||
944 | 165 | |||
945 | 166 | |||
946 | 167 | |||
947 | 168 | |||
948 | 169 | |||
949 | 170 | |||
950 | 171 | |||
951 | 172 | |||
952 | 173 | |||
953 | 174 | |||
954 | 175 | |||
955 | 176 | |||
956 | 177 | |||
957 | 178 | |||
958 | 179 | |||
959 | 180 | |||
960 | 181 | |||
961 | 182 | |||
962 | 183 | |||
963 | 184 | |||
964 | 185 | |||
965 | 186 | |||
966 | 187 | |||
967 | 188 | |||
968 | 189 | |||
969 | 190 | |||
970 | 191 | |||
971 | 192 | |||
972 | 193 | |||
973 | 194 | |||
974 | 195 | def main(argv, version=DEFAULT_VERSION): | ||
975 | 196 | """Install or upgrade setuptools and EasyInstall""" | ||
976 | 197 | try: | ||
977 | 198 | import setuptools | ||
978 | 199 | except ImportError: | ||
979 | 200 | egg = None | ||
980 | 201 | try: | ||
981 | 202 | egg = download_setuptools(version, delay=0) | ||
982 | 203 | sys.path.insert(0,egg) | ||
983 | 204 | from setuptools.command.easy_install import main | ||
984 | 205 | return main(list(argv)+[egg]) # we're done here | ||
985 | 206 | finally: | ||
986 | 207 | if egg and os.path.exists(egg): | ||
987 | 208 | os.unlink(egg) | ||
988 | 209 | else: | ||
989 | 210 | if setuptools.__version__ == '0.0.1': | ||
990 | 211 | print >>sys.stderr, ( | ||
991 | 212 | "You have an obsolete version of setuptools installed. Please\n" | ||
992 | 213 | "remove it from your system entirely before rerunning this script." | ||
993 | 214 | ) | ||
994 | 215 | sys.exit(2) | ||
995 | 216 | |||
996 | 217 | req = "setuptools>="+version | ||
997 | 218 | import pkg_resources | ||
998 | 219 | try: | ||
999 | 220 | pkg_resources.require(req) | ||
1000 | 221 | except pkg_resources.VersionConflict: | ||
1001 | 222 | try: | ||
1002 | 223 | from setuptools.command.easy_install import main | ||
1003 | 224 | except ImportError: | ||
1004 | 225 | from easy_install import main | ||
1005 | 226 | main(list(argv)+[download_setuptools(delay=0)]) | ||
1006 | 227 | sys.exit(0) # try to force an exit | ||
1007 | 228 | else: | ||
1008 | 229 | if argv: | ||
1009 | 230 | from setuptools.command.easy_install import main | ||
1010 | 231 | main(argv) | ||
1011 | 232 | else: | ||
1012 | 233 | print "Setuptools version",version,"or greater has been installed." | ||
1013 | 234 | print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' | ||
1014 | 235 | |||
1015 | 236 | def update_md5(filenames): | ||
1016 | 237 | """Update our built-in md5 registry""" | ||
1017 | 238 | |||
1018 | 239 | import re | ||
1019 | 240 | |||
1020 | 241 | for name in filenames: | ||
1021 | 242 | base = os.path.basename(name) | ||
1022 | 243 | f = open(name,'rb') | ||
1023 | 244 | md5_data[base] = md5(f.read()).hexdigest() | ||
1024 | 245 | f.close() | ||
1025 | 246 | |||
1026 | 247 | data = [" %r: %r,\n" % it for it in md5_data.items()] | ||
1027 | 248 | data.sort() | ||
1028 | 249 | repl = "".join(data) | ||
1029 | 250 | |||
1030 | 251 | import inspect | ||
1031 | 252 | srcfile = inspect.getsourcefile(sys.modules[__name__]) | ||
1032 | 253 | f = open(srcfile, 'rb'); src = f.read(); f.close() | ||
1033 | 254 | |||
1034 | 255 | match = re.search("\nmd5_data = {\n([^}]+)}", src) | ||
1035 | 256 | if not match: | ||
1036 | 257 | print >>sys.stderr, "Internal error!" | ||
1037 | 258 | sys.exit(2) | ||
1038 | 259 | |||
1039 | 260 | src = src[:match.start(1)] + repl + src[match.end(1):] | ||
1040 | 261 | f = open(srcfile,'w') | ||
1041 | 262 | f.write(src) | ||
1042 | 263 | f.close() | ||
1043 | 264 | |||
1044 | 265 | |||
1045 | 266 | if __name__=='__main__': | ||
1046 | 267 | if len(sys.argv)>2 and sys.argv[1]=='--md5update': | ||
1047 | 268 | update_md5(sys.argv[2:]) | ||
1048 | 269 | else: | ||
1049 | 270 | main(sys.argv[1:]) | ||
1050 | 271 | |||
1051 | 272 | |||
1052 | 273 | |||
1053 | 274 | |||
1054 | 275 | |||
1055 | 276 | 0 | ||
1056 | === modified file 'setup.py' | |||
1057 | --- setup.py 2009-12-16 13:52:09 +0000 | |||
1058 | +++ setup.py 2010-03-16 15:59:22 +0000 | |||
1059 | @@ -1,7 +1,7 @@ | |||
1060 | 1 | # Copyright 2009 Canonical Ltd. All rights reserved. | 1 | # Copyright 2009 Canonical Ltd. All rights reserved. |
1061 | 2 | 2 | ||
1064 | 3 | import ez_setup | 3 | import distribute_setup |
1065 | 4 | ez_setup.use_setuptools() | 4 | distribute_setup.use_setuptools() |
1066 | 5 | 5 | ||
1067 | 6 | import sys | 6 | import sys |
1068 | 7 | from setuptools import setup, find_packages | 7 | from setuptools import setup, find_packages |
1069 | 8 | 8 | ||
1070 | === modified file 'versions.cfg' | |||
1071 | --- versions.cfg 2009-11-13 20:43:37 +0000 | |||
1072 | +++ versions.cfg 2010-03-16 15:59:22 +0000 | |||
1073 | @@ -8,10 +8,10 @@ | |||
1074 | 8 | cssutils = 0.9.6 | 8 | cssutils = 0.9.6 |
1075 | 9 | lazr.testing = 0.1.1 | 9 | lazr.testing = 0.1.1 |
1076 | 10 | mocker = 0.10.1 | 10 | mocker = 0.10.1 |
1078 | 11 | setuptools = 0.6c9 | 11 | distribute = 0.6.10 |
1079 | 12 | simplejson = 2.0.9 | 12 | simplejson = 2.0.9 |
1080 | 13 | z3c.recipe.tag = 0.2.0 | 13 | z3c.recipe.tag = 0.2.0 |
1082 | 14 | zc.buildout = 1.4.1 | 14 | zc.buildout = 1.4.3 |
1083 | 15 | zc.recipe.egg = 1.2.2 | 15 | zc.recipe.egg = 1.2.2 |
1084 | 16 | zc.recipe.testrunner = 1.2.0 | 16 | zc.recipe.testrunner = 1.2.0 |
1085 | 17 | zope.exceptions = 3.5.2 | 17 | zope.exceptions = 3.5.2 |
I'm not happy reviewing this branch as I don't have the necessary knowledge. I'm asking Gary to either review this or find someone else who has the necessary contextual knowledge to do so.