annotate Lib/distutils/cmd.py @ 70817:dd775b1561ba

Fix markup.
author Georg Brandl <georg@python.org>
date Tue, 14 Jun 2011 21:09:55 +0200
parents dc245d681901
children 3e26c9033306
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
41480
99027c2b3fd2 Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
9 import sys, os, re
51393
b4820fceda24 Merged revisions 69360 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 48575
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
59 raise TypeError("dist must be a Distribution instance")
12225
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:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
61 raise RuntimeError("Command is an abstract class")
12225
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.
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
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:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
105 raise AttributeError(attr)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
106
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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 """
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
135 raise RuntimeError("abstract method -- subclass %s must override"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
136 % self.__class__)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
137
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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 """
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
149 raise RuntimeError("abstract method -- subclass %s must override"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
150 % self.__class__)
12225
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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()
51418
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
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:
56155
4008a0137de7 Merged revisions 74990 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53148
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)
51418
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
164 self.announce(indent + "%s = %s" % (option, value),
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
165 level=log.INFO)
12789
f0d03689c1ae Added 'dump_options()' for debugging output.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
166
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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 """
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
177 raise RuntimeError("abstract method -- subclass %s must override"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
178 % self.__class__)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
179
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 33965
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43026
diff changeset
214 elif not isinstance(val, str):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
215 raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
216 % (option, what, val))
12849
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
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
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43026
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:
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
237 if isinstance(val, list):
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43026
diff changeset
238 ok = all(isinstance(v, str) for v in val)
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
239 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
240 ok = False
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
241 if not ok:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
242 raise DistutilsOptionError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
243 "'%s' must be a list of strings (got %r)"
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
244 % (option, val))
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
245
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
246 def _ensure_tested_string(self, option, tester, what, error_fmt,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
247 default=None):
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
248 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
249 if val is not None and not tester(val):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
250 raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
251 % (option, val))
12849
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
252
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
253 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
254 """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
255 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
256 "filename",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
257 "'%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
258
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
259 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
260 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
261 "directory name",
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
262 "'%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
263
594c27c870ad Added the 'ensure_*' methods from bdist_rpm; refactored 'ensure_filename()'
Greg Ward <gward@python.net>
parents: 12822
diff changeset
264
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
265 # -- 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
266
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
267 def get_command_name(self):
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
268 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
269 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
270 else:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
271 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
272
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
273 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
274 """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
275 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
276 "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
277 has not been changed between 'initialize_options()' and
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
278 'finalize_options()'. Usually called from 'finalize_options()' for
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
279 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
280 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
281 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
282 for it if necessary); the remaining arguments are
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
283 '(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
284 '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
285 'dst_option' in the current command object".
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
286 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
287 # Option_pairs: list of (src_option, dst_option) tuples
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
288 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
289 src_cmd_obj.ensure_finalized()
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12322
diff changeset
290 for (src_option, dst_option) in option_pairs:
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
291 if getattr(self, dst_option) is None:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
292 setattr(self, dst_option, 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
293
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
294 def get_finalized_command(self, command, create=1):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
295 """Wrapper around Distribution's 'get_command_obj()' method: find
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
296 (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
297 'command', call its 'ensure_finalized()' method, and return the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
298 finalized command object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
299 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
300 cmd_obj = self.distribution.get_command_obj(command, create)
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
301 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
302 return cmd_obj
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
303
12810
711b32960934 Added 'reinitialize_command()' method -- delegated to Distribution instance.
Greg Ward <gward@python.net>
parents: 12789
diff changeset
304 # 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
305 # same in dist.py, if so)
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
306 def reinitialize_command(self, command, reinit_subcommands=0):
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
307 return self.distribution.reinitialize_command(command,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
308 reinit_subcommands)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
309
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
310 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
311 """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
312 Distribution, which creates and finalizes the command object if
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
313 necessary and then invokes its 'run()' method.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
314 """
14863
c3f0d6f19f7b Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14628
diff changeset
315 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
316
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
317 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
318 """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
319 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
320 '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
321 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
322 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
323 """
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
324 commands = []
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
325 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
326 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
327 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
328 return commands
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
329
fe47d238b50d Added the "sub-command" machinery to formalize the notion of "command
Greg Ward <gward@python.net>
parents: 13947
diff changeset
330
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
331 # -- External world manipulation -----------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
332
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
333 def warn(self, msg):
52892
792bb885029f Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 52594
diff changeset
334 log.warn("warning: %s: %s\n" %
792bb885029f Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 52594
diff changeset
335 (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
336
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
337 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
338 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
339
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
340 def mkpath(self, name, mode=0o777):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
341 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
342
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
343 def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
344 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
345 """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
346 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
347 the latter defaults to false for commands that don't define it.)"""
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
348 return file_util.copy_file(infile, outfile, preserve_mode,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
349 preserve_times, not self.force, link,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
350 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
351
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
diff changeset
352 def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1,
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
353 preserve_symlinks=0, level=1):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
354 """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
355 and force flags.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
356 """
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
357 return dir_util.copy_tree(infile, outfile, preserve_mode,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
358 preserve_times, preserve_symlinks,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
359 not self.force, 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
360
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
361 def move_file (self, src, dst, level=1):
68585
bf94b6a73fc8 #11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 56155
diff changeset
362 """Move a file respecting dry-run flag."""
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
363 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
364
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
365 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
366 """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
367 from distutils.spawn import spawn
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
368 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
369
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
370 def make_archive(self, base_name, format, root_dir=None, base_dir=None):
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
371 return archive_util.make_archive(base_name, format, root_dir, base_dir,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
372 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
373
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
374 def make_file(self, infiles, outfile, func, args,
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
375 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
376 """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
377 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
378 '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
379 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
380 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
381 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
382 timestamp checks.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12810
diff changeset
383 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
384 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
385 skip_msg = "skipping %s (inputs unchanged)" % outfile
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
386
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
387 # Allow 'infiles' to be a single string
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43026
diff changeset
388 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
389 infiles = (infiles,)
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41558
diff changeset
390 elif not isinstance(infiles, (list, tuple)):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
391 raise TypeError(
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
392 "'infiles' must be a string, or a list or tuple of strings")
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
393
51418
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
394 if exec_msg is None:
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
395 exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
396
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
397 # 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
398 # 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
399 # perform the action that presumably regenerates it
51418
b091bf834226 Merged revisions 69385 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51393
diff changeset
400 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
401 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
402 # 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
403 else:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
404 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
405
12747
6c6844a2fa30 Added comment to remind us of the (temporary?) obsolescense of the
Greg Ward <gward@python.net>
parents: 12729
diff changeset
406 # 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
407 # 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
408 # 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
409 # 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
410
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
411 class install_misc(Command):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
412 """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
413 Currently used by install_data and install_scripts.
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
414 """
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19583
diff changeset
415
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
416 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
417
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
418 def initialize_options (self):
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
419 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
420 self.outfiles = []
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
421
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
diff changeset
422 def _install_dir_from(self, dirname):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
423 self.set_undefined_options('install', (dirname, 'install_dir'))
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
424
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
diff changeset
425 def _copy_files(self, filelist):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
426 self.outfiles = []
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
427 if not filelist:
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
428 return
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
429 self.mkpath(self.install_dir)
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12601
diff changeset
430 for f in filelist:
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
431 self.copy_file(f, self.install_dir)
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
432 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
433
53148
71f48adad892 Merged revisions 71589 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52892
diff changeset
434 def get_outputs(self):
12677
234074545eb4 In 'install_misc' class:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
435 return self.outfiles