Mercurial > cpython-lru_cache-weakref
annotate Lib/packaging/command/clean.py @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | 1a31c3be88b1 |
| children |
| rev | line source |
|---|---|
|
70194
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
1 """Clean up temporary files created by the build command.""" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
2 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
3 # Contributed by Bastian Kleineidam <calvin@cs.uni-sb.de> |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
4 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
5 import os |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
6 from shutil import rmtree |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
7 from packaging.command.cmd import Command |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
8 from packaging import logger |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
9 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
10 class clean(Command): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
11 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
12 description = "clean up temporary files from 'build' command" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
13 user_options = [ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
14 ('build-base=', 'b', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
15 "base build directory (default: 'build.build-base')"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
16 ('build-lib=', None, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
17 "build directory for all modules (default: 'build.build-lib')"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
18 ('build-temp=', 't', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
19 "temporary build directory (default: 'build.build-temp')"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
20 ('build-scripts=', None, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
21 "build directory for scripts (default: 'build.build-scripts')"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
22 ('bdist-base=', None, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
23 "temporary directory for built distributions"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
24 ('all', 'a', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
25 "remove all build output, not just temporary by-products") |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
26 ] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
27 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
28 boolean_options = ['all'] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
29 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
30 def initialize_options(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
31 self.build_base = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
32 self.build_lib = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
33 self.build_temp = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
34 self.build_scripts = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
35 self.bdist_base = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
36 self.all = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
37 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
38 def finalize_options(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
39 self.set_undefined_options('build', 'build_base', 'build_lib', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
40 'build_scripts', 'build_temp') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
41 self.set_undefined_options('bdist', 'bdist_base') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
42 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
43 def run(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
44 # remove the build/temp.<plat> directory (unless it's already |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
45 # gone) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
46 if os.path.exists(self.build_temp): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
47 if self.dry_run: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
48 logger.info('removing %s', self.build_temp) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
49 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
50 rmtree(self.build_temp) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
51 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
52 logger.debug("'%s' does not exist -- can't clean it", |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
53 self.build_temp) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
54 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
55 if self.all: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
56 # remove build directories |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
57 for directory in (self.build_lib, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
58 self.bdist_base, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
59 self.build_scripts): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
60 if os.path.exists(directory): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
61 if self.dry_run: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
62 logger.info('removing %s', directory) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
63 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
64 rmtree(directory) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
65 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
66 logger.warning("'%s' does not exist -- can't clean it", |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
67 directory) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
68 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
69 # just for the heck of it, try to remove the base build directory: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
70 # we might have emptied it right now, but if not we don't care |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
71 if not self.dry_run: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
72 try: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
73 os.rmdir(self.build_base) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
74 logger.info("removing '%s'", self.build_base) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
75 except OSError: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
76 pass |
