annotate Lib/distutils/command/clean.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 2b9c91668777
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.command.clean
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
2
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
3 Implements the Distutils 'clean' command."""
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
4
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
6
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
7 __revision__ = "$Id$"
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
8
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
9 import os
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
10 from distutils.core import Command
13871
8307446bc6aa Fixed imports from '*util' modules to not just import everything from util.
Greg Ward <gward@python.net>
parents: 12785
diff changeset
11 from distutils.dir_util import remove_tree
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
12 from distutils import log
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
13
52582
2b9c91668777 added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
14 class clean(Command):
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
15
34648
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
16 description = "clean up temporary files from 'build' command"
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
17 user_options = [
12021
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
18 ('build-base=', 'b',
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
19 "base build directory (default: 'build.build-base')"),
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
20 ('build-lib=', None,
12021
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
21 "build directory for all modules (default: 'build.build-lib')"),
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
22 ('build-temp=', 't',
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
23 "temporary build directory (default: 'build.build-temp')"),
14517
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
24 ('build-scripts=', None,
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
25 "build directory for scripts (default: 'build.build-scripts')"),
12700
94ede04b9a9e Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12699
diff changeset
26 ('bdist-base=', None,
12693
1dee93eb9ee3 Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12021
diff changeset
27 "temporary directory for built distributions"),
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
28 ('all', 'a',
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
29 "remove all build output, not just temporary by-products")
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
30 ]
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
31
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14517
diff changeset
32 boolean_options = ['all']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14517
diff changeset
33
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
34 def initialize_options(self):
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
35 self.build_base = None
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
36 self.build_lib = None
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
37 self.build_temp = None
14517
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
38 self.build_scripts = None
12700
94ede04b9a9e Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12699
diff changeset
39 self.bdist_base = None
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
40 self.all = None
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
41
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
42 def finalize_options(self):
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
43 self.set_undefined_options('build',
12693
1dee93eb9ee3 Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12021
diff changeset
44 ('build_base', 'build_base'),
1dee93eb9ee3 Added the 'build_bdist' option and code to clean it up -- this is the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12021
diff changeset
45 ('build_lib', 'build_lib'),
14517
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
46 ('build_scripts', 'build_scripts'),
12700
94ede04b9a9e Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12699
diff changeset
47 ('build_temp', 'build_temp'))
94ede04b9a9e Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12699
diff changeset
48 self.set_undefined_options('bdist',
94ede04b9a9e Rename 'build_bdist' to 'bdist_base', and get it by default from the
Gregory P. Smith <greg@mad-scientist.com>
parents: 12699
diff changeset
49 ('bdist_base', 'bdist_base'))
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
50
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
51 def run(self):
12021
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
52 # remove the build/temp.<plat> directory (unless it's already
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
53 # gone)
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
54 if os.path.exists(self.build_temp):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
55 remove_tree(self.build_temp, dry_run=self.dry_run)
12785
f6e730f65bce Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents: 12743
diff changeset
56 else:
23701
9a5c48579633 Change warning to debug level; it's a very minor issue.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
57 log.debug("'%s' does not exist -- can't clean it",
9a5c48579633 Change warning to debug level; it's a very minor issue.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
58 self.build_temp)
12785
f6e730f65bce Moved warnings out of 'finalize_options()' into 'run()'.
Greg Ward <gward@python.net>
parents: 12743
diff changeset
59
12018
056972517191 Contribution from Bastian Kleineidam <calvin@cs.uni-sb.de>:
Greg Ward <gward@python.net>
parents:
diff changeset
60 if self.all:
14517
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
61 # remove build directories
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
62 for directory in (self.build_lib,
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
63 self.bdist_base,
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
64 self.build_scripts):
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
65 if os.path.exists(directory):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
66 remove_tree(directory, dry_run=self.dry_run)
14517
bf844ac2c81a Bastian Kleineidam: fix so it cleans up the temporary script-building
Greg Ward <gward@python.net>
parents: 13871
diff changeset
67 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
68 log.warn("'%s' does not exist -- can't clean it",
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
69 directory)
12021
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
70
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
71 # just for the heck of it, try to remove the base build directory:
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
72 # we might have emptied it right now, but if not we don't care
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
73 if not self.dry_run:
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
74 try:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
75 os.rmdir(self.build_base)
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 15216
diff changeset
76 log.info("removing '%s'", self.build_base)
12021
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
77 except OSError:
1e1aebb3e4f6 Tweaked all over:
Greg Ward <gward@python.net>
parents: 12018
diff changeset
78 pass
12743
e878a647e06e Normalized all the end-of-class lines.
Greg Ward <gward@python.net>
parents: 12700
diff changeset
79
e878a647e06e Normalized all the end-of-class lines.
Greg Ward <gward@python.net>
parents: 12700
diff changeset
80 # class clean