Merge lp:~bac/lpsetup/sansbuildout into lp:lpsetup
- sansbuildout
- Merge into trunk
Proposed by
Brad Crittenden
Status: | Merged |
---|---|
Approved by: | Brad Crittenden |
Approved revision: | 35 |
Merged at revision: | 36 |
Proposed branch: | lp:~bac/lpsetup/sansbuildout |
Merge into: | lp:lpsetup |
Diff against target: |
828 lines (+501/-296) 3 files modified
distribute_setup.py (+497/-0) ez_setup.py (+0/-288) setup.py (+4/-8) |
To merge this branch: | bzr merge lp:~bac/lpsetup/sansbuildout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gary Poster (community) | Approve | ||
Yellow Squad | code | Pending | |
Review via email: mp+111942@code.launchpad.net |
Commit message
Remove unused buildout. Replace distutils with distribute.
Description of the change
Remove unused buildout. Replace distutils with distribute.
To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote : | # |
Gary thanks for the review. Unfortunately I didn't see your suggestions and toggled the review to 'Approved', which caused tarmac to automatically land it. I've moved it back to 'WIP', will push the changes using your suggestions, will go back to 'Approved' and see if tarmac will re-land.
lp:~bac/lpsetup/sansbuildout
updated
- 34. By Brad Crittenden
-
Replace ez_setup with distribute_setup
- 35. By Brad Crittenden
-
Cleaned up some lint so that we can run pocketlint as a pre-commit hook.
Revision history for this message
Brad Crittenden (bac) wrote : | # |
Changes made, except for the suggestion from Piotr.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'distribute_setup.py' |
2 | --- distribute_setup.py 1970-01-01 00:00:00 +0000 |
3 | +++ distribute_setup.py 2012-06-26 19:31:19 +0000 |
4 | @@ -0,0 +1,497 @@ |
5 | +#!python |
6 | +"""Bootstrap distribute installation |
7 | + |
8 | +If you want to use setuptools in your package's setup.py, just include this |
9 | +file in the same directory with it, and add this to the top of your setup.py:: |
10 | + |
11 | + from distribute_setup import use_setuptools |
12 | + use_setuptools() |
13 | + |
14 | +If you want to require a specific version of setuptools, set a download |
15 | +mirror, or use an alternate download directory, you can do so by supplying |
16 | +the appropriate options to ``use_setuptools()``. |
17 | + |
18 | +This file can also be run as a script to install or upgrade setuptools. |
19 | +""" |
20 | +import os |
21 | +import sys |
22 | +import time |
23 | +import fnmatch |
24 | +import tempfile |
25 | +import tarfile |
26 | +from distutils import log |
27 | + |
28 | +try: |
29 | + from site import USER_SITE |
30 | +except ImportError: |
31 | + USER_SITE = None |
32 | + |
33 | +try: |
34 | + import subprocess |
35 | + |
36 | + def _python_cmd(*args): |
37 | + args = (sys.executable,) + args |
38 | + return subprocess.call(args) == 0 |
39 | + |
40 | +except ImportError: |
41 | + # will be used for python 2.3 |
42 | + def _python_cmd(*args): |
43 | + args = (sys.executable,) + args |
44 | + # quoting arguments if windows |
45 | + if sys.platform == 'win32': |
46 | + def quote(arg): |
47 | + if ' ' in arg: |
48 | + return '"%s"' % arg |
49 | + return arg |
50 | + args = [quote(arg) for arg in args] |
51 | + return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 |
52 | + |
53 | +DEFAULT_VERSION = "0.6.27" |
54 | +DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" |
55 | +SETUPTOOLS_FAKED_VERSION = "0.6c11" |
56 | + |
57 | +SETUPTOOLS_PKG_INFO = """\ |
58 | +Metadata-Version: 1.0 |
59 | +Name: setuptools |
60 | +Version: %s |
61 | +Summary: xxxx |
62 | +Home-page: xxx |
63 | +Author: xxx |
64 | +Author-email: xxx |
65 | +License: xxx |
66 | +Description: xxx |
67 | +""" % SETUPTOOLS_FAKED_VERSION |
68 | + |
69 | + |
70 | +def _install(tarball, install_args=()): |
71 | + # extracting the tarball |
72 | + tmpdir = tempfile.mkdtemp() |
73 | + log.warn('Extracting in %s', tmpdir) |
74 | + old_wd = os.getcwd() |
75 | + try: |
76 | + os.chdir(tmpdir) |
77 | + tar = tarfile.open(tarball) |
78 | + _extractall(tar) |
79 | + tar.close() |
80 | + |
81 | + # going in the directory |
82 | + subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) |
83 | + os.chdir(subdir) |
84 | + log.warn('Now working in %s', subdir) |
85 | + |
86 | + # installing |
87 | + log.warn('Installing Distribute') |
88 | + if not _python_cmd('setup.py', 'install', *install_args): |
89 | + log.warn('Something went wrong during the installation.') |
90 | + log.warn('See the error message above.') |
91 | + finally: |
92 | + os.chdir(old_wd) |
93 | + |
94 | + |
95 | +def _build_egg(egg, tarball, to_dir): |
96 | + # extracting the tarball |
97 | + tmpdir = tempfile.mkdtemp() |
98 | + log.warn('Extracting in %s', tmpdir) |
99 | + old_wd = os.getcwd() |
100 | + try: |
101 | + os.chdir(tmpdir) |
102 | + tar = tarfile.open(tarball) |
103 | + _extractall(tar) |
104 | + tar.close() |
105 | + |
106 | + # going in the directory |
107 | + subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) |
108 | + os.chdir(subdir) |
109 | + log.warn('Now working in %s', subdir) |
110 | + |
111 | + # building an egg |
112 | + log.warn('Building a Distribute egg in %s', to_dir) |
113 | + _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) |
114 | + |
115 | + finally: |
116 | + os.chdir(old_wd) |
117 | + # returning the result |
118 | + log.warn(egg) |
119 | + if not os.path.exists(egg): |
120 | + raise IOError('Could not build the egg.') |
121 | + |
122 | + |
123 | +def _do_download(version, download_base, to_dir, download_delay): |
124 | + egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' |
125 | + % (version, sys.version_info[0], sys.version_info[1])) |
126 | + if not os.path.exists(egg): |
127 | + tarball = download_setuptools(version, download_base, |
128 | + to_dir, download_delay) |
129 | + _build_egg(egg, tarball, to_dir) |
130 | + sys.path.insert(0, egg) |
131 | + import setuptools |
132 | + setuptools.bootstrap_install_from = egg |
133 | + |
134 | + |
135 | +def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
136 | + to_dir=os.curdir, download_delay=15, no_fake=True): |
137 | + # making sure we use the absolute path |
138 | + to_dir = os.path.abspath(to_dir) |
139 | + was_imported = 'pkg_resources' in sys.modules or \ |
140 | + 'setuptools' in sys.modules |
141 | + try: |
142 | + try: |
143 | + import pkg_resources |
144 | + if not hasattr(pkg_resources, '_distribute'): |
145 | + if not no_fake: |
146 | + _fake_setuptools() |
147 | + raise ImportError |
148 | + except ImportError: |
149 | + return _do_download(version, download_base, to_dir, download_delay) |
150 | + try: |
151 | + pkg_resources.require("distribute>="+version) |
152 | + return |
153 | + except pkg_resources.VersionConflict: |
154 | + e = sys.exc_info()[1] |
155 | + if was_imported: |
156 | + sys.stderr.write( |
157 | + "The required version of distribute (>=%s) is not available,\n" |
158 | + "and can't be installed while this script is running. Please\n" |
159 | + "install a more recent version first, using\n" |
160 | + "'easy_install -U distribute'." |
161 | + "\n\n(Currently using %r)\n" % (version, e.args[0])) |
162 | + sys.exit(2) |
163 | + else: |
164 | + del pkg_resources, sys.modules['pkg_resources'] # reload ok |
165 | + return _do_download(version, download_base, to_dir, |
166 | + download_delay) |
167 | + except pkg_resources.DistributionNotFound: |
168 | + return _do_download(version, download_base, to_dir, |
169 | + download_delay) |
170 | + finally: |
171 | + if not no_fake: |
172 | + _create_fake_setuptools_pkg_info(to_dir) |
173 | + |
174 | +def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
175 | + to_dir=os.curdir, delay=15): |
176 | + """Download distribute from a specified location and return its filename |
177 | + |
178 | + `version` should be a valid distribute version number that is available |
179 | + as an egg for download under the `download_base` URL (which should end |
180 | + with a '/'). `to_dir` is the directory where the egg will be downloaded. |
181 | + `delay` is the number of seconds to pause before an actual download |
182 | + attempt. |
183 | + """ |
184 | + # making sure we use the absolute path |
185 | + to_dir = os.path.abspath(to_dir) |
186 | + try: |
187 | + from urllib.request import urlopen |
188 | + except ImportError: |
189 | + from urllib2 import urlopen |
190 | + tgz_name = "distribute-%s.tar.gz" % version |
191 | + url = download_base + tgz_name |
192 | + saveto = os.path.join(to_dir, tgz_name) |
193 | + src = dst = None |
194 | + if not os.path.exists(saveto): # Avoid repeated downloads |
195 | + try: |
196 | + log.warn("Downloading %s", url) |
197 | + src = urlopen(url) |
198 | + # Read/write all in one block, so we don't create a corrupt file |
199 | + # if the download is interrupted. |
200 | + data = src.read() |
201 | + dst = open(saveto, "wb") |
202 | + dst.write(data) |
203 | + finally: |
204 | + if src: |
205 | + src.close() |
206 | + if dst: |
207 | + dst.close() |
208 | + return os.path.realpath(saveto) |
209 | + |
210 | +def _no_sandbox(function): |
211 | + def __no_sandbox(*args, **kw): |
212 | + try: |
213 | + from setuptools.sandbox import DirectorySandbox |
214 | + if not hasattr(DirectorySandbox, '_old'): |
215 | + def violation(*args): |
216 | + pass |
217 | + DirectorySandbox._old = DirectorySandbox._violation |
218 | + DirectorySandbox._violation = violation |
219 | + patched = True |
220 | + else: |
221 | + patched = False |
222 | + except ImportError: |
223 | + patched = False |
224 | + |
225 | + try: |
226 | + return function(*args, **kw) |
227 | + finally: |
228 | + if patched: |
229 | + DirectorySandbox._violation = DirectorySandbox._old |
230 | + del DirectorySandbox._old |
231 | + |
232 | + return __no_sandbox |
233 | + |
234 | +def _patch_file(path, content): |
235 | + """Will backup the file then patch it""" |
236 | + existing_content = open(path).read() |
237 | + if existing_content == content: |
238 | + # already patched |
239 | + log.warn('Already patched.') |
240 | + return False |
241 | + log.warn('Patching...') |
242 | + _rename_path(path) |
243 | + f = open(path, 'w') |
244 | + try: |
245 | + f.write(content) |
246 | + finally: |
247 | + f.close() |
248 | + return True |
249 | + |
250 | +_patch_file = _no_sandbox(_patch_file) |
251 | + |
252 | +def _same_content(path, content): |
253 | + return open(path).read() == content |
254 | + |
255 | +def _rename_path(path): |
256 | + new_name = path + '.OLD.%s' % time.time() |
257 | + log.warn('Renaming %s into %s', path, new_name) |
258 | + os.rename(path, new_name) |
259 | + return new_name |
260 | + |
261 | +def _remove_flat_installation(placeholder): |
262 | + if not os.path.isdir(placeholder): |
263 | + log.warn('Unkown installation at %s', placeholder) |
264 | + return False |
265 | + found = False |
266 | + for file in os.listdir(placeholder): |
267 | + if fnmatch.fnmatch(file, 'setuptools*.egg-info'): |
268 | + found = True |
269 | + break |
270 | + if not found: |
271 | + log.warn('Could not locate setuptools*.egg-info') |
272 | + return |
273 | + |
274 | + log.warn('Removing elements out of the way...') |
275 | + pkg_info = os.path.join(placeholder, file) |
276 | + if os.path.isdir(pkg_info): |
277 | + patched = _patch_egg_dir(pkg_info) |
278 | + else: |
279 | + patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) |
280 | + |
281 | + if not patched: |
282 | + log.warn('%s already patched.', pkg_info) |
283 | + return False |
284 | + # now let's move the files out of the way |
285 | + for element in ('setuptools', 'pkg_resources.py', 'site.py'): |
286 | + element = os.path.join(placeholder, element) |
287 | + if os.path.exists(element): |
288 | + _rename_path(element) |
289 | + else: |
290 | + log.warn('Could not find the %s element of the ' |
291 | + 'Setuptools distribution', element) |
292 | + return True |
293 | + |
294 | +_remove_flat_installation = _no_sandbox(_remove_flat_installation) |
295 | + |
296 | +def _after_install(dist): |
297 | + log.warn('After install bootstrap.') |
298 | + placeholder = dist.get_command_obj('install').install_purelib |
299 | + _create_fake_setuptools_pkg_info(placeholder) |
300 | + |
301 | +def _create_fake_setuptools_pkg_info(placeholder): |
302 | + if not placeholder or not os.path.exists(placeholder): |
303 | + log.warn('Could not find the install location') |
304 | + return |
305 | + pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) |
306 | + setuptools_file = 'setuptools-%s-py%s.egg-info' % \ |
307 | + (SETUPTOOLS_FAKED_VERSION, pyver) |
308 | + pkg_info = os.path.join(placeholder, setuptools_file) |
309 | + if os.path.exists(pkg_info): |
310 | + log.warn('%s already exists', pkg_info) |
311 | + return |
312 | + |
313 | + if not os.access(pkg_info, os.W_OK): |
314 | + log.warn("Don't have permissions to write %s, skipping", pkg_info) |
315 | + |
316 | + log.warn('Creating %s', pkg_info) |
317 | + f = open(pkg_info, 'w') |
318 | + try: |
319 | + f.write(SETUPTOOLS_PKG_INFO) |
320 | + finally: |
321 | + f.close() |
322 | + |
323 | + pth_file = os.path.join(placeholder, 'setuptools.pth') |
324 | + log.warn('Creating %s', pth_file) |
325 | + f = open(pth_file, 'w') |
326 | + try: |
327 | + f.write(os.path.join(os.curdir, setuptools_file)) |
328 | + finally: |
329 | + f.close() |
330 | + |
331 | +_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) |
332 | + |
333 | +def _patch_egg_dir(path): |
334 | + # let's check if it's already patched |
335 | + pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') |
336 | + if os.path.exists(pkg_info): |
337 | + if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): |
338 | + log.warn('%s already patched.', pkg_info) |
339 | + return False |
340 | + _rename_path(path) |
341 | + os.mkdir(path) |
342 | + os.mkdir(os.path.join(path, 'EGG-INFO')) |
343 | + pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') |
344 | + f = open(pkg_info, 'w') |
345 | + try: |
346 | + f.write(SETUPTOOLS_PKG_INFO) |
347 | + finally: |
348 | + f.close() |
349 | + return True |
350 | + |
351 | +_patch_egg_dir = _no_sandbox(_patch_egg_dir) |
352 | + |
353 | +def _before_install(): |
354 | + log.warn('Before install bootstrap.') |
355 | + _fake_setuptools() |
356 | + |
357 | + |
358 | +def _under_prefix(location): |
359 | + if 'install' not in sys.argv: |
360 | + return True |
361 | + args = sys.argv[sys.argv.index('install')+1:] |
362 | + for index, arg in enumerate(args): |
363 | + for option in ('--root', '--prefix'): |
364 | + if arg.startswith('%s=' % option): |
365 | + top_dir = arg.split('root=')[-1] |
366 | + return location.startswith(top_dir) |
367 | + elif arg == option: |
368 | + if len(args) > index: |
369 | + top_dir = args[index+1] |
370 | + return location.startswith(top_dir) |
371 | + if arg == '--user' and USER_SITE is not None: |
372 | + return location.startswith(USER_SITE) |
373 | + return True |
374 | + |
375 | + |
376 | +def _fake_setuptools(): |
377 | + log.warn('Scanning installed packages') |
378 | + try: |
379 | + import pkg_resources |
380 | + except ImportError: |
381 | + # we're cool |
382 | + log.warn('Setuptools or Distribute does not seem to be installed.') |
383 | + return |
384 | + ws = pkg_resources.working_set |
385 | + try: |
386 | + setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', |
387 | + replacement=False)) |
388 | + except TypeError: |
389 | + # old distribute API |
390 | + setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) |
391 | + |
392 | + if setuptools_dist is None: |
393 | + log.warn('No setuptools distribution found') |
394 | + return |
395 | + # detecting if it was already faked |
396 | + setuptools_location = setuptools_dist.location |
397 | + log.warn('Setuptools installation detected at %s', setuptools_location) |
398 | + |
399 | + # if --root or --preix was provided, and if |
400 | + # setuptools is not located in them, we don't patch it |
401 | + if not _under_prefix(setuptools_location): |
402 | + log.warn('Not patching, --root or --prefix is installing Distribute' |
403 | + ' in another location') |
404 | + return |
405 | + |
406 | + # let's see if its an egg |
407 | + if not setuptools_location.endswith('.egg'): |
408 | + log.warn('Non-egg installation') |
409 | + res = _remove_flat_installation(setuptools_location) |
410 | + if not res: |
411 | + return |
412 | + else: |
413 | + log.warn('Egg installation') |
414 | + pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') |
415 | + if (os.path.exists(pkg_info) and |
416 | + _same_content(pkg_info, SETUPTOOLS_PKG_INFO)): |
417 | + log.warn('Already patched.') |
418 | + return |
419 | + log.warn('Patching...') |
420 | + # let's create a fake egg replacing setuptools one |
421 | + res = _patch_egg_dir(setuptools_location) |
422 | + if not res: |
423 | + return |
424 | + log.warn('Patched done.') |
425 | + _relaunch() |
426 | + |
427 | + |
428 | +def _relaunch(): |
429 | + log.warn('Relaunching...') |
430 | + # we have to relaunch the process |
431 | + # pip marker to avoid a relaunch bug |
432 | + if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']: |
433 | + sys.argv[0] = 'setup.py' |
434 | + args = [sys.executable] + sys.argv |
435 | + sys.exit(subprocess.call(args)) |
436 | + |
437 | + |
438 | +def _extractall(self, path=".", members=None): |
439 | + """Extract all members from the archive to the current working |
440 | + directory and set owner, modification time and permissions on |
441 | + directories afterwards. `path' specifies a different directory |
442 | + to extract to. `members' is optional and must be a subset of the |
443 | + list returned by getmembers(). |
444 | + """ |
445 | + import copy |
446 | + import operator |
447 | + from tarfile import ExtractError |
448 | + directories = [] |
449 | + |
450 | + if members is None: |
451 | + members = self |
452 | + |
453 | + for tarinfo in members: |
454 | + if tarinfo.isdir(): |
455 | + # Extract directories with a safe mode. |
456 | + directories.append(tarinfo) |
457 | + tarinfo = copy.copy(tarinfo) |
458 | + tarinfo.mode = 448 # decimal for oct 0700 |
459 | + self.extract(tarinfo, path) |
460 | + |
461 | + # Reverse sort directories. |
462 | + if sys.version_info < (2, 4): |
463 | + def sorter(dir1, dir2): |
464 | + return cmp(dir1.name, dir2.name) |
465 | + directories.sort(sorter) |
466 | + directories.reverse() |
467 | + else: |
468 | + directories.sort(key=operator.attrgetter('name'), reverse=True) |
469 | + |
470 | + # Set correct owner, mtime and filemode on directories. |
471 | + for tarinfo in directories: |
472 | + dirpath = os.path.join(path, tarinfo.name) |
473 | + try: |
474 | + self.chown(tarinfo, dirpath) |
475 | + self.utime(tarinfo, dirpath) |
476 | + self.chmod(tarinfo, dirpath) |
477 | + except ExtractError: |
478 | + e = sys.exc_info()[1] |
479 | + if self.errorlevel > 1: |
480 | + raise |
481 | + else: |
482 | + self._dbg(1, "tarfile: %s" % e) |
483 | + |
484 | +def _build_install_args(argv): |
485 | + install_args = [] |
486 | + user_install = '--user' in argv |
487 | + if user_install and sys.version_info < (2,6): |
488 | + log.warn("--user requires Python 2.6 or later") |
489 | + raise SystemExit(1) |
490 | + if user_install: |
491 | + install_args.append('--user') |
492 | + return install_args |
493 | + |
494 | +def main(argv, version=DEFAULT_VERSION): |
495 | + """Install or upgrade setuptools and EasyInstall""" |
496 | + tarball = download_setuptools() |
497 | + _install(tarball, _build_install_args(argv)) |
498 | + |
499 | + |
500 | +if __name__ == '__main__': |
501 | + main(sys.argv[1:]) |
502 | |
503 | === removed file 'ez_setup.py' |
504 | --- ez_setup.py 2012-06-25 21:17:38 +0000 |
505 | +++ ez_setup.py 1970-01-01 00:00:00 +0000 |
506 | @@ -1,288 +0,0 @@ |
507 | -#!python |
508 | - |
509 | -# NOTE TO LAUNCHPAD DEVELOPERS: This is a bootstrapping file from the |
510 | -# setuptools project. It is imported by our setup.py. |
511 | - |
512 | -"""Bootstrap setuptools installation |
513 | - |
514 | -If you want to use setuptools in your package's setup.py, just include this |
515 | -file in the same directory with it, and add this to the top of your setup.py:: |
516 | - |
517 | - from ez_setup import use_setuptools |
518 | - use_setuptools() |
519 | - |
520 | -If you want to require a specific version of setuptools, set a download |
521 | -mirror, or use an alternate download directory, you can do so by supplying |
522 | -the appropriate options to ``use_setuptools()``. |
523 | - |
524 | -This file can also be run as a script to install or upgrade setuptools. |
525 | -""" |
526 | -import sys |
527 | -DEFAULT_VERSION = "0.6c11" |
528 | -DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] |
529 | - |
530 | -md5_data = { |
531 | - 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', |
532 | - 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', |
533 | - 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', |
534 | - 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', |
535 | - 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', |
536 | - 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', |
537 | - 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', |
538 | - 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', |
539 | - 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', |
540 | - 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', |
541 | - 'setuptools-0.6c10-py2.3.egg': 'ce1e2ab5d3a0256456d9fc13800a7090', |
542 | - 'setuptools-0.6c10-py2.4.egg': '57d6d9d6e9b80772c59a53a8433a5dd4', |
543 | - 'setuptools-0.6c10-py2.5.egg': 'de46ac8b1c97c895572e5e8596aeb8c7', |
544 | - 'setuptools-0.6c10-py2.6.egg': '58ea40aef06da02ce641495523a0b7f5', |
545 | - 'setuptools-0.6c11-py2.3.egg': '2baeac6e13d414a9d28e7ba5b5a596de', |
546 | - 'setuptools-0.6c11-py2.4.egg': 'bd639f9b0eac4c42497034dec2ec0c2b', |
547 | - 'setuptools-0.6c11-py2.5.egg': '64c94f3bf7a72a13ec83e0b24f2749b2', |
548 | - 'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086', |
549 | - 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', |
550 | - 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', |
551 | - 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', |
552 | - 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', |
553 | - 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', |
554 | - 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', |
555 | - 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', |
556 | - 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', |
557 | - 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', |
558 | - 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', |
559 | - 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', |
560 | - 'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20', |
561 | - 'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab', |
562 | - 'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53', |
563 | - 'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2', |
564 | - 'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e', |
565 | - 'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372', |
566 | - 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', |
567 | - 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', |
568 | - 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', |
569 | - 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', |
570 | - 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', |
571 | - 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', |
572 | - 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', |
573 | -} |
574 | - |
575 | -import sys, os |
576 | -try: from hashlib import md5 |
577 | -except ImportError: from md5 import md5 |
578 | - |
579 | -def _validate_md5(egg_name, data): |
580 | - if egg_name in md5_data: |
581 | - digest = md5(data).hexdigest() |
582 | - if digest != md5_data[egg_name]: |
583 | - print >>sys.stderr, ( |
584 | - "md5 validation of %s failed! (Possible download problem?)" |
585 | - % egg_name |
586 | - ) |
587 | - sys.exit(2) |
588 | - return data |
589 | - |
590 | -def use_setuptools( |
591 | - version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, |
592 | - download_delay=15 |
593 | -): |
594 | - """Automatically find/download setuptools and make it available on sys.path |
595 | - |
596 | - `version` should be a valid setuptools version number that is available |
597 | - as an egg for download under the `download_base` URL (which should end with |
598 | - a '/'). `to_dir` is the directory where setuptools will be downloaded, if |
599 | - it is not already available. If `download_delay` is specified, it should |
600 | - be the number of seconds that will be paused before initiating a download, |
601 | - should one be required. If an older version of setuptools is installed, |
602 | - this routine will print a message to ``sys.stderr`` and raise SystemExit in |
603 | - an attempt to abort the calling script. |
604 | - """ |
605 | - was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules |
606 | - def do_download(): |
607 | - egg = download_setuptools(version, download_base, to_dir, download_delay) |
608 | - sys.path.insert(0, egg) |
609 | - import setuptools; setuptools.bootstrap_install_from = egg |
610 | - try: |
611 | - import pkg_resources |
612 | - except ImportError: |
613 | - return do_download() |
614 | - try: |
615 | - pkg_resources.require("setuptools>="+version); return |
616 | - except pkg_resources.VersionConflict, e: |
617 | - if was_imported: |
618 | - print >>sys.stderr, ( |
619 | - "The required version of setuptools (>=%s) is not available, and\n" |
620 | - "can't be installed while this script is running. Please install\n" |
621 | - " a more recent version first, using 'easy_install -U setuptools'." |
622 | - "\n\n(Currently using %r)" |
623 | - ) % (version, e.args[0]) |
624 | - sys.exit(2) |
625 | - else: |
626 | - del pkg_resources, sys.modules['pkg_resources'] # reload ok |
627 | - return do_download() |
628 | - except pkg_resources.DistributionNotFound: |
629 | - return do_download() |
630 | - |
631 | -def download_setuptools( |
632 | - version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, |
633 | - delay = 15 |
634 | -): |
635 | - """Download setuptools from a specified location and return its filename |
636 | - |
637 | - `version` should be a valid setuptools version number that is available |
638 | - as an egg for download under the `download_base` URL (which should end |
639 | - with a '/'). `to_dir` is the directory where the egg will be downloaded. |
640 | - `delay` is the number of seconds to pause before an actual download attempt. |
641 | - """ |
642 | - import urllib2, shutil |
643 | - egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) |
644 | - url = download_base + egg_name |
645 | - saveto = os.path.join(to_dir, egg_name) |
646 | - src = dst = None |
647 | - if not os.path.exists(saveto): # Avoid repeated downloads |
648 | - try: |
649 | - from distutils import log |
650 | - if delay: |
651 | - log.warn(""" |
652 | ---------------------------------------------------------------------------- |
653 | -This script requires setuptools version %s to run (even to display |
654 | -help). I will attempt to download it for you (from |
655 | -%s), but |
656 | -you may need to enable firewall access for this script first. |
657 | -I will start the download in %d seconds. |
658 | - |
659 | -(Note: if this machine does not have network access, please obtain the file |
660 | - |
661 | - %s |
662 | - |
663 | -and place it in this directory before rerunning this script.) |
664 | ----------------------------------------------------------------------------""", |
665 | - version, download_base, delay, url |
666 | - ); from time import sleep; sleep(delay) |
667 | - log.warn("Downloading %s", url) |
668 | - src = urllib2.urlopen(url) |
669 | - # Read/write all in one block, so we don't create a corrupt file |
670 | - # if the download is interrupted. |
671 | - data = _validate_md5(egg_name, src.read()) |
672 | - dst = open(saveto,"wb"); dst.write(data) |
673 | - finally: |
674 | - if src: src.close() |
675 | - if dst: dst.close() |
676 | - return os.path.realpath(saveto) |
677 | - |
678 | - |
679 | - |
680 | - |
681 | - |
682 | - |
683 | - |
684 | - |
685 | - |
686 | - |
687 | - |
688 | - |
689 | - |
690 | - |
691 | - |
692 | - |
693 | - |
694 | - |
695 | - |
696 | - |
697 | - |
698 | - |
699 | - |
700 | - |
701 | - |
702 | - |
703 | - |
704 | - |
705 | - |
706 | - |
707 | - |
708 | - |
709 | - |
710 | - |
711 | - |
712 | - |
713 | -def main(argv, version=DEFAULT_VERSION): |
714 | - """Install or upgrade setuptools and EasyInstall""" |
715 | - try: |
716 | - import setuptools |
717 | - except ImportError: |
718 | - egg = None |
719 | - try: |
720 | - egg = download_setuptools(version, delay=0) |
721 | - sys.path.insert(0,egg) |
722 | - from setuptools.command.easy_install import main |
723 | - return main(list(argv)+[egg]) # we're done here |
724 | - finally: |
725 | - if egg and os.path.exists(egg): |
726 | - os.unlink(egg) |
727 | - else: |
728 | - if setuptools.__version__ == '0.0.1': |
729 | - print >>sys.stderr, ( |
730 | - "You have an obsolete version of setuptools installed. Please\n" |
731 | - "remove it from your system entirely before rerunning this script." |
732 | - ) |
733 | - sys.exit(2) |
734 | - |
735 | - req = "setuptools>="+version |
736 | - import pkg_resources |
737 | - try: |
738 | - pkg_resources.require(req) |
739 | - except pkg_resources.VersionConflict: |
740 | - try: |
741 | - from setuptools.command.easy_install import main |
742 | - except ImportError: |
743 | - from easy_install import main |
744 | - main(list(argv)+[download_setuptools(delay=0)]) |
745 | - sys.exit(0) # try to force an exit |
746 | - else: |
747 | - if argv: |
748 | - from setuptools.command.easy_install import main |
749 | - main(argv) |
750 | - else: |
751 | - print "Setuptools version",version,"or greater has been installed." |
752 | - print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' |
753 | - |
754 | -def update_md5(filenames): |
755 | - """Update our built-in md5 registry""" |
756 | - |
757 | - import re |
758 | - |
759 | - for name in filenames: |
760 | - base = os.path.basename(name) |
761 | - f = open(name,'rb') |
762 | - md5_data[base] = md5(f.read()).hexdigest() |
763 | - f.close() |
764 | - |
765 | - data = [" %r: %r,\n" % it for it in md5_data.items()] |
766 | - data.sort() |
767 | - repl = "".join(data) |
768 | - |
769 | - import inspect |
770 | - srcfile = inspect.getsourcefile(sys.modules[__name__]) |
771 | - f = open(srcfile, 'rb'); src = f.read(); f.close() |
772 | - |
773 | - match = re.search("\nmd5_data = {\n([^}]+)}", src) |
774 | - if not match: |
775 | - print >>sys.stderr, "Internal error!" |
776 | - sys.exit(2) |
777 | - |
778 | - src = src[:match.start(1)] + repl + src[match.end(1):] |
779 | - f = open(srcfile,'w') |
780 | - f.write(src) |
781 | - f.close() |
782 | - |
783 | - |
784 | -if __name__=='__main__': |
785 | - if len(sys.argv)>2 and sys.argv[1]=='--md5update': |
786 | - update_md5(sys.argv[2:]) |
787 | - else: |
788 | - main(sys.argv[1:]) |
789 | - |
790 | - |
791 | - |
792 | - |
793 | - |
794 | - |
795 | |
796 | === modified file 'setup.py' |
797 | --- setup.py 2012-06-26 18:26:09 +0000 |
798 | +++ setup.py 2012-06-26 19:31:19 +0000 |
799 | @@ -2,17 +2,13 @@ |
800 | # Copyright 2012 Canonical Ltd. This software is licensed under the |
801 | # GNU Affero General Public License version 3 (see the file LICENSE). |
802 | |
803 | -import ez_setup |
804 | - |
805 | - |
806 | -ez_setup.use_setuptools() |
807 | - |
808 | -from setuptools import setup |
809 | +import distribute_setup |
810 | +distribute_setup.use_setuptools() |
811 | +import setuptools |
812 | |
813 | import os |
814 | import shutil |
815 | |
816 | - |
817 | project_name = 'lpsetup' |
818 | |
819 | root_dir = os.path.dirname(__file__) |
820 | @@ -36,7 +32,7 @@ |
821 | # Create the `lp-lxc-ip` script. |
822 | shutil.copyfile('lplxcip/lxcip.py', 'lp-lxc-ip') |
823 | |
824 | -setup( |
825 | +setuptools.setup( |
826 | name=project_name, |
827 | version=project.get_version(), |
828 | description=project.__doc__, |
Great! Thank you.
Rather than copying over ez_setup.py from Launchpad, I suggest using the distribute version. http:// packages. python. org/distribute/ using.html describes details very roughly. http:// python- distribute. org/distribute_ setup.py
Moreover, see this discussion, and contain your weeping. And talk to barry if you want to. http:// old.nabble. com/to- distribute_ setup() -or-not, -that-is- the-question- td33210691. html I kind of like Piotr's approach in that thread:
import sys distribute' in sys.argv:
distribute_ setup.use_ setuptools( ) distribute argument'"
try:
import setuptools
except ImportError:
if '--download-
import distribute_setup
else:
print >>sys.stderr, 'Please install distribute or add --download-
exit(1)
He didn't get a reply though.
Did I mention the idea about running away?