annotate Lib/distutils/cmd.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 c2c90d1f3c33
children cd8d3c2d3bce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.cmd
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
2
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
3 Provides the Command class, the base class for the command classes
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
4 in the distutils.command package.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
5 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
6
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
7 __revision__ = "$Id$"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
8
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
9 import sys, os, re
51391
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
10 from distutils.errors import DistutilsOptionError
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
11 from distutils import util, dir_util, file_util, archive_util, dep_util
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
12 from distutils import log
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
13
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
14 class Command:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
15 """Abstract base class for defining command classes, the "worker bees"
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
16 of the Distutils. A useful analogy for command classes is to think of
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
17 them as subroutines with local variables called "options". The options
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
18 are "declared" in 'initialize_options()' and "defined" (given their
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
19 final values, aka "finalized") in 'finalize_options()', both of which
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
20 must be defined by every command class. The distinction between the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
21 two is necessary because option values might come from the outside
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
22 world (command line, config file, ...), and any options dependent on
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
23 other options must be computed *after* these outside influences have
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
24 been processed -- hence 'finalize_options()'. The "body" of the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
25 subroutine, where it does all its work based on the values of its
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
26 options, is the 'run()' method, which must also be implemented by every
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
27 command class.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
28 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
29
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
30 # 'sub_commands' formalizes the notion of a "family" of commands,
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
31 # eg. "install" as the parent with sub-commands "install_lib",
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
32 # "install_headers", etc. The parent of a family of commands
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
33 # defines 'sub_commands' as a class attribute; it's a list of
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
34 # (command_name : string, predicate : unbound_method | string | None)
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
35 # tuples, where 'predicate' is a method of the parent command that
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
36 # determines whether the corresponding command is applicable in the
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
37 # current situation. (Eg. we "install_headers" is only applicable if
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
38 # we have any C header files to install.) If 'predicate' is None,
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
39 # that command is always applicable.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
40 #
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
41 # 'sub_commands' is usually defined at the *end* of a class, because
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
42 # predicates can be unbound methods, so they must already have been
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
43 # defined. The canonical example is the "install" command.
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
44 sub_commands = []
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
45
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
46
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
47 # -- Creation/initialization methods -------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
48
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
49 def __init__(self, dist):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
50 """Create and initialize a new Command object. Most importantly,
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
51 invokes the 'initialize_options()' method, which is the real
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
52 initializer and depends on the actual command being
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
53 instantiated.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
54 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
55 # late import because of mutual dependence between these classes
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
56 from distutils.dist import Distribution
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
57
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
58 if not isinstance(dist, Distribution):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
59 raise TypeError, "dist must be a Distribution instance"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
60 if self.__class__ is Command:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
61 raise RuntimeError, "Command is an abstract class"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
62
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
63 self.distribution = dist
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
64 self.initialize_options()
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
65
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
66 # Per-command versions of the global flags, so that the user can
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
67 # customize Distutils' behaviour command-by-command and let some
32379
5bfc7543d7ef fix typo
Fred Drake <fdrake@acm.org>
parents: 31515
diff changeset
68 # commands fall back on the Distribution's behaviour. None means
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
69 # "not defined, check self.distribution's copy", while 0 or 1 mean
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
70 # false and true (duh). Note that this means figuring out the real
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
71 # value of each flag is a touch complicated -- hence "self._dry_run"
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
72 # will be handled by __getattr__, below.
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
73 # XXX This needs to be fixed.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
74 self._dry_run = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
75
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
76 # verbose is largely ignored, but needs to be set for
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
77 # backwards compatibility (I think)?
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
78 self.verbose = dist.verbose
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32379
diff changeset
79
12322
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
80 # Some commands define a 'self.force' option to ignore file
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
81 # timestamps, but methods defined *here* assume that
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
82 # 'self.force' exists for all commands. So define it here
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
83 # just to be safe.
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
84 self.force = None
d7629fa3b29f Define 'self.force' in the constructor and remove the hack in '__getattr__()'
Greg Ward <gward@python.net>
parents: 12317
diff changeset
85
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
86 # The 'help' flag is just used for command-line parsing, so
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
87 # none of that complicated bureaucracy is needed.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
88 self.help = 0
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
89
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
90 # 'finalized' records whether or not 'finalize_options()' has been
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
91 # called. 'finalize_options()' itself should not pay attention to
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
92 # this flag: it is the business of 'ensure_finalized()', which
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
93 # always calls 'finalize_options()', to respect/update it.
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
94 self.finalized = 0
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
95
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
96 # XXX A more explicit way to customize dry_run would be better.
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
97 def __getattr__(self, attr):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
98 if attr == 'dry_run':
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
99 myval = getattr(self, "_" + attr)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
100 if myval is None:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
101 return getattr(self.distribution, attr)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
102 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
103 return myval
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
104 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
105 raise AttributeError, attr
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
106
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
107 def ensure_finalized(self):
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
108 if not self.finalized:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
109 self.finalize_options()
12783
b91b35c1d4c0 Some far-reaching naming changes:
Greg Ward <gward@python.net>
parents: 12747
diff changeset
110 self.finalized = 1
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
111
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
112 # Subclasses must define:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
113 # initialize_options()
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
114 # provide default values for all options; may be customized by
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
115 # setup script, by options from config file(s), or by command-line
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
116 # options
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
117 # finalize_options()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
118 # decide on the final values for all options; this is called
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
119 # after all possible intervention from the outside world
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
120 # (command-line, option file, etc.) has been processed
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
121 # run()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
122 # run the command: do whatever it is we're here to do,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
123 # controlled by the command's various option values
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
124
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
125 def initialize_options(self):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
126 """Set default values for all the options that this command
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
127 supports. Note that these defaults may be overridden by other
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
128 commands, by the setup script, by config files, or by the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
129 command-line. Thus, this is not the place to code dependencies
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
130 between options; generally, 'initialize_options()' implementations
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
131 are just a bunch of "self.foo = None" assignments.
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
132
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
133 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
134 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
135 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
136 "abstract method -- subclass %s must override" % self.__class__
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
137
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
138 def finalize_options(self):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
139 """Set final values for all the options that this command supports.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
140 This is always called as late as possible, ie. after any option
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
141 assignments from the command-line or from other commands have been
30723
6f15e73b59f2 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 27988
diff changeset
142 done. Thus, this is the place to code option dependencies: if
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
143 'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
144 long as 'foo' still has the same value it was assigned in
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
145 'initialize_options()'.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
146
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
147 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
148 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
149 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
150 "abstract method -- subclass %s must override" % self.__class__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
151
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
152
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
153 def dump_options(self, header=None, indent=""):
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
154 from distutils.fancy_getopt import longopt_xlate
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
155 if header is None:
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
156 header = "command options for '%s':" % self.get_command_name()
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
157 self.announce(indent + header, level=log.INFO)
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
158 indent = indent + " "
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
159 for (option, _, _) in self.user_options:
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
160 option = option.translate(longopt_xlate)
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
161 if option[-1] == "=":
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
162 option = option[:-1]
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
163 value = getattr(self, option)
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
164 self.announce(indent + "%s = %s" % (option, value),
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
165 level=log.INFO)
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
166
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
167 def run(self):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
168 """A command's raison d'etre: carry out the action it exists to
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
169 perform, controlled by the options initialized in
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
170 'initialize_options()', customized by other commands, the setup
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
171 script, the command-line, and config files, and finalized in
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
172 'finalize_options()'. All terminal output and filesystem
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
173 interaction should be done by 'run()'.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
174
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
175 This method must be implemented by all command classes.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
176 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
177 raise RuntimeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
178 "abstract method -- subclass %s must override" % self.__class__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
179
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
180 def announce(self, msg, level=1):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
181 """If the current verbosity level is of greater than or equal to
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
182 'level' print 'msg' to stdout.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
183 """
27988
b26f5758414a announce(): use the level argument to control the log level.
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
184 log.log(level, msg)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
185
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
186 def debug_print(self, msg):
12886
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
187 """Print 'msg' to stdout if the global DEBUG (taken from the
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
188 DISTUTILS_DEBUG environment variable) flag is true.
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
189 """
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
190 from distutils.debug import DEBUG
12886
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
191 if DEBUG:
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
192 print msg
19583
44a62e3b706f Flush output more aggressively. This makes things look better if
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 17129
diff changeset
193 sys.stdout.flush()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
194
12886
1ae035a31cb4 Added 'debug_print()' method (driven by DEBUG global from distutils.core).
Greg Ward <gward@python.net>
parents: 12849
diff changeset
195
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
196 # -- Option validation methods -------------------------------------
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
197 # (these are very handy in writing the 'finalize_options()' method)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
198 #
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
199 # NB. the general philosophy here is to ensure that a particular option
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
200 # value meets certain type and value constraints. If not, we try to
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
201 # force it into conformance (eg. if we expect a list but have a string,
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
202 # split the string on comma and/or whitespace). If we can't force the
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
203 # option into conformance, raise DistutilsOptionError. Thus, command
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
204 # classes need do nothing more than (eg.)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
205 # self.ensure_string_list('foo')
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
206 # and they can be guaranteed that thereafter, self.foo will be
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
207 # a list of strings.
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
208
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
209 def _ensure_stringlike(self, option, what, default=None):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
210 val = getattr(self, option)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
211 if val is None:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
212 setattr(self, option, default)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
213 return default
51391
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
214 elif not isinstance(val, str):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
215 raise DistutilsOptionError, \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
216 "'%s' must be a %s (got `%s`)" % (option, what, val)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
217 return val
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
218
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
219 def ensure_string(self, option, default=None):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
220 """Ensure that 'option' is a string; if not defined, set it to
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
221 'default'.
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
222 """
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
223 self._ensure_stringlike(option, "string", default)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
224
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
225 def ensure_string_list(self, option):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
226 """Ensure that 'option' is a list of strings. If 'option' is
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
227 currently a string, we split it either on /,\s*/ or /\s+/, so
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
228 "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
229 ["foo", "bar", "baz"].
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
230 """
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
231 val = getattr(self, option)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
232 if val is None:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
233 return
51391
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
234 elif isinstance(val, str):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
235 setattr(self, option, re.split(r',\s*|\s+', val))
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
236 else:
51391
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
237 if isinstance(val, list):
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
238 # checks if all elements are str
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
239 ok = 1
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
240 for element in val:
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
241 if not isinstance(element, str):
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
242 ok = 0
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
243 break
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
244 else:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
245 ok = 0
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
246
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
247 if not ok:
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
248 raise DistutilsOptionError, \
51391
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
249 "'%s' must be a list of strings (got %r)" % \
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
250 (option, val)
183a6c29bf9c removed types usage and added test coverage (work for #3986)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
251
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
252
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
253 def _ensure_tested_string(self, option, tester,
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
254 what, error_fmt, default=None):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
255 val = self._ensure_stringlike(option, what, default)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
256 if val is not None and not tester(val):
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
257 raise DistutilsOptionError, \
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
258 ("error in '%s' option: " + error_fmt) % (option, val)
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
259
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
260 def ensure_filename(self, option):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
261 """Ensure that 'option' is the name of an existing file."""
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
262 self._ensure_tested_string(option, os.path.isfile,
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
263 "filename",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
264 "'%s' does not exist or is not a file")
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
265
53143
4703965da2ce improved test coverage for distutils.cmd
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52581
diff changeset
266 def ensure_dirname(self, option):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
267 self._ensure_tested_string(option, os.path.isdir,
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
268 "directory name",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
269 "'%s' does not exist or is not a directory")
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
270
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
271
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
272 # -- Convenience methods for commands ------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
273
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
274 def get_command_name(self):
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
275 if hasattr(self, 'command_name'):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
276 return self.command_name
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
277 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
278 return self.__class__.__name__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
279
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
280 def set_undefined_options(self, src_cmd, *option_pairs):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
281 """Set the values of any "undefined" options from corresponding
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
282 option values in some other command object. "Undefined" here means
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
283 "is None", which is the convention used to indicate that an option
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
284 has not been changed between 'initialize_options()' and
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
285 'finalize_options()'. Usually called from 'finalize_options()' for
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
286 options that depend on some other command rather than another
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
287 option of the same command. 'src_cmd' is the other command from
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
288 which option values will be taken (a command object will be created
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
289 for it if necessary); the remaining arguments are
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
290 '(src_option,dst_option)' tuples which mean "take the value of
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
291 'src_option' in the 'src_cmd' command object, and copy it to
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
292 'dst_option' in the current command object".
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
293 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
294
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
295 # Option_pairs: list of (src_option, dst_option) tuples
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
296
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
297 src_cmd_obj = self.distribution.get_command_obj(src_cmd)
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
298 src_cmd_obj.ensure_finalized()
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12322
diff changeset
299 for (src_option, dst_option) in option_pairs:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
300 if getattr(self, dst_option) is None:
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
301 setattr(self, dst_option,
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
302 getattr(src_cmd_obj, src_option))
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
303
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
304
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
305 def get_finalized_command(self, command, create=1):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
306 """Wrapper around Distribution's 'get_command_obj()' method: find
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
307 (create if necessary and 'create' is true) the command object for
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
308 'command', call its 'ensure_finalized()' method, and return the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
309 finalized command object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
310 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
311 cmd_obj = self.distribution.get_command_obj(command, create)
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
312 cmd_obj.ensure_finalized()
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
313 return cmd_obj
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
314
12810
711b32960934 Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents: 12789
diff changeset
315 # XXX rename to 'get_reinitialized_command()'? (should do the
711b32960934 Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents: 12789
diff changeset
316 # same in dist.py, if so)
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
317 def reinitialize_command(self, command, reinit_subcommands=0):
14628
7211fbe0db9d In 'reinitialize_subcommand()', pass 'reinit_subcommands' flag on to the
Greg Ward <gward@python.net>
parents: 14626
diff changeset
318 return self.distribution.reinitialize_command(
7211fbe0db9d In 'reinitialize_subcommand()', pass 'reinit_subcommands' flag on to the
Greg Ward <gward@python.net>
parents: 14626
diff changeset
319 command, reinit_subcommands)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
320
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
321 def run_command(self, command):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
322 """Run some other command: uses the 'run_command()' method of
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
323 Distribution, which creates and finalizes the command object if
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
324 necessary and then invokes its 'run()' method.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
325 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
326 self.distribution.run_command(command)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
327
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
328 def get_sub_commands(self):
14626
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
329 """Determine the sub-commands that are relevant in the current
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
330 distribution (ie., that need to be run). This is based on the
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
331 'sub_commands' class attribute: each tuple in that list may include
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
332 a method that we call to determine if the subcommand needs to be
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
333 run for the current distribution. Return a list of command names.
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
334 """
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
335 commands = []
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
336 for (cmd_name, method) in self.sub_commands:
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
337 if method is None or method(self):
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
338 commands.append(cmd_name)
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
339 return commands
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
340
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
341
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
342 # -- External world manipulation -----------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
343
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
344 def warn(self, msg):
52581
1d7a772b3b18 using log.warn for sys.stderr
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51799
diff changeset
345 log.warn("warning: %s: %s\n" %
1d7a772b3b18 using log.warn for sys.stderr
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51799
diff changeset
346 (self.get_command_name(), msg))
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
347
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
348 def execute(self, func, args, msg=None, level=1):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
349 util.execute(func, args, msg, dry_run=self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
350
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
351 def mkpath(self, name, mode=0777):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
352 dir_util.mkpath(name, mode, dry_run=self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
353
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
354 def copy_file(self, infile, outfile,
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
355 preserve_mode=1, preserve_times=1, link=None, level=1):
12317
29e753493d8e Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents: 12313
diff changeset
356 """Copy a file respecting verbose, dry-run and force flags. (The
29e753493d8e Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents: 12313
diff changeset
357 former two default to whatever is in the Distribution object, and
29e753493d8e Added a check for the 'force' attribute in '__getattr__()' -- better than
Greg Ward <gward@python.net>
parents: 12313
diff changeset
358 the latter defaults to false for commands that don't define it.)"""
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
359
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
360 return file_util.copy_file(
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
361 infile, outfile,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
362 preserve_mode, preserve_times,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
363 not self.force,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
364 link,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
365 dry_run=self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
366
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
367 def copy_tree(self, infile, outfile,
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
368 preserve_mode=1, preserve_times=1, preserve_symlinks=0,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
369 level=1):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
370 """Copy an entire directory tree respecting verbose, dry-run,
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
371 and force flags.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
372 """
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
373 return dir_util.copy_tree(
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
374 infile, outfile,
13947
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
375 preserve_mode,preserve_times,preserve_symlinks,
191f20e0473e Fix references to functions formerly imported from 'util'.
Greg Ward <gward@python.net>
parents: 13808
diff changeset
376 not self.force,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
377 dry_run=self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
378
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
379 def move_file (self, src, dst, level=1):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
380 """Move a file respectin dry-run flag."""
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
381 return file_util.move_file(src, dst, dry_run = self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
382
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
383 def spawn (self, cmd, search_path=1, level=1):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
384 """Spawn an external command respecting dry-run flag."""
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
385 from distutils.spawn import spawn
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
386 spawn(cmd, search_path, dry_run= self.dry_run)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
387
56335
c2c90d1f3c33 #6516 added owner/group support for tarfiles in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53147
diff changeset
388 def make_archive(self, base_name, format, root_dir=None, base_dir=None,
c2c90d1f3c33 #6516 added owner/group support for tarfiles in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53147
diff changeset
389 owner=None, group=None):
c2c90d1f3c33 #6516 added owner/group support for tarfiles in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53147
diff changeset
390 return archive_util.make_archive(base_name, format, root_dir,
c2c90d1f3c33 #6516 added owner/group support for tarfiles in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53147
diff changeset
391 base_dir, dry_run=self.dry_run,
c2c90d1f3c33 #6516 added owner/group support for tarfiles in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53147
diff changeset
392 owner=owner, group=group)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
393
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
394 def make_file(self, infiles, outfile, func, args,
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
395 exec_msg=None, skip_msg=None, level=1):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
396 """Special case of 'execute()' for operations that process one or
12313
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
397 more input files and generate one output file. Works just like
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
398 'execute()', except the operation is skipped and a different
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
399 message printed if 'outfile' already exists and is newer than all
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
400 files listed in 'infiles'. If the command defined 'self.force',
90b2a3cd365f Removed global '--force' option -- just too vague a concept to be applicable
Greg Ward <gward@python.net>
parents: 12296
diff changeset
401 and it is true, then the command is unconditionally run -- does no
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
402 timestamp checks.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
403 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
404 if skip_msg is None:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
405 skip_msg = "skipping %s (inputs unchanged)" % outfile
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
406
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
407 # Allow 'infiles' to be a single string
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
408 if isinstance(infiles, str):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
409 infiles = (infiles,)
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
410 elif not isinstance(infiles, (list, tuple)):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
411 raise TypeError, \
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
412 "'infiles' must be a string, or a list or tuple of strings"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
413
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
414 if exec_msg is None:
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
415 exec_msg = "generating %s from %s" % \
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
416 (outfile, ', '.join(infiles))
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
417
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
418 # If 'outfile' must be regenerated (either because it doesn't
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
419 # exist, is out-of-date, or the 'force' flag is true) then
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
420 # perform the action that presumably regenerates it
51416
a7132db69092 #3986 replacing string and types call (like in the Py3k branch), and put exec_msg call at the right place
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51391
diff changeset
421 if self.force or dep_util.newer_group(infiles, outfile):
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
422 self.execute(func, args, exec_msg, level)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
423
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
424 # Otherwise, print the "skip" message
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
425 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
426 log.debug(skip_msg)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
427
12747
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
428 # XXX 'install_misc' class not currently used -- it was the base class for
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
429 # both 'install_scripts' and 'install_data', but they outgrew it. It might
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
430 # still be useful for 'install_headers', though, so I'm keeping it around
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
431 # for the time being.
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
432
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
433 class install_misc(Command):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
434 """Common base class for installing some files in a subdirectory.
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
435 Currently used by install_data and install_scripts.
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
436 """
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
437
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
438 user_options = [('install-dir=', 'd', "directory to install the files to")]
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
439
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
440 def initialize_options (self):
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
441 self.install_dir = None
12705
7ff5ae10a771 In 'install_misc': 'self.outfiles' defaults to the empty list, so we don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12677
diff changeset
442 self.outfiles = []
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
443
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
444 def _install_dir_from(self, dirname):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
445 self.set_undefined_options('install', (dirname, 'install_dir'))
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
446
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
447 def _copy_files(self, filelist):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
448 self.outfiles = []
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
449 if not filelist:
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
450 return
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
451 self.mkpath(self.install_dir)
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
452 for f in filelist:
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
453 self.copy_file(f, self.install_dir)
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
454 self.outfiles.append(os.path.join(self.install_dir, f))
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
455
53147
7baa68d66c8f pep8-fied
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53143
diff changeset
456 def get_outputs(self):
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
457 return self.outfiles