Merge lp:~allenap/python-oops-datedir-repo/dont-depend-on-launchpadlib into lp:python-oops-datedir-repo
- dont-depend-on-launchpadlib
- Merge into trunk
Proposed by
Gavin Panella
Status: | Work in progress |
---|---|
Proposed branch: | lp:~allenap/python-oops-datedir-repo/dont-depend-on-launchpadlib |
Merge into: | lp:python-oops-datedir-repo |
Diff against target: |
560 lines (+507/-15) 3 files modified
.bzrignore (+9/-7) distribute_setup.py (+485/-0) setup.py (+13/-8) |
To merge this branch: | bzr merge lp:~allenap/python-oops-datedir-repo/dont-depend-on-launchpadlib |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Needs Fixing | ||
Review via email: mp+90405@code.launchpad.net |
Commit message
Make prune an optional feature.
Description of the change
To post a comment you must log in.
Unmerged revisions
- 32. By Gavin Panella
-
Make prune optional.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2011-11-11 04:48:53 +0000 | |||
3 | +++ .bzrignore 2012-01-27 11:25:27 +0000 | |||
4 | @@ -1,11 +1,13 @@ | |||
5 | 1 | ./eggs/* | ||
6 | 2 | ./.installed.cfg | 1 | ./.installed.cfg |
7 | 2 | ./.testrepository | ||
8 | 3 | ./bin | ||
9 | 3 | ./develop-eggs | 4 | ./develop-eggs |
11 | 4 | ./bin | 5 | ./dist |
12 | 6 | ./distribute*.egg | ||
13 | 7 | ./distribute*.tar.gz | ||
14 | 8 | ./download-cache | ||
15 | 9 | ./eggs | ||
16 | 10 | ./eggs/* | ||
17 | 11 | ./MANIFEST | ||
18 | 5 | ./oops_datedir_repo.egg-info | 12 | ./oops_datedir_repo.egg-info |
19 | 6 | ./parts | 13 | ./parts |
20 | 7 | ./eggs | ||
21 | 8 | ./download-cache | ||
22 | 9 | ./dist | ||
23 | 10 | ./MANIFEST | ||
24 | 11 | .testrepository | ||
25 | 12 | 14 | ||
26 | === added file 'distribute_setup.py' | |||
27 | --- distribute_setup.py 1970-01-01 00:00:00 +0000 | |||
28 | +++ distribute_setup.py 2012-01-27 11:25:27 +0000 | |||
29 | @@ -0,0 +1,485 @@ | |||
30 | 1 | #!python | ||
31 | 2 | """Bootstrap distribute installation | ||
32 | 3 | |||
33 | 4 | If you want to use setuptools in your package's setup.py, just include this | ||
34 | 5 | file in the same directory with it, and add this to the top of your setup.py:: | ||
35 | 6 | |||
36 | 7 | from distribute_setup import use_setuptools | ||
37 | 8 | use_setuptools() | ||
38 | 9 | |||
39 | 10 | If you want to require a specific version of setuptools, set a download | ||
40 | 11 | mirror, or use an alternate download directory, you can do so by supplying | ||
41 | 12 | the appropriate options to ``use_setuptools()``. | ||
42 | 13 | |||
43 | 14 | This file can also be run as a script to install or upgrade setuptools. | ||
44 | 15 | """ | ||
45 | 16 | import os | ||
46 | 17 | import sys | ||
47 | 18 | import time | ||
48 | 19 | import fnmatch | ||
49 | 20 | import tempfile | ||
50 | 21 | import tarfile | ||
51 | 22 | from distutils import log | ||
52 | 23 | |||
53 | 24 | try: | ||
54 | 25 | from site import USER_SITE | ||
55 | 26 | except ImportError: | ||
56 | 27 | USER_SITE = None | ||
57 | 28 | |||
58 | 29 | try: | ||
59 | 30 | import subprocess | ||
60 | 31 | |||
61 | 32 | def _python_cmd(*args): | ||
62 | 33 | args = (sys.executable,) + args | ||
63 | 34 | return subprocess.call(args) == 0 | ||
64 | 35 | |||
65 | 36 | except ImportError: | ||
66 | 37 | # will be used for python 2.3 | ||
67 | 38 | def _python_cmd(*args): | ||
68 | 39 | args = (sys.executable,) + args | ||
69 | 40 | # quoting arguments if windows | ||
70 | 41 | if sys.platform == 'win32': | ||
71 | 42 | def quote(arg): | ||
72 | 43 | if ' ' in arg: | ||
73 | 44 | return '"%s"' % arg | ||
74 | 45 | return arg | ||
75 | 46 | args = [quote(arg) for arg in args] | ||
76 | 47 | return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 | ||
77 | 48 | |||
78 | 49 | DEFAULT_VERSION = "0.6.24" | ||
79 | 50 | DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" | ||
80 | 51 | SETUPTOOLS_FAKED_VERSION = "0.6c11" | ||
81 | 52 | |||
82 | 53 | SETUPTOOLS_PKG_INFO = """\ | ||
83 | 54 | Metadata-Version: 1.0 | ||
84 | 55 | Name: setuptools | ||
85 | 56 | Version: %s | ||
86 | 57 | Summary: xxxx | ||
87 | 58 | Home-page: xxx | ||
88 | 59 | Author: xxx | ||
89 | 60 | Author-email: xxx | ||
90 | 61 | License: xxx | ||
91 | 62 | Description: xxx | ||
92 | 63 | """ % SETUPTOOLS_FAKED_VERSION | ||
93 | 64 | |||
94 | 65 | |||
95 | 66 | def _install(tarball): | ||
96 | 67 | # extracting the tarball | ||
97 | 68 | tmpdir = tempfile.mkdtemp() | ||
98 | 69 | log.warn('Extracting in %s', tmpdir) | ||
99 | 70 | old_wd = os.getcwd() | ||
100 | 71 | try: | ||
101 | 72 | os.chdir(tmpdir) | ||
102 | 73 | tar = tarfile.open(tarball) | ||
103 | 74 | _extractall(tar) | ||
104 | 75 | tar.close() | ||
105 | 76 | |||
106 | 77 | # going in the directory | ||
107 | 78 | subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) | ||
108 | 79 | os.chdir(subdir) | ||
109 | 80 | log.warn('Now working in %s', subdir) | ||
110 | 81 | |||
111 | 82 | # installing | ||
112 | 83 | log.warn('Installing Distribute') | ||
113 | 84 | if not _python_cmd('setup.py', 'install'): | ||
114 | 85 | log.warn('Something went wrong during the installation.') | ||
115 | 86 | log.warn('See the error message above.') | ||
116 | 87 | finally: | ||
117 | 88 | os.chdir(old_wd) | ||
118 | 89 | |||
119 | 90 | |||
120 | 91 | def _build_egg(egg, tarball, to_dir): | ||
121 | 92 | # extracting the tarball | ||
122 | 93 | tmpdir = tempfile.mkdtemp() | ||
123 | 94 | log.warn('Extracting in %s', tmpdir) | ||
124 | 95 | old_wd = os.getcwd() | ||
125 | 96 | try: | ||
126 | 97 | os.chdir(tmpdir) | ||
127 | 98 | tar = tarfile.open(tarball) | ||
128 | 99 | _extractall(tar) | ||
129 | 100 | tar.close() | ||
130 | 101 | |||
131 | 102 | # going in the directory | ||
132 | 103 | subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) | ||
133 | 104 | os.chdir(subdir) | ||
134 | 105 | log.warn('Now working in %s', subdir) | ||
135 | 106 | |||
136 | 107 | # building an egg | ||
137 | 108 | log.warn('Building a Distribute egg in %s', to_dir) | ||
138 | 109 | _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) | ||
139 | 110 | |||
140 | 111 | finally: | ||
141 | 112 | os.chdir(old_wd) | ||
142 | 113 | # returning the result | ||
143 | 114 | log.warn(egg) | ||
144 | 115 | if not os.path.exists(egg): | ||
145 | 116 | raise IOError('Could not build the egg.') | ||
146 | 117 | |||
147 | 118 | |||
148 | 119 | def _do_download(version, download_base, to_dir, download_delay): | ||
149 | 120 | egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' | ||
150 | 121 | % (version, sys.version_info[0], sys.version_info[1])) | ||
151 | 122 | if not os.path.exists(egg): | ||
152 | 123 | tarball = download_setuptools(version, download_base, | ||
153 | 124 | to_dir, download_delay) | ||
154 | 125 | _build_egg(egg, tarball, to_dir) | ||
155 | 126 | sys.path.insert(0, egg) | ||
156 | 127 | import setuptools | ||
157 | 128 | setuptools.bootstrap_install_from = egg | ||
158 | 129 | |||
159 | 130 | |||
160 | 131 | def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | ||
161 | 132 | to_dir=os.curdir, download_delay=15, no_fake=True): | ||
162 | 133 | # making sure we use the absolute path | ||
163 | 134 | to_dir = os.path.abspath(to_dir) | ||
164 | 135 | was_imported = 'pkg_resources' in sys.modules or \ | ||
165 | 136 | 'setuptools' in sys.modules | ||
166 | 137 | try: | ||
167 | 138 | try: | ||
168 | 139 | import pkg_resources | ||
169 | 140 | if not hasattr(pkg_resources, '_distribute'): | ||
170 | 141 | if not no_fake: | ||
171 | 142 | _fake_setuptools() | ||
172 | 143 | raise ImportError | ||
173 | 144 | except ImportError: | ||
174 | 145 | return _do_download(version, download_base, to_dir, download_delay) | ||
175 | 146 | try: | ||
176 | 147 | pkg_resources.require("distribute>="+version) | ||
177 | 148 | return | ||
178 | 149 | except pkg_resources.VersionConflict: | ||
179 | 150 | e = sys.exc_info()[1] | ||
180 | 151 | if was_imported: | ||
181 | 152 | sys.stderr.write( | ||
182 | 153 | "The required version of distribute (>=%s) is not available,\n" | ||
183 | 154 | "and can't be installed while this script is running. Please\n" | ||
184 | 155 | "install a more recent version first, using\n" | ||
185 | 156 | "'easy_install -U distribute'." | ||
186 | 157 | "\n\n(Currently using %r)\n" % (version, e.args[0])) | ||
187 | 158 | sys.exit(2) | ||
188 | 159 | else: | ||
189 | 160 | del pkg_resources, sys.modules['pkg_resources'] # reload ok | ||
190 | 161 | return _do_download(version, download_base, to_dir, | ||
191 | 162 | download_delay) | ||
192 | 163 | except pkg_resources.DistributionNotFound: | ||
193 | 164 | return _do_download(version, download_base, to_dir, | ||
194 | 165 | download_delay) | ||
195 | 166 | finally: | ||
196 | 167 | if not no_fake: | ||
197 | 168 | _create_fake_setuptools_pkg_info(to_dir) | ||
198 | 169 | |||
199 | 170 | def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, | ||
200 | 171 | to_dir=os.curdir, delay=15): | ||
201 | 172 | """Download distribute from a specified location and return its filename | ||
202 | 173 | |||
203 | 174 | `version` should be a valid distribute version number that is available | ||
204 | 175 | as an egg for download under the `download_base` URL (which should end | ||
205 | 176 | with a '/'). `to_dir` is the directory where the egg will be downloaded. | ||
206 | 177 | `delay` is the number of seconds to pause before an actual download | ||
207 | 178 | attempt. | ||
208 | 179 | """ | ||
209 | 180 | # making sure we use the absolute path | ||
210 | 181 | to_dir = os.path.abspath(to_dir) | ||
211 | 182 | try: | ||
212 | 183 | from urllib.request import urlopen | ||
213 | 184 | except ImportError: | ||
214 | 185 | from urllib2 import urlopen | ||
215 | 186 | tgz_name = "distribute-%s.tar.gz" % version | ||
216 | 187 | url = download_base + tgz_name | ||
217 | 188 | saveto = os.path.join(to_dir, tgz_name) | ||
218 | 189 | src = dst = None | ||
219 | 190 | if not os.path.exists(saveto): # Avoid repeated downloads | ||
220 | 191 | try: | ||
221 | 192 | log.warn("Downloading %s", url) | ||
222 | 193 | src = urlopen(url) | ||
223 | 194 | # Read/write all in one block, so we don't create a corrupt file | ||
224 | 195 | # if the download is interrupted. | ||
225 | 196 | data = src.read() | ||
226 | 197 | dst = open(saveto, "wb") | ||
227 | 198 | dst.write(data) | ||
228 | 199 | finally: | ||
229 | 200 | if src: | ||
230 | 201 | src.close() | ||
231 | 202 | if dst: | ||
232 | 203 | dst.close() | ||
233 | 204 | return os.path.realpath(saveto) | ||
234 | 205 | |||
235 | 206 | def _no_sandbox(function): | ||
236 | 207 | def __no_sandbox(*args, **kw): | ||
237 | 208 | try: | ||
238 | 209 | from setuptools.sandbox import DirectorySandbox | ||
239 | 210 | if not hasattr(DirectorySandbox, '_old'): | ||
240 | 211 | def violation(*args): | ||
241 | 212 | pass | ||
242 | 213 | DirectorySandbox._old = DirectorySandbox._violation | ||
243 | 214 | DirectorySandbox._violation = violation | ||
244 | 215 | patched = True | ||
245 | 216 | else: | ||
246 | 217 | patched = False | ||
247 | 218 | except ImportError: | ||
248 | 219 | patched = False | ||
249 | 220 | |||
250 | 221 | try: | ||
251 | 222 | return function(*args, **kw) | ||
252 | 223 | finally: | ||
253 | 224 | if patched: | ||
254 | 225 | DirectorySandbox._violation = DirectorySandbox._old | ||
255 | 226 | del DirectorySandbox._old | ||
256 | 227 | |||
257 | 228 | return __no_sandbox | ||
258 | 229 | |||
259 | 230 | def _patch_file(path, content): | ||
260 | 231 | """Will backup the file then patch it""" | ||
261 | 232 | existing_content = open(path).read() | ||
262 | 233 | if existing_content == content: | ||
263 | 234 | # already patched | ||
264 | 235 | log.warn('Already patched.') | ||
265 | 236 | return False | ||
266 | 237 | log.warn('Patching...') | ||
267 | 238 | _rename_path(path) | ||
268 | 239 | f = open(path, 'w') | ||
269 | 240 | try: | ||
270 | 241 | f.write(content) | ||
271 | 242 | finally: | ||
272 | 243 | f.close() | ||
273 | 244 | return True | ||
274 | 245 | |||
275 | 246 | _patch_file = _no_sandbox(_patch_file) | ||
276 | 247 | |||
277 | 248 | def _same_content(path, content): | ||
278 | 249 | return open(path).read() == content | ||
279 | 250 | |||
280 | 251 | def _rename_path(path): | ||
281 | 252 | new_name = path + '.OLD.%s' % time.time() | ||
282 | 253 | log.warn('Renaming %s into %s', path, new_name) | ||
283 | 254 | os.rename(path, new_name) | ||
284 | 255 | return new_name | ||
285 | 256 | |||
286 | 257 | def _remove_flat_installation(placeholder): | ||
287 | 258 | if not os.path.isdir(placeholder): | ||
288 | 259 | log.warn('Unkown installation at %s', placeholder) | ||
289 | 260 | return False | ||
290 | 261 | found = False | ||
291 | 262 | for file in os.listdir(placeholder): | ||
292 | 263 | if fnmatch.fnmatch(file, 'setuptools*.egg-info'): | ||
293 | 264 | found = True | ||
294 | 265 | break | ||
295 | 266 | if not found: | ||
296 | 267 | log.warn('Could not locate setuptools*.egg-info') | ||
297 | 268 | return | ||
298 | 269 | |||
299 | 270 | log.warn('Removing elements out of the way...') | ||
300 | 271 | pkg_info = os.path.join(placeholder, file) | ||
301 | 272 | if os.path.isdir(pkg_info): | ||
302 | 273 | patched = _patch_egg_dir(pkg_info) | ||
303 | 274 | else: | ||
304 | 275 | patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) | ||
305 | 276 | |||
306 | 277 | if not patched: | ||
307 | 278 | log.warn('%s already patched.', pkg_info) | ||
308 | 279 | return False | ||
309 | 280 | # now let's move the files out of the way | ||
310 | 281 | for element in ('setuptools', 'pkg_resources.py', 'site.py'): | ||
311 | 282 | element = os.path.join(placeholder, element) | ||
312 | 283 | if os.path.exists(element): | ||
313 | 284 | _rename_path(element) | ||
314 | 285 | else: | ||
315 | 286 | log.warn('Could not find the %s element of the ' | ||
316 | 287 | 'Setuptools distribution', element) | ||
317 | 288 | return True | ||
318 | 289 | |||
319 | 290 | _remove_flat_installation = _no_sandbox(_remove_flat_installation) | ||
320 | 291 | |||
321 | 292 | def _after_install(dist): | ||
322 | 293 | log.warn('After install bootstrap.') | ||
323 | 294 | placeholder = dist.get_command_obj('install').install_purelib | ||
324 | 295 | _create_fake_setuptools_pkg_info(placeholder) | ||
325 | 296 | |||
326 | 297 | def _create_fake_setuptools_pkg_info(placeholder): | ||
327 | 298 | if not placeholder or not os.path.exists(placeholder): | ||
328 | 299 | log.warn('Could not find the install location') | ||
329 | 300 | return | ||
330 | 301 | pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) | ||
331 | 302 | setuptools_file = 'setuptools-%s-py%s.egg-info' % \ | ||
332 | 303 | (SETUPTOOLS_FAKED_VERSION, pyver) | ||
333 | 304 | pkg_info = os.path.join(placeholder, setuptools_file) | ||
334 | 305 | if os.path.exists(pkg_info): | ||
335 | 306 | log.warn('%s already exists', pkg_info) | ||
336 | 307 | return | ||
337 | 308 | |||
338 | 309 | log.warn('Creating %s', pkg_info) | ||
339 | 310 | f = open(pkg_info, 'w') | ||
340 | 311 | try: | ||
341 | 312 | f.write(SETUPTOOLS_PKG_INFO) | ||
342 | 313 | finally: | ||
343 | 314 | f.close() | ||
344 | 315 | |||
345 | 316 | pth_file = os.path.join(placeholder, 'setuptools.pth') | ||
346 | 317 | log.warn('Creating %s', pth_file) | ||
347 | 318 | f = open(pth_file, 'w') | ||
348 | 319 | try: | ||
349 | 320 | f.write(os.path.join(os.curdir, setuptools_file)) | ||
350 | 321 | finally: | ||
351 | 322 | f.close() | ||
352 | 323 | |||
353 | 324 | _create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) | ||
354 | 325 | |||
355 | 326 | def _patch_egg_dir(path): | ||
356 | 327 | # let's check if it's already patched | ||
357 | 328 | pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') | ||
358 | 329 | if os.path.exists(pkg_info): | ||
359 | 330 | if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): | ||
360 | 331 | log.warn('%s already patched.', pkg_info) | ||
361 | 332 | return False | ||
362 | 333 | _rename_path(path) | ||
363 | 334 | os.mkdir(path) | ||
364 | 335 | os.mkdir(os.path.join(path, 'EGG-INFO')) | ||
365 | 336 | pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') | ||
366 | 337 | f = open(pkg_info, 'w') | ||
367 | 338 | try: | ||
368 | 339 | f.write(SETUPTOOLS_PKG_INFO) | ||
369 | 340 | finally: | ||
370 | 341 | f.close() | ||
371 | 342 | return True | ||
372 | 343 | |||
373 | 344 | _patch_egg_dir = _no_sandbox(_patch_egg_dir) | ||
374 | 345 | |||
375 | 346 | def _before_install(): | ||
376 | 347 | log.warn('Before install bootstrap.') | ||
377 | 348 | _fake_setuptools() | ||
378 | 349 | |||
379 | 350 | |||
380 | 351 | def _under_prefix(location): | ||
381 | 352 | if 'install' not in sys.argv: | ||
382 | 353 | return True | ||
383 | 354 | args = sys.argv[sys.argv.index('install')+1:] | ||
384 | 355 | for index, arg in enumerate(args): | ||
385 | 356 | for option in ('--root', '--prefix'): | ||
386 | 357 | if arg.startswith('%s=' % option): | ||
387 | 358 | top_dir = arg.split('root=')[-1] | ||
388 | 359 | return location.startswith(top_dir) | ||
389 | 360 | elif arg == option: | ||
390 | 361 | if len(args) > index: | ||
391 | 362 | top_dir = args[index+1] | ||
392 | 363 | return location.startswith(top_dir) | ||
393 | 364 | if arg == '--user' and USER_SITE is not None: | ||
394 | 365 | return location.startswith(USER_SITE) | ||
395 | 366 | return True | ||
396 | 367 | |||
397 | 368 | |||
398 | 369 | def _fake_setuptools(): | ||
399 | 370 | log.warn('Scanning installed packages') | ||
400 | 371 | try: | ||
401 | 372 | import pkg_resources | ||
402 | 373 | except ImportError: | ||
403 | 374 | # we're cool | ||
404 | 375 | log.warn('Setuptools or Distribute does not seem to be installed.') | ||
405 | 376 | return | ||
406 | 377 | ws = pkg_resources.working_set | ||
407 | 378 | try: | ||
408 | 379 | setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', | ||
409 | 380 | replacement=False)) | ||
410 | 381 | except TypeError: | ||
411 | 382 | # old distribute API | ||
412 | 383 | setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) | ||
413 | 384 | |||
414 | 385 | if setuptools_dist is None: | ||
415 | 386 | log.warn('No setuptools distribution found') | ||
416 | 387 | return | ||
417 | 388 | # detecting if it was already faked | ||
418 | 389 | setuptools_location = setuptools_dist.location | ||
419 | 390 | log.warn('Setuptools installation detected at %s', setuptools_location) | ||
420 | 391 | |||
421 | 392 | # if --root or --preix was provided, and if | ||
422 | 393 | # setuptools is not located in them, we don't patch it | ||
423 | 394 | if not _under_prefix(setuptools_location): | ||
424 | 395 | log.warn('Not patching, --root or --prefix is installing Distribute' | ||
425 | 396 | ' in another location') | ||
426 | 397 | return | ||
427 | 398 | |||
428 | 399 | # let's see if its an egg | ||
429 | 400 | if not setuptools_location.endswith('.egg'): | ||
430 | 401 | log.warn('Non-egg installation') | ||
431 | 402 | res = _remove_flat_installation(setuptools_location) | ||
432 | 403 | if not res: | ||
433 | 404 | return | ||
434 | 405 | else: | ||
435 | 406 | log.warn('Egg installation') | ||
436 | 407 | pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') | ||
437 | 408 | if (os.path.exists(pkg_info) and | ||
438 | 409 | _same_content(pkg_info, SETUPTOOLS_PKG_INFO)): | ||
439 | 410 | log.warn('Already patched.') | ||
440 | 411 | return | ||
441 | 412 | log.warn('Patching...') | ||
442 | 413 | # let's create a fake egg replacing setuptools one | ||
443 | 414 | res = _patch_egg_dir(setuptools_location) | ||
444 | 415 | if not res: | ||
445 | 416 | return | ||
446 | 417 | log.warn('Patched done.') | ||
447 | 418 | _relaunch() | ||
448 | 419 | |||
449 | 420 | |||
450 | 421 | def _relaunch(): | ||
451 | 422 | log.warn('Relaunching...') | ||
452 | 423 | # we have to relaunch the process | ||
453 | 424 | # pip marker to avoid a relaunch bug | ||
454 | 425 | if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']: | ||
455 | 426 | sys.argv[0] = 'setup.py' | ||
456 | 427 | args = [sys.executable] + sys.argv | ||
457 | 428 | sys.exit(subprocess.call(args)) | ||
458 | 429 | |||
459 | 430 | |||
460 | 431 | def _extractall(self, path=".", members=None): | ||
461 | 432 | """Extract all members from the archive to the current working | ||
462 | 433 | directory and set owner, modification time and permissions on | ||
463 | 434 | directories afterwards. `path' specifies a different directory | ||
464 | 435 | to extract to. `members' is optional and must be a subset of the | ||
465 | 436 | list returned by getmembers(). | ||
466 | 437 | """ | ||
467 | 438 | import copy | ||
468 | 439 | import operator | ||
469 | 440 | from tarfile import ExtractError | ||
470 | 441 | directories = [] | ||
471 | 442 | |||
472 | 443 | if members is None: | ||
473 | 444 | members = self | ||
474 | 445 | |||
475 | 446 | for tarinfo in members: | ||
476 | 447 | if tarinfo.isdir(): | ||
477 | 448 | # Extract directories with a safe mode. | ||
478 | 449 | directories.append(tarinfo) | ||
479 | 450 | tarinfo = copy.copy(tarinfo) | ||
480 | 451 | tarinfo.mode = 448 # decimal for oct 0700 | ||
481 | 452 | self.extract(tarinfo, path) | ||
482 | 453 | |||
483 | 454 | # Reverse sort directories. | ||
484 | 455 | if sys.version_info < (2, 4): | ||
485 | 456 | def sorter(dir1, dir2): | ||
486 | 457 | return cmp(dir1.name, dir2.name) | ||
487 | 458 | directories.sort(sorter) | ||
488 | 459 | directories.reverse() | ||
489 | 460 | else: | ||
490 | 461 | directories.sort(key=operator.attrgetter('name'), reverse=True) | ||
491 | 462 | |||
492 | 463 | # Set correct owner, mtime and filemode on directories. | ||
493 | 464 | for tarinfo in directories: | ||
494 | 465 | dirpath = os.path.join(path, tarinfo.name) | ||
495 | 466 | try: | ||
496 | 467 | self.chown(tarinfo, dirpath) | ||
497 | 468 | self.utime(tarinfo, dirpath) | ||
498 | 469 | self.chmod(tarinfo, dirpath) | ||
499 | 470 | except ExtractError: | ||
500 | 471 | e = sys.exc_info()[1] | ||
501 | 472 | if self.errorlevel > 1: | ||
502 | 473 | raise | ||
503 | 474 | else: | ||
504 | 475 | self._dbg(1, "tarfile: %s" % e) | ||
505 | 476 | |||
506 | 477 | |||
507 | 478 | def main(argv, version=DEFAULT_VERSION): | ||
508 | 479 | """Install or upgrade setuptools and EasyInstall""" | ||
509 | 480 | tarball = download_setuptools() | ||
510 | 481 | _install(tarball) | ||
511 | 482 | |||
512 | 483 | |||
513 | 484 | if __name__ == '__main__': | ||
514 | 485 | main(sys.argv[1:]) | ||
515 | 0 | 486 | ||
516 | === modified file 'setup.py' | |||
517 | --- setup.py 2011-12-08 03:05:06 +0000 | |||
518 | +++ setup.py 2012-01-27 11:25:27 +0000 | |||
519 | @@ -14,9 +14,11 @@ | |||
520 | 14 | # You should have received a copy of the GNU Lesser General Public License | 14 | # You should have received a copy of the GNU Lesser General Public License |
521 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
522 | 16 | # GNU Lesser General Public License version 3 (see the file LICENSE). | 16 | # GNU Lesser General Public License version 3 (see the file LICENSE). |
526 | 17 | 17 | ||
527 | 18 | 18 | import distribute_setup | |
528 | 19 | from distutils.core import setup | 19 | distribute_setup.use_setuptools() |
529 | 20 | |||
530 | 21 | from setuptools import setup | ||
531 | 20 | import os.path | 22 | import os.path |
532 | 21 | 23 | ||
533 | 22 | description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read() | 24 | description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read() |
534 | @@ -40,7 +42,6 @@ | |||
535 | 40 | install_requires = [ | 42 | install_requires = [ |
536 | 41 | 'bson', | 43 | 'bson', |
537 | 42 | 'iso8601', | 44 | 'iso8601', |
538 | 43 | 'launchpadlib', # Needed for pruning - perhaps should be optional. | ||
539 | 44 | 'oops', | 45 | 'oops', |
540 | 45 | 'pytz', | 46 | 'pytz', |
541 | 46 | ], | 47 | ], |
542 | @@ -48,10 +49,14 @@ | |||
543 | 48 | test=[ | 49 | test=[ |
544 | 49 | 'fixtures', | 50 | 'fixtures', |
545 | 50 | 'testtools', | 51 | 'testtools', |
546 | 52 | ], | ||
547 | 53 | prune=[ | ||
548 | 54 | 'launchpadlib', | ||
549 | 55 | ], | ||
550 | 56 | ), | ||
551 | 57 | entry_points=dict( | ||
552 | 58 | console_scripts=[ # `console_scripts` is a magic name to setuptools | ||
553 | 59 | 'prune = oops_datedir_repo.prune:main [prune]', | ||
554 | 51 | ] | 60 | ] |
555 | 52 | ), | 61 | ), |
556 | 53 | entry_points=dict( | ||
557 | 54 | console_scripts=[ # `console_scripts` is a magic name to setuptools | ||
558 | 55 | 'prune = oops_datedir_repo.prune:main', | ||
559 | 56 | ]), | ||
560 | 57 | ) | 62 | ) |
Hi, this seems to conflate three entirely different things: repo.prune: main [prune]'
- it reformats some stuff (shrug)
- it adds a totally new way to install the package, with a -tonne- of boilerplate (yuck)
- it does a one-line change:
+ 'prune = oops_datedir_
The last thing seems to do its work on it's own - what is is the huge boilerplate for? Why does it need to be copied into the tree?