1 """distutils.command.clean
3 Implements the Distutils 'clean' command."""
5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
10 from distutils
.core
import Command
11 from distutils
.dir_util
import remove_tree
12 from distutils
import log
16 description
= "clean up temporary files from 'build' command"
19 "base build directory (default: 'build.build-base')"),
21 "build directory for all modules (default: 'build.build-lib')"),
23 "temporary build directory (default: 'build.build-temp')"),
24 ('build-scripts=', None,
25 "build directory for scripts (default: 'build.build-scripts')"),
27 "temporary directory for built distributions"),
29 "remove all build output, not just temporary by-products")
32 boolean_options
= ['all']
34 def initialize_options(self
):
35 self
.build_base
= None
37 self
.build_temp
= None
38 self
.build_scripts
= None
39 self
.bdist_base
= None
42 def finalize_options(self
):
43 self
.set_undefined_options('build',
44 ('build_base', 'build_base'),
45 ('build_lib', 'build_lib'),
46 ('build_scripts', 'build_scripts'),
47 ('build_temp', 'build_temp'))
48 self
.set_undefined_options('bdist',
49 ('bdist_base', 'bdist_base'))
52 # remove the build/temp.<plat> directory (unless it's already
54 if os
.path
.exists(self
.build_temp
):
55 remove_tree(self
.build_temp
, dry_run
=self
.dry_run
)
57 log
.debug("'%s' does not exist -- can't clean it",
61 # remove build directories
62 for directory
in (self
.build_lib
,
65 if os
.path
.exists(directory
):
66 remove_tree(directory
, dry_run
=self
.dry_run
)
68 log
.warn("'%s' does not exist -- can't clean it",
71 # just for the heck of it, try to remove the base build directory:
72 # we might have emptied it right now, but if not we don't care
75 os
.rmdir(self
.build_base
)
76 log
.info("removing '%s'", self
.build_base
)