Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 1 | """distutils.dist |
| 2 | |
| 3 | Provides the Distribution class, which represents the module distribution |
Greg Ward | 8ff5a3f | 2000-06-02 00:44:53 +0000 | [diff] [blame] | 4 | being built/installed/distributed. |
| 5 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 6 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 7 | __revision__ = "$Id$" |
| 8 | |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 9 | import sys, os, re |
Tarek Ziadé | b88a496 | 2009-12-08 09:45:25 +0000 | [diff] [blame] | 10 | from email import message_from_file |
Andrew M. Kuchling | ff4ad9a | 2002-10-31 13:22:41 +0000 | [diff] [blame] | 11 | |
| 12 | try: |
| 13 | import warnings |
Andrew M. Kuchling | ccf4e42 | 2002-10-31 13:39:33 +0000 | [diff] [blame] | 14 | except ImportError: |
Andrew M. Kuchling | ff4ad9a | 2002-10-31 13:22:41 +0000 | [diff] [blame] | 15 | warnings = None |
| 16 | |
Tarek Ziadé | 88e2c5d | 2009-12-21 01:49:00 +0000 | [diff] [blame] | 17 | from distutils.errors import (DistutilsOptionError, DistutilsArgError, |
| 18 | DistutilsModuleError, DistutilsClassError) |
Greg Ward | 2f2b6c6 | 2000-09-25 01:58:07 +0000 | [diff] [blame] | 19 | from distutils.fancy_getopt import FancyGetopt, translate_longopt |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 20 | from distutils.util import check_environ, strtobool, rfc822_escape |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 21 | from distutils import log |
Jeremy Hylton | fcd7353 | 2002-09-11 16:31:53 +0000 | [diff] [blame] | 22 | from distutils.debug import DEBUG |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 23 | |
| 24 | # Regex to define acceptable Distutils command names. This is not *quite* |
| 25 | # the same as a Python NAME -- I don't allow leading underscores. The fact |
| 26 | # that they're very similar is no coincidence; the default naming scheme is |
| 27 | # to look for a Python module named after the command. |
| 28 | command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$') |
| 29 | |
| 30 | |
| 31 | class Distribution: |
Greg Ward | 8ff5a3f | 2000-06-02 00:44:53 +0000 | [diff] [blame] | 32 | """The core of the Distutils. Most of the work hiding behind 'setup' |
| 33 | is really done within a Distribution instance, which farms the work out |
| 34 | to the Distutils commands specified on the command line. |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 35 | |
Greg Ward | 8ff5a3f | 2000-06-02 00:44:53 +0000 | [diff] [blame] | 36 | Setup scripts will almost never instantiate Distribution directly, |
| 37 | unless the 'setup()' function is totally inadequate to their needs. |
| 38 | However, it is conceivable that a setup script might wish to subclass |
| 39 | Distribution for some specialized purpose, and then pass the subclass |
| 40 | to 'setup()' as the 'distclass' keyword argument. If so, it is |
| 41 | necessary to respect the expectations that 'setup' has of Distribution. |
| 42 | See the code for 'setup()', in core.py, for details. |
| 43 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | # 'global_options' describes the command-line options that may be |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 47 | # supplied to the setup script prior to any actual commands. |
| 48 | # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 49 | # these global options. This list should be kept to a bare minimum, |
| 50 | # since every global option is also valid as a command option -- and we |
| 51 | # don't want to pollute the commands with too many options that they |
| 52 | # have minimal control over. |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 53 | # The fourth entry for verbose means that it can be repeated. |
| 54 | global_options = [('verbose', 'v', "run verbosely (default)", 1), |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 55 | ('quiet', 'q', "run quietly (turns verbosity off)"), |
| 56 | ('dry-run', 'n', "don't actually do anything"), |
| 57 | ('help', 'h', "show detailed help message"), |
Tarek Ziadé | c7c71ff | 2009-10-27 23:12:01 +0000 | [diff] [blame] | 58 | ('no-user-cfg', None, |
| 59 | 'ignore pydistutils.cfg in your home directory'), |
| 60 | ] |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 61 | |
Martin v. Löwis | 8ed338a | 2005-03-03 08:12:27 +0000 | [diff] [blame] | 62 | # 'common_usage' is a short (2-3 line) string describing the common |
| 63 | # usage of the setup script. |
| 64 | common_usage = """\ |
| 65 | Common commands: (see '--help-commands' for more) |
| 66 | |
| 67 | setup.py build will build the package underneath 'build/' |
| 68 | setup.py install will install the package |
| 69 | """ |
| 70 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 71 | # options that are not propagated to the commands |
| 72 | display_options = [ |
| 73 | ('help-commands', None, |
| 74 | "list all available commands"), |
| 75 | ('name', None, |
| 76 | "print package name"), |
| 77 | ('version', 'V', |
| 78 | "print package version"), |
| 79 | ('fullname', None, |
| 80 | "print <package name>-<version>"), |
| 81 | ('author', None, |
| 82 | "print the author's name"), |
| 83 | ('author-email', None, |
| 84 | "print the author's email address"), |
| 85 | ('maintainer', None, |
| 86 | "print the maintainer's name"), |
| 87 | ('maintainer-email', None, |
| 88 | "print the maintainer's email address"), |
| 89 | ('contact', None, |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 90 | "print the maintainer's name if known, else the author's"), |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 91 | ('contact-email', None, |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 92 | "print the maintainer's email address if known, else the author's"), |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 93 | ('url', None, |
| 94 | "print the URL for this package"), |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 95 | ('license', None, |
Andrew M. Kuchling | fa7dc57 | 2001-08-10 18:49:23 +0000 | [diff] [blame] | 96 | "print the license of the package"), |
| 97 | ('licence', None, |
| 98 | "alias for --license"), |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 99 | ('description', None, |
| 100 | "print the package description"), |
Greg Ward | e5a584e | 2000-04-26 02:26:55 +0000 | [diff] [blame] | 101 | ('long-description', None, |
| 102 | "print the long package description"), |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 103 | ('platforms', None, |
| 104 | "print the list of platforms"), |
Andrew M. Kuchling | 282e2c3 | 2003-01-03 15:24:36 +0000 | [diff] [blame] | 105 | ('classifiers', None, |
| 106 | "print the list of classifiers"), |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 107 | ('keywords', None, |
| 108 | "print the list of keywords"), |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 109 | ('provides', None, |
| 110 | "print the list of packages/modules provided"), |
| 111 | ('requires', None, |
| 112 | "print the list of packages/modules required"), |
| 113 | ('obsoletes', None, |
| 114 | "print the list of packages/modules made obsolete") |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 115 | ] |
Guido van Rossum | c1f779c | 2007-07-03 08:25:58 +0000 | [diff] [blame] | 116 | display_option_names = [translate_longopt(x[0]) for x in display_options] |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 117 | |
| 118 | # negative options are options that exclude other options |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 119 | negative_opt = {'quiet': 'verbose'} |
| 120 | |
| 121 | |
| 122 | # -- Creation/initialization methods ------------------------------- |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 123 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 124 | def __init__ (self, attrs=None): |
| 125 | """Construct a new Distribution instance: initialize all the |
Greg Ward | 8ff5a3f | 2000-06-02 00:44:53 +0000 | [diff] [blame] | 126 | attributes of a Distribution, and then use 'attrs' (a dictionary |
| 127 | mapping attribute names to values) to assign some of those |
| 128 | attributes their "real" values. (Any attributes not mentioned in |
| 129 | 'attrs' will be assigned to some null value: 0, None, an empty list |
| 130 | or dictionary, etc.) Most importantly, initialize the |
| 131 | 'command_obj' attribute to the empty dictionary; this will be |
| 132 | filled in with real command objects by 'parse_command_line()'. |
| 133 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 134 | |
| 135 | # Default values for our command-line options |
| 136 | self.verbose = 1 |
| 137 | self.dry_run = 0 |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 138 | self.help = 0 |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 139 | for attr in self.display_option_names: |
| 140 | setattr(self, attr, 0) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 141 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 142 | # Store the distribution meta-data (name, version, author, and so |
| 143 | # forth) in a separate object -- we're getting to have enough |
| 144 | # information here (and enough command-line options) that it's |
| 145 | # worth it. Also delegate 'get_XXX()' methods to the 'metadata' |
| 146 | # object in a sneaky and underhanded (but efficient!) way. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 147 | self.metadata = DistributionMetadata() |
Neil Schemenauer | a8aefe5 | 2001-09-03 15:47:21 +0000 | [diff] [blame] | 148 | for basename in self.metadata._METHOD_BASENAMES: |
Greg Ward | 4982f98 | 2000-04-22 02:52:44 +0000 | [diff] [blame] | 149 | method_name = "get_" + basename |
| 150 | setattr(self, method_name, getattr(self.metadata, method_name)) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 151 | |
| 152 | # 'cmdclass' maps command names to class objects, so we |
| 153 | # can 1) quickly figure out which class to instantiate when |
| 154 | # we need to create a new command object, and 2) have a way |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 155 | # for the setup script to override command classes |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 156 | self.cmdclass = {} |
| 157 | |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 158 | # 'command_packages' is a list of packages in which commands |
| 159 | # are searched for. The factory for command 'foo' is expected |
| 160 | # to be named 'foo' in the module 'foo' in one of the packages |
| 161 | # named here. This list is searched from the left; an error |
| 162 | # is raised if no named package provides the command being |
| 163 | # searched for. (Always access using get_command_packages().) |
| 164 | self.command_packages = None |
| 165 | |
Greg Ward | 9821bf4 | 2000-08-29 01:15:18 +0000 | [diff] [blame] | 166 | # 'script_name' and 'script_args' are usually set to sys.argv[0] |
| 167 | # and sys.argv[1:], but they can be overridden when the caller is |
| 168 | # not necessarily a setup script run from the command-line. |
| 169 | self.script_name = None |
| 170 | self.script_args = None |
| 171 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 172 | # 'command_options' is where we store command options between |
| 173 | # parsing them (from config files, the command-line, etc.) and when |
| 174 | # they are actually needed -- ie. when the command in question is |
| 175 | # instantiated. It is a dictionary of dictionaries of 2-tuples: |
| 176 | # command_options = { command_name : { option : (source, value) } } |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 177 | self.command_options = {} |
| 178 | |
Martin v. Löwis | 98da562 | 2005-03-23 18:54:36 +0000 | [diff] [blame] | 179 | # 'dist_files' is the list of (command, pyversion, file) that |
| 180 | # have been created by any dist commands run so far. This is |
| 181 | # filled regardless of whether the run is dry or not. pyversion |
| 182 | # gives sysconfig.get_python_version() if the dist file is |
| 183 | # specific to a Python version, 'any' if it is good for all |
| 184 | # Python versions on the target platform, and '' for a source |
| 185 | # file. pyversion should not be used to specify minimum or |
| 186 | # maximum required Python versions; use the metainfo for that |
| 187 | # instead. |
Martin v. Löwis | 55f1bb8 | 2005-03-21 20:56:35 +0000 | [diff] [blame] | 188 | self.dist_files = [] |
| 189 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 190 | # These options are really the business of various commands, rather |
| 191 | # than of the Distribution itself. We provide aliases for them in |
| 192 | # Distribution as a convenience to the developer. |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 193 | self.packages = None |
Fred Drake | 0eb32a6 | 2004-06-11 21:50:33 +0000 | [diff] [blame] | 194 | self.package_data = {} |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 195 | self.package_dir = None |
| 196 | self.py_modules = None |
| 197 | self.libraries = None |
Greg Ward | 51def7d | 2000-05-27 01:36:14 +0000 | [diff] [blame] | 198 | self.headers = None |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 199 | self.ext_modules = None |
| 200 | self.ext_package = None |
| 201 | self.include_dirs = None |
| 202 | self.extra_path = None |
Gregory P. Smith | b2e3bb3 | 2000-05-12 00:52:23 +0000 | [diff] [blame] | 203 | self.scripts = None |
Gregory P. Smith | 6a901dd | 2000-05-13 03:09:50 +0000 | [diff] [blame] | 204 | self.data_files = None |
Tarek Ziadé | 13f7c3b | 2009-01-09 00:15:45 +0000 | [diff] [blame] | 205 | self.password = '' |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 206 | |
| 207 | # And now initialize bookkeeping stuff that can't be supplied by |
| 208 | # the caller at all. 'command_obj' maps command names to |
| 209 | # Command instances -- that's how we enforce that every command |
| 210 | # class is a singleton. |
| 211 | self.command_obj = {} |
| 212 | |
| 213 | # 'have_run' maps command names to boolean values; it keeps track |
| 214 | # of whether we have actually run a particular command, to make it |
| 215 | # cheap to "run" a command whenever we think we might need to -- if |
| 216 | # it's already been done, no need for expensive filesystem |
| 217 | # operations, we just check the 'have_run' dictionary and carry on. |
| 218 | # It's only safe to query 'have_run' for a command class that has |
| 219 | # been instantiated -- a false value will be inserted when the |
| 220 | # command object is created, and replaced with a true value when |
Greg Ward | 612eb9f | 2000-07-27 02:13:20 +0000 | [diff] [blame] | 221 | # the command is successfully run. Thus it's probably best to use |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 222 | # '.get()' rather than a straight lookup. |
| 223 | self.have_run = {} |
| 224 | |
| 225 | # Now we'll use the attrs dictionary (ultimately, keyword args from |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 226 | # the setup script) to possibly override any or all of these |
| 227 | # distribution options. |
| 228 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 229 | if attrs: |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 230 | # Pull out the set of command options and work on them |
| 231 | # specifically. Note that this order guarantees that aliased |
| 232 | # command options will override any supplied redundantly |
| 233 | # through the general options dictionary. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 234 | options = attrs.get('options') |
Tarek Ziadé | 4450dcf | 2008-12-29 22:38:38 +0000 | [diff] [blame] | 235 | if options is not None: |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 236 | del attrs['options'] |
| 237 | for (command, cmd_options) in options.items(): |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 238 | opt_dict = self.get_option_dict(command) |
| 239 | for (opt, val) in cmd_options.items(): |
| 240 | opt_dict[opt] = ("setup script", val) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 241 | |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 242 | if 'licence' in attrs: |
Andrew M. Kuchling | a52b852 | 2003-03-03 20:07:27 +0000 | [diff] [blame] | 243 | attrs['license'] = attrs['licence'] |
| 244 | del attrs['licence'] |
| 245 | msg = "'licence' distribution option is deprecated; use 'license'" |
| 246 | if warnings is not None: |
| 247 | warnings.warn(msg) |
| 248 | else: |
| 249 | sys.stderr.write(msg + "\n") |
| 250 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 251 | # Now work on the rest of the attributes. Any attribute that's |
| 252 | # not already defined is invalid! |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 253 | for (key, val) in attrs.items(): |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 254 | if hasattr(self.metadata, "set_" + key): |
| 255 | getattr(self.metadata, "set_" + key)(val) |
| 256 | elif hasattr(self.metadata, key): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 257 | setattr(self.metadata, key, val) |
| 258 | elif hasattr(self, key): |
| 259 | setattr(self, key, val) |
Anthony Baxter | 73cc847 | 2004-10-13 13:22:34 +0000 | [diff] [blame] | 260 | else: |
Andrew M. Kuchling | ff4ad9a | 2002-10-31 13:22:41 +0000 | [diff] [blame] | 261 | msg = "Unknown distribution option: %s" % repr(key) |
| 262 | if warnings is not None: |
| 263 | warnings.warn(msg) |
| 264 | else: |
| 265 | sys.stderr.write(msg + "\n") |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 266 | |
Tarek Ziadé | c7c71ff | 2009-10-27 23:12:01 +0000 | [diff] [blame] | 267 | # no-user-cfg is handled before other command line args |
| 268 | # because other args override the config files, and this |
| 269 | # one is needed before we can load the config files. |
| 270 | # If attrs['script_args'] wasn't passed, assume false. |
| 271 | # |
| 272 | # This also make sure we just look at the global options |
| 273 | self.want_user_cfg = True |
| 274 | |
| 275 | if self.script_args is not None: |
| 276 | for arg in self.script_args: |
| 277 | if not arg.startswith('-'): |
| 278 | break |
| 279 | if arg == '--no-user-cfg': |
| 280 | self.want_user_cfg = False |
| 281 | break |
| 282 | |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 283 | self.finalize_options() |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 284 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 285 | def get_option_dict(self, command): |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 286 | """Get the option dictionary for a given command. If that |
| 287 | command's option dictionary hasn't been created yet, then create it |
| 288 | and return the new dictionary; otherwise, return the existing |
| 289 | option dictionary. |
| 290 | """ |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 291 | dict = self.command_options.get(command) |
| 292 | if dict is None: |
| 293 | dict = self.command_options[command] = {} |
| 294 | return dict |
| 295 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 296 | def dump_option_dicts(self, header=None, commands=None, indent=""): |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 297 | from pprint import pformat |
| 298 | |
| 299 | if commands is None: # dump all command option dicts |
Guido van Rossum | d4ee167 | 2007-10-15 01:27:53 +0000 | [diff] [blame] | 300 | commands = sorted(self.command_options.keys()) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 301 | |
| 302 | if header is not None: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 303 | self.announce(indent + header) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 304 | indent = indent + " " |
| 305 | |
| 306 | if not commands: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 307 | self.announce(indent + "no commands known yet") |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 308 | return |
| 309 | |
| 310 | for cmd_name in commands: |
| 311 | opt_dict = self.command_options.get(cmd_name) |
| 312 | if opt_dict is None: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 313 | self.announce(indent + |
| 314 | "no option dict for '%s' command" % cmd_name) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 315 | else: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 316 | self.announce(indent + |
| 317 | "option dict for '%s' command:" % cmd_name) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 318 | out = pformat(opt_dict) |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 319 | for line in out.split('\n'): |
| 320 | self.announce(indent + " " + line) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 321 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 322 | # -- Config file finding/parsing methods --------------------------- |
| 323 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 324 | def find_config_files(self): |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 325 | """Find as many configuration files as should be processed for this |
| 326 | platform, and return a list of filenames in the order in which they |
| 327 | should be parsed. The filenames returned are guaranteed to exist |
| 328 | (modulo nasty race conditions). |
| 329 | |
Andrew M. Kuchling | d303b61 | 2001-12-06 16:32:05 +0000 | [diff] [blame] | 330 | There are three possible config files: distutils.cfg in the |
| 331 | Distutils installation directory (ie. where the top-level |
| 332 | Distutils __inst__.py file lives), a file in the user's home |
| 333 | directory named .pydistutils.cfg on Unix and pydistutils.cfg |
Tarek Ziadé | c7c71ff | 2009-10-27 23:12:01 +0000 | [diff] [blame] | 334 | on Windows/Mac; and setup.cfg in the current directory. |
| 335 | |
| 336 | The file in the user's home directory can be disabled with the |
| 337 | --no-user-cfg option. |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 338 | """ |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 339 | files = [] |
Greg Ward | acf3f6a | 2000-06-07 02:26:19 +0000 | [diff] [blame] | 340 | check_environ() |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 341 | |
Greg Ward | 1169687 | 2000-06-07 02:29:03 +0000 | [diff] [blame] | 342 | # Where to look for the system-wide Distutils config file |
| 343 | sys_dir = os.path.dirname(sys.modules['distutils'].__file__) |
| 344 | |
| 345 | # Look for the system config file |
| 346 | sys_file = os.path.join(sys_dir, "distutils.cfg") |
Greg Ward | acf3f6a | 2000-06-07 02:26:19 +0000 | [diff] [blame] | 347 | if os.path.isfile(sys_file): |
| 348 | files.append(sys_file) |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 349 | |
Greg Ward | 1169687 | 2000-06-07 02:29:03 +0000 | [diff] [blame] | 350 | # What to call the per-user config file |
| 351 | if os.name == 'posix': |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 352 | user_filename = ".pydistutils.cfg" |
| 353 | else: |
| 354 | user_filename = "pydistutils.cfg" |
Greg Ward | fa9ff76 | 2000-10-14 04:06:40 +0000 | [diff] [blame] | 355 | |
Greg Ward | 1169687 | 2000-06-07 02:29:03 +0000 | [diff] [blame] | 356 | # And look for the user config file |
Tarek Ziadé | c7c71ff | 2009-10-27 23:12:01 +0000 | [diff] [blame] | 357 | if self.want_user_cfg: |
| 358 | user_file = os.path.join(os.path.expanduser('~'), user_filename) |
| 359 | if os.path.isfile(user_file): |
| 360 | files.append(user_file) |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 361 | |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 362 | # All platforms support local setup.cfg |
| 363 | local_file = "setup.cfg" |
| 364 | if os.path.isfile(local_file): |
| 365 | files.append(local_file) |
| 366 | |
Tarek Ziadé | c7c71ff | 2009-10-27 23:12:01 +0000 | [diff] [blame] | 367 | if DEBUG: |
| 368 | self.announce("using config files: %s" % ', '.join(files)) |
| 369 | |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 370 | return files |
| 371 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 372 | def parse_config_files(self, filenames=None): |
Alexandre Vassalotti | 1d1eaa4 | 2008-05-14 22:59:42 +0000 | [diff] [blame] | 373 | from configparser import ConfigParser |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 374 | |
| 375 | if filenames is None: |
| 376 | filenames = self.find_config_files() |
| 377 | |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 378 | if DEBUG: |
| 379 | self.announce("Distribution.parse_config_files():") |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 380 | |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 381 | parser = ConfigParser() |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 382 | for filename in filenames: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 383 | if DEBUG: |
Tarek Ziadé | 31d4607 | 2009-09-21 13:55:19 +0000 | [diff] [blame] | 384 | self.announce(" reading %s" % filename) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 385 | parser.read(filename) |
| 386 | for section in parser.sections(): |
| 387 | options = parser.options(section) |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 388 | opt_dict = self.get_option_dict(section) |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 389 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 390 | for opt in options: |
| 391 | if opt != '__name__': |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 392 | val = parser.get(section,opt) |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 393 | opt = opt.replace('-', '_') |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 394 | opt_dict[opt] = (filename, val) |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 395 | |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 396 | # Make the ConfigParser forget everything (so we retain |
Fred Drake | f06116d | 2004-02-17 22:35:19 +0000 | [diff] [blame] | 397 | # the original filenames that options come from) |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 398 | parser.__init__() |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 399 | |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 400 | # If there was a "global" section in the config file, use it |
| 401 | # to set Distribution options. |
| 402 | |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 403 | if 'global' in self.command_options: |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 404 | for (opt, (src, val)) in self.command_options['global'].items(): |
| 405 | alias = self.negative_opt.get(opt) |
| 406 | try: |
| 407 | if alias: |
| 408 | setattr(self, alias, not strtobool(val)) |
| 409 | elif opt in ('verbose', 'dry_run'): # ugh! |
| 410 | setattr(self, opt, strtobool(val)) |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 411 | else: |
| 412 | setattr(self, opt, val) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 413 | except ValueError as msg: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 414 | raise DistutilsOptionError(msg) |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 415 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 416 | # -- Command-line parsing methods ---------------------------------- |
| 417 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 418 | def parse_command_line(self): |
Greg Ward | 9821bf4 | 2000-08-29 01:15:18 +0000 | [diff] [blame] | 419 | """Parse the setup script's command line, taken from the |
| 420 | 'script_args' instance attribute (which defaults to 'sys.argv[1:]' |
| 421 | -- see 'setup()' in core.py). This list is first processed for |
| 422 | "global options" -- options that set attributes of the Distribution |
| 423 | instance. Then, it is alternately scanned for Distutils commands |
| 424 | and options for that command. Each new command terminates the |
| 425 | options for the previous command. The allowed options for a |
| 426 | command are determined by the 'user_options' attribute of the |
| 427 | command class -- thus, we have to be able to load command classes |
| 428 | in order to parse the command line. Any error in that 'options' |
| 429 | attribute raises DistutilsGetoptError; any error on the |
| 430 | command-line raises DistutilsArgError. If no Distutils commands |
| 431 | were found on the command line, raises DistutilsArgError. Return |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 432 | true if command-line was successfully parsed and we should carry |
Greg Ward | 9821bf4 | 2000-08-29 01:15:18 +0000 | [diff] [blame] | 433 | on with executing commands; false if no errors but we shouldn't |
| 434 | execute commands (currently, this only happens if user asks for |
| 435 | help). |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 436 | """ |
Andrew M. Kuchling | 3f819ec | 2001-01-15 16:09:35 +0000 | [diff] [blame] | 437 | # |
Fred Drake | 981a178 | 2001-08-10 18:59:30 +0000 | [diff] [blame] | 438 | # We now have enough information to show the Macintosh dialog |
| 439 | # that allows the user to interactively specify the "command line". |
Andrew M. Kuchling | 3f819ec | 2001-01-15 16:09:35 +0000 | [diff] [blame] | 440 | # |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 441 | toplevel_options = self._get_toplevel_options() |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 442 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 443 | # We have to parse the command line a bit at a time -- global |
| 444 | # options, then the first command, then its options, and so on -- |
| 445 | # because each command will be handled by a different class, and |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 446 | # the options that are valid for a particular class aren't known |
| 447 | # until we have loaded the command class, which doesn't happen |
| 448 | # until we know what the command is. |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 449 | |
| 450 | self.commands = [] |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 451 | parser = FancyGetopt(toplevel_options + self.display_options) |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 452 | parser.set_negative_aliases(self.negative_opt) |
Andrew M. Kuchling | fa7dc57 | 2001-08-10 18:49:23 +0000 | [diff] [blame] | 453 | parser.set_aliases({'licence': 'license'}) |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 454 | args = parser.getopt(args=self.script_args, object=self) |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 455 | option_order = parser.get_option_order() |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 456 | log.set_verbosity(self.verbose) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 457 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 458 | # for display options we return immediately |
| 459 | if self.handle_display_options(option_order): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 460 | return |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 461 | while args: |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 462 | args = self._parse_command_opts(parser, args) |
| 463 | if args is None: # user asked for help (and got it) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 464 | return |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 465 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 466 | # Handle the cases of --help as a "global" option, ie. |
| 467 | # "setup.py --help" and "setup.py --help command ...". For the |
| 468 | # former, we show global options (--verbose, --dry-run, etc.) |
| 469 | # and display-only options (--name, --version, etc.); for the |
| 470 | # latter, we omit the display-only options and show help for |
| 471 | # each command listed on the command line. |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 472 | if self.help: |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 473 | self._show_help(parser, |
| 474 | display_options=len(self.commands) == 0, |
| 475 | commands=self.commands) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 476 | return |
| 477 | |
| 478 | # Oops, no commands found -- an end-user error |
| 479 | if not self.commands: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 480 | raise DistutilsArgError("no commands supplied") |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 481 | |
| 482 | # All is well: return true |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 483 | return True |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 484 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 485 | def _get_toplevel_options(self): |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 486 | """Return the non-display options recognized at the top level. |
| 487 | |
| 488 | This includes options that are recognized *only* at the top |
| 489 | level as well as options recognized for commands. |
| 490 | """ |
| 491 | return self.global_options + [ |
| 492 | ("command-packages=", None, |
| 493 | "list of packages that provide distutils commands"), |
| 494 | ] |
| 495 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 496 | def _parse_command_opts(self, parser, args): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 497 | """Parse the command-line options for a single command. |
| 498 | 'parser' must be a FancyGetopt instance; 'args' must be the list |
| 499 | of arguments, starting with the current command (whose options |
| 500 | we are about to parse). Returns a new version of 'args' with |
| 501 | the next command at the front of the list; will be the empty |
| 502 | list if there are no more commands on the command line. Returns |
| 503 | None if the user asked for help on this command. |
| 504 | """ |
| 505 | # late import because of mutual dependence between these modules |
| 506 | from distutils.cmd import Command |
| 507 | |
| 508 | # Pull the current command from the head of the command line |
| 509 | command = args[0] |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 510 | if not command_re.match(command): |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 511 | raise SystemExit("invalid command name '%s'" % command) |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 512 | self.commands.append(command) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 513 | |
| 514 | # Dig up the command class that implements this command, so we |
| 515 | # 1) know that it's a valid command, and 2) know which options |
| 516 | # it takes. |
| 517 | try: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 518 | cmd_class = self.get_command_class(command) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 519 | except DistutilsModuleError as msg: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 520 | raise DistutilsArgError(msg) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 521 | |
| 522 | # Require that the command class be derived from Command -- want |
| 523 | # to be sure that the basic "command" interface is implemented. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 524 | if not issubclass(cmd_class, Command): |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 525 | raise DistutilsClassError( |
| 526 | "command class %s must subclass Command" % cmd_class) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 527 | |
| 528 | # Also make sure that the command object provides a list of its |
| 529 | # known options. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 530 | if not (hasattr(cmd_class, 'user_options') and |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 531 | isinstance(cmd_class.user_options, list)): |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 532 | raise DistutilsClassError(("command class %s must provide " + |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 533 | "'user_options' attribute (a list of tuples)") % \ |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 534 | cmd_class) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 535 | |
| 536 | # If the command class has a list of negative alias options, |
| 537 | # merge it in with the global negative aliases. |
| 538 | negative_opt = self.negative_opt |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 539 | if hasattr(cmd_class, 'negative_opt'): |
Antoine Pitrou | 56a00de | 2009-05-15 17:34:21 +0000 | [diff] [blame] | 540 | negative_opt = negative_opt.copy() |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 541 | negative_opt.update(cmd_class.negative_opt) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 542 | |
Greg Ward | fa9ff76 | 2000-10-14 04:06:40 +0000 | [diff] [blame] | 543 | # Check for help_options in command class. They have a different |
| 544 | # format (tuple of four) so we need to preprocess them here. |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 545 | if (hasattr(cmd_class, 'help_options') and |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 546 | isinstance(cmd_class.help_options, list)): |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 547 | help_options = fix_help_options(cmd_class.help_options) |
| 548 | else: |
Greg Ward | 55fced3 | 2000-06-24 01:22:41 +0000 | [diff] [blame] | 549 | help_options = [] |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 550 | |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 551 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 552 | # All commands support the global options too, just by adding |
| 553 | # in 'global_options'. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 554 | parser.set_option_table(self.global_options + |
| 555 | cmd_class.user_options + |
| 556 | help_options) |
| 557 | parser.set_negative_aliases(negative_opt) |
| 558 | (args, opts) = parser.getopt(args[1:]) |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 559 | if hasattr(opts, 'help') and opts.help: |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 560 | self._show_help(parser, display_options=0, commands=[cmd_class]) |
| 561 | return |
| 562 | |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 563 | if (hasattr(cmd_class, 'help_options') and |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 564 | isinstance(cmd_class.help_options, list)): |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 565 | help_option_found=0 |
| 566 | for (help_option, short, desc, func) in cmd_class.help_options: |
| 567 | if hasattr(opts, parser.get_attr_name(help_option)): |
| 568 | help_option_found=1 |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 569 | if hasattr(func, '__call__'): |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 570 | func() |
Greg Ward | 55fced3 | 2000-06-24 01:22:41 +0000 | [diff] [blame] | 571 | else: |
Fred Drake | 981a178 | 2001-08-10 18:59:30 +0000 | [diff] [blame] | 572 | raise DistutilsClassError( |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 573 | "invalid help function %r for help option '%s': " |
Fred Drake | 981a178 | 2001-08-10 18:59:30 +0000 | [diff] [blame] | 574 | "must be a callable object (function, etc.)" |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 575 | % (func, help_option)) |
Greg Ward | 55fced3 | 2000-06-24 01:22:41 +0000 | [diff] [blame] | 576 | |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 577 | if help_option_found: |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 578 | return |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 579 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 580 | # Put the options from the command-line into their official |
| 581 | # holding pen, the 'command_options' dictionary. |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 582 | opt_dict = self.get_option_dict(command) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 583 | for (name, value) in vars(opts).items(): |
Greg Ward | 0e48cfd | 2000-05-26 01:00:15 +0000 | [diff] [blame] | 584 | opt_dict[name] = ("command line", value) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 585 | |
| 586 | return args |
| 587 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 588 | def finalize_options(self): |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 589 | """Set final values for all the options on the Distribution |
| 590 | instance, analogous to the .finalize_options() method of Command |
| 591 | objects. |
| 592 | """ |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 593 | for attr in ('keywords', 'platforms'): |
| 594 | value = getattr(self.metadata, attr) |
| 595 | if value is None: |
| 596 | continue |
| 597 | if isinstance(value, str): |
| 598 | value = [elm.strip() for elm in value.split(',')] |
| 599 | setattr(self.metadata, attr, value) |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 600 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 601 | def _show_help(self, parser, global_options=1, display_options=1, |
| 602 | commands=[]): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 603 | """Show help for the setup script command-line in the form of |
| 604 | several lists of command-line options. 'parser' should be a |
| 605 | FancyGetopt instance; do not expect it to be returned in the |
| 606 | same state, as its option table will be reset to make it |
| 607 | generate the correct help text. |
| 608 | |
| 609 | If 'global_options' is true, lists the global options: |
| 610 | --verbose, --dry-run, etc. If 'display_options' is true, lists |
| 611 | the "display-only" options: --name, --version, etc. Finally, |
| 612 | lists per-command help for every command name or command class |
| 613 | in 'commands'. |
| 614 | """ |
| 615 | # late import because of mutual dependence between these modules |
Greg Ward | 9821bf4 | 2000-08-29 01:15:18 +0000 | [diff] [blame] | 616 | from distutils.core import gen_usage |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 617 | from distutils.cmd import Command |
| 618 | |
| 619 | if global_options: |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 620 | if display_options: |
| 621 | options = self._get_toplevel_options() |
| 622 | else: |
| 623 | options = self.global_options |
| 624 | parser.set_option_table(options) |
Martin v. Löwis | 8ed338a | 2005-03-03 08:12:27 +0000 | [diff] [blame] | 625 | parser.print_help(self.common_usage + "\nGlobal options:") |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 626 | print('') |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 627 | |
| 628 | if display_options: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 629 | parser.set_option_table(self.display_options) |
| 630 | parser.print_help( |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 631 | "Information display options (just display " + |
| 632 | "information, ignore any commands)") |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 633 | print('') |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 634 | |
| 635 | for command in self.commands: |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 636 | if isinstance(command, type) and issubclass(command, Command): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 637 | klass = command |
| 638 | else: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 639 | klass = self.get_command_class(command) |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 640 | if (hasattr(klass, 'help_options') and |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 641 | isinstance(klass.help_options, list)): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 642 | parser.set_option_table(klass.user_options + |
| 643 | fix_help_options(klass.help_options)) |
Jeremy Hylton | 65d6edb | 2000-07-07 20:45:21 +0000 | [diff] [blame] | 644 | else: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 645 | parser.set_option_table(klass.user_options) |
| 646 | parser.print_help("Options for '%s' command:" % klass.__name__) |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 647 | print('') |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 648 | |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 649 | print(gen_usage(self.script_name)) |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 650 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 651 | def handle_display_options(self, option_order): |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 652 | """If there were any non-global "display-only" options |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 653 | (--help-commands or the metadata display options) on the command |
| 654 | line, display the requested info and return true; else return |
| 655 | false. |
| 656 | """ |
Greg Ward | 9821bf4 | 2000-08-29 01:15:18 +0000 | [diff] [blame] | 657 | from distutils.core import gen_usage |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 658 | |
| 659 | # User just wants a list of commands -- we'll print it out and stop |
| 660 | # processing now (ie. if they ran "setup --help-commands foo bar", |
| 661 | # we ignore "foo bar"). |
| 662 | if self.help_commands: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 663 | self.print_commands() |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 664 | print('') |
| 665 | print(gen_usage(self.script_name)) |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 666 | return 1 |
| 667 | |
| 668 | # If user supplied any of the "display metadata" options, then |
| 669 | # display that metadata in the order in which the user supplied the |
| 670 | # metadata options. |
| 671 | any_display_options = 0 |
| 672 | is_display_option = {} |
| 673 | for option in self.display_options: |
| 674 | is_display_option[option[0]] = 1 |
| 675 | |
| 676 | for (opt, val) in option_order: |
| 677 | if val and is_display_option.get(opt): |
Greg Ward | 2f2b6c6 | 2000-09-25 01:58:07 +0000 | [diff] [blame] | 678 | opt = translate_longopt(opt) |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 679 | value = getattr(self.metadata, "get_"+opt)() |
| 680 | if opt in ['keywords', 'platforms']: |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 681 | print(','.join(value)) |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 682 | elif opt in ('classifiers', 'provides', 'requires', |
| 683 | 'obsoletes'): |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 684 | print('\n'.join(value)) |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 685 | else: |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 686 | print(value) |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 687 | any_display_options = 1 |
| 688 | |
| 689 | return any_display_options |
| 690 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 691 | def print_command_list(self, commands, header, max_length): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 692 | """Print a subset of the list of all commands -- used by |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 693 | 'print_commands()'. |
| 694 | """ |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 695 | print(header + ":") |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 696 | |
| 697 | for cmd in commands: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 698 | klass = self.cmdclass.get(cmd) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 699 | if not klass: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 700 | klass = self.get_command_class(cmd) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 701 | try: |
| 702 | description = klass.description |
| 703 | except AttributeError: |
| 704 | description = "(no description available)" |
| 705 | |
Tarek Ziadé | 0d3fa83 | 2009-07-04 03:00:50 +0000 | [diff] [blame] | 706 | print(" %-*s %s" % (max_length, cmd, description)) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 707 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 708 | def print_commands(self): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 709 | """Print out a help message listing all available commands with a |
| 710 | description of each. The list is divided into "standard commands" |
| 711 | (listed in distutils.command.__all__) and "extra commands" |
| 712 | (mentioned in self.cmdclass, but not a standard command). The |
| 713 | descriptions come from the command class attribute |
| 714 | 'description'. |
| 715 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 716 | import distutils.command |
| 717 | std_commands = distutils.command.__all__ |
| 718 | is_std = {} |
| 719 | for cmd in std_commands: |
| 720 | is_std[cmd] = 1 |
| 721 | |
| 722 | extra_commands = [] |
| 723 | for cmd in self.cmdclass.keys(): |
| 724 | if not is_std.get(cmd): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 725 | extra_commands.append(cmd) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 726 | |
| 727 | max_length = 0 |
| 728 | for cmd in (std_commands + extra_commands): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 729 | if len(cmd) > max_length: |
| 730 | max_length = len(cmd) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 731 | |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 732 | self.print_command_list(std_commands, |
| 733 | "Standard commands", |
| 734 | max_length) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 735 | if extra_commands: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 736 | print() |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 737 | self.print_command_list(extra_commands, |
| 738 | "Extra commands", |
| 739 | max_length) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 740 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 741 | def get_command_list(self): |
Greg Ward | f6fc875 | 2000-11-11 02:47:11 +0000 | [diff] [blame] | 742 | """Get a list of (command, description) tuples. |
| 743 | The list is divided into "standard commands" (listed in |
| 744 | distutils.command.__all__) and "extra commands" (mentioned in |
| 745 | self.cmdclass, but not a standard command). The descriptions come |
| 746 | from the command class attribute 'description'. |
| 747 | """ |
| 748 | # Currently this is only used on Mac OS, for the Mac-only GUI |
| 749 | # Distutils interface (by Jack Jansen) |
Greg Ward | f6fc875 | 2000-11-11 02:47:11 +0000 | [diff] [blame] | 750 | import distutils.command |
| 751 | std_commands = distutils.command.__all__ |
| 752 | is_std = {} |
| 753 | for cmd in std_commands: |
| 754 | is_std[cmd] = 1 |
| 755 | |
| 756 | extra_commands = [] |
| 757 | for cmd in self.cmdclass.keys(): |
| 758 | if not is_std.get(cmd): |
| 759 | extra_commands.append(cmd) |
| 760 | |
| 761 | rv = [] |
| 762 | for cmd in (std_commands + extra_commands): |
| 763 | klass = self.cmdclass.get(cmd) |
| 764 | if not klass: |
| 765 | klass = self.get_command_class(cmd) |
| 766 | try: |
| 767 | description = klass.description |
| 768 | except AttributeError: |
| 769 | description = "(no description available)" |
| 770 | rv.append((cmd, description)) |
| 771 | return rv |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 772 | |
| 773 | # -- Command class/object methods ---------------------------------- |
| 774 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 775 | def get_command_packages(self): |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 776 | """Return a list of packages from which commands are loaded.""" |
| 777 | pkgs = self.command_packages |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 778 | if not isinstance(pkgs, list): |
| 779 | if pkgs is None: |
| 780 | pkgs = '' |
| 781 | pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != ''] |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 782 | if "distutils.command" not in pkgs: |
| 783 | pkgs.insert(0, "distutils.command") |
| 784 | self.command_packages = pkgs |
| 785 | return pkgs |
| 786 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 787 | def get_command_class(self, command): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 788 | """Return the class that implements the Distutils command named by |
| 789 | 'command'. First we check the 'cmdclass' dictionary; if the |
| 790 | command is mentioned there, we fetch the class object from the |
| 791 | dictionary and return it. Otherwise we load the command module |
| 792 | ("distutils.command." + command) and fetch the command class from |
| 793 | the module. The loaded class is also stored in 'cmdclass' |
| 794 | to speed future calls to 'get_command_class()'. |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 795 | |
Gregory P. Smith | 1426354 | 2000-05-12 00:41:33 +0000 | [diff] [blame] | 796 | Raises DistutilsModuleError if the expected module could not be |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 797 | found, or if that module does not define the expected class. |
| 798 | """ |
| 799 | klass = self.cmdclass.get(command) |
| 800 | if klass: |
| 801 | return klass |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 802 | |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 803 | for pkgname in self.get_command_packages(): |
| 804 | module_name = "%s.%s" % (pkgname, command) |
| 805 | klass_name = command |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 806 | |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 807 | try: |
| 808 | __import__ (module_name) |
| 809 | module = sys.modules[module_name] |
| 810 | except ImportError: |
| 811 | continue |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 812 | |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 813 | try: |
| 814 | klass = getattr(module, klass_name) |
| 815 | except AttributeError: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 816 | raise DistutilsModuleError( |
| 817 | "invalid command '%s' (no class '%s' in module '%s')" |
| 818 | % (command, klass_name, module_name)) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 819 | |
Fred Drake | d04573f | 2004-08-03 16:37:40 +0000 | [diff] [blame] | 820 | self.cmdclass[command] = klass |
| 821 | return klass |
| 822 | |
| 823 | raise DistutilsModuleError("invalid command '%s'" % command) |
| 824 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 825 | def get_command_obj(self, command, create=1): |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 826 | """Return the command object for 'command'. Normally this object |
Greg Ward | 612eb9f | 2000-07-27 02:13:20 +0000 | [diff] [blame] | 827 | is cached on a previous call to 'get_command_obj()'; if no command |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 828 | object for 'command' is in the cache, then we either create and |
| 829 | return it (if 'create' is true) or return None. |
| 830 | """ |
| 831 | cmd_obj = self.command_obj.get(command) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 832 | if not cmd_obj and create: |
Greg Ward | 2bd3f42 | 2000-06-02 01:59:33 +0000 | [diff] [blame] | 833 | if DEBUG: |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 834 | self.announce("Distribution.get_command_obj(): " \ |
| 835 | "creating '%s' command object" % command) |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 836 | |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 837 | klass = self.get_command_class(command) |
Greg Ward | 4746077 | 2000-05-23 03:47:35 +0000 | [diff] [blame] | 838 | cmd_obj = self.command_obj[command] = klass(self) |
| 839 | self.have_run[command] = 0 |
| 840 | |
| 841 | # Set any options that were supplied in config files |
| 842 | # or on the command line. (NB. support for error |
| 843 | # reporting is lame here: any errors aren't reported |
| 844 | # until 'finalize_options()' is called, which means |
| 845 | # we won't report the source of the error.) |
| 846 | options = self.command_options.get(command) |
| 847 | if options: |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 848 | self._set_command_options(cmd_obj, options) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 849 | |
| 850 | return cmd_obj |
| 851 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 852 | def _set_command_options(self, command_obj, option_dict=None): |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 853 | """Set the options for 'command_obj' from 'option_dict'. Basically |
| 854 | this means copying elements of a dictionary ('option_dict') to |
| 855 | attributes of an instance ('command'). |
| 856 | |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 857 | 'command_obj' must be a Command instance. If 'option_dict' is not |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 858 | supplied, uses the standard option dictionary for this command |
| 859 | (from 'self.command_options'). |
| 860 | """ |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 861 | command_name = command_obj.get_command_name() |
| 862 | if option_dict is None: |
| 863 | option_dict = self.get_option_dict(command_name) |
| 864 | |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 865 | if DEBUG: |
| 866 | self.announce(" setting options for '%s' command:" % command_name) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 867 | for (option, (source, value)) in option_dict.items(): |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 868 | if DEBUG: |
| 869 | self.announce(" %s = %s (from %s)" % (option, value, |
| 870 | source)) |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 871 | try: |
Amaury Forgeot d'Arc | 61cb087 | 2008-07-26 20:09:45 +0000 | [diff] [blame] | 872 | bool_opts = [translate_longopt(o) |
| 873 | for o in command_obj.boolean_options] |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 874 | except AttributeError: |
| 875 | bool_opts = [] |
| 876 | try: |
| 877 | neg_opt = command_obj.negative_opt |
| 878 | except AttributeError: |
| 879 | neg_opt = {} |
| 880 | |
| 881 | try: |
Guido van Rossum | 3172c5d | 2007-10-16 18:12:55 +0000 | [diff] [blame] | 882 | is_string = isinstance(value, str) |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 883 | if option in neg_opt and is_string: |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 884 | setattr(command_obj, neg_opt[option], not strtobool(value)) |
Greg Ward | 2c08cf0 | 2000-09-27 00:15:37 +0000 | [diff] [blame] | 885 | elif option in bool_opts and is_string: |
Greg Ward | ceb9e22 | 2000-09-25 01:23:52 +0000 | [diff] [blame] | 886 | setattr(command_obj, option, strtobool(value)) |
| 887 | elif hasattr(command_obj, option): |
| 888 | setattr(command_obj, option, value) |
| 889 | else: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 890 | raise DistutilsOptionError( |
| 891 | "error in %s: command '%s' has no such option '%s'" |
| 892 | % (source, command_name, option)) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 893 | except ValueError as msg: |
Collin Winter | 5b7e9d7 | 2007-08-30 03:52:21 +0000 | [diff] [blame] | 894 | raise DistutilsOptionError(msg) |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 895 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 896 | def reinitialize_command(self, command, reinit_subcommands=0): |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 897 | """Reinitializes a command to the state it was in when first |
| 898 | returned by 'get_command_obj()': ie., initialized but not yet |
Greg Ward | 7d9c705 | 2000-06-28 01:25:27 +0000 | [diff] [blame] | 899 | finalized. This provides the opportunity to sneak option |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 900 | values in programmatically, overriding or supplementing |
| 901 | user-supplied values from the config files and command line. |
| 902 | You'll have to re-finalize the command object (by calling |
| 903 | 'finalize_options()' or 'ensure_finalized()') before using it for |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 904 | real. |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 905 | |
Greg Ward | f449ea5 | 2000-09-16 15:23:28 +0000 | [diff] [blame] | 906 | 'command' should be a command name (string) or command object. If |
| 907 | 'reinit_subcommands' is true, also reinitializes the command's |
| 908 | sub-commands, as declared by the 'sub_commands' class attribute (if |
| 909 | it has one). See the "install" command for an example. Only |
| 910 | reinitializes the sub-commands that actually matter, ie. those |
| 911 | whose test predicates return true. |
| 912 | |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 913 | Returns the reinitialized command object. |
| 914 | """ |
| 915 | from distutils.cmd import Command |
| 916 | if not isinstance(command, Command): |
| 917 | command_name = command |
| 918 | command = self.get_command_obj(command_name) |
| 919 | else: |
| 920 | command_name = command.get_command_name() |
| 921 | |
| 922 | if not command.finalized: |
Greg Ward | 282c7a0 | 2000-06-01 01:09:47 +0000 | [diff] [blame] | 923 | return command |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 924 | command.initialize_options() |
| 925 | command.finalized = 0 |
Greg Ward | 43955c9 | 2000-06-06 02:52:36 +0000 | [diff] [blame] | 926 | self.have_run[command_name] = 0 |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 927 | self._set_command_options(command) |
Greg Ward | f449ea5 | 2000-09-16 15:23:28 +0000 | [diff] [blame] | 928 | |
Greg Ward | f449ea5 | 2000-09-16 15:23:28 +0000 | [diff] [blame] | 929 | if reinit_subcommands: |
Greg Ward | f449ea5 | 2000-09-16 15:23:28 +0000 | [diff] [blame] | 930 | for sub in command.get_sub_commands(): |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 931 | self.reinitialize_command(sub, reinit_subcommands) |
Greg Ward | f449ea5 | 2000-09-16 15:23:28 +0000 | [diff] [blame] | 932 | |
Greg Ward | c32d9a6 | 2000-05-28 23:53:06 +0000 | [diff] [blame] | 933 | return command |
| 934 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 935 | # -- Methods that operate on the Distribution ---------------------- |
| 936 | |
Tarek Ziadé | 05bf01a | 2009-07-04 02:04:21 +0000 | [diff] [blame] | 937 | def announce(self, msg, level=log.INFO): |
| 938 | log.log(level, msg) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 939 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 940 | def run_commands(self): |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 941 | """Run each command that was seen on the setup script command line. |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 942 | Uses the list of commands found and cache of command objects |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 943 | created by 'get_command_obj()'. |
| 944 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 945 | for cmd in self.commands: |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 946 | self.run_command(cmd) |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 947 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 948 | # -- Methods that operate on its Commands -------------------------- |
| 949 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 950 | def run_command(self, command): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 951 | """Do whatever it takes to run a command (including nothing at all, |
Greg Ward | d5d8a99 | 2000-05-23 01:42:17 +0000 | [diff] [blame] | 952 | if the command has already been run). Specifically: if we have |
| 953 | already created and run the command named by 'command', return |
| 954 | silently without doing anything. If the command named by 'command' |
| 955 | doesn't even have a command object yet, create one. Then invoke |
| 956 | 'run()' on that command object (or an existing one). |
| 957 | """ |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 958 | # Already been here, done that? then return silently. |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 959 | if self.have_run.get(command): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 960 | return |
| 961 | |
Jeremy Hylton | cd8a114 | 2002-06-04 20:14:43 +0000 | [diff] [blame] | 962 | log.info("running %s", command) |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 963 | cmd_obj = self.get_command_obj(command) |
| 964 | cmd_obj.ensure_finalized() |
| 965 | cmd_obj.run() |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 966 | self.have_run[command] = 1 |
| 967 | |
| 968 | |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 969 | # -- Distribution query methods ------------------------------------ |
| 970 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 971 | def has_pure_modules(self): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 972 | return len(self.packages or self.py_modules or []) > 0 |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 973 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 974 | def has_ext_modules(self): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 975 | return self.ext_modules and len(self.ext_modules) > 0 |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 976 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 977 | def has_c_libraries(self): |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 978 | return self.libraries and len(self.libraries) > 0 |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 979 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 980 | def has_modules(self): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 981 | return self.has_pure_modules() or self.has_ext_modules() |
| 982 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 983 | def has_headers(self): |
Greg Ward | 51def7d | 2000-05-27 01:36:14 +0000 | [diff] [blame] | 984 | return self.headers and len(self.headers) > 0 |
| 985 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 986 | def has_scripts(self): |
Greg Ward | 44a61bb | 2000-05-20 15:06:48 +0000 | [diff] [blame] | 987 | return self.scripts and len(self.scripts) > 0 |
| 988 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 989 | def has_data_files(self): |
Greg Ward | 44a61bb | 2000-05-20 15:06:48 +0000 | [diff] [blame] | 990 | return self.data_files and len(self.data_files) > 0 |
| 991 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 992 | def is_pure(self): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 993 | return (self.has_pure_modules() and |
| 994 | not self.has_ext_modules() and |
| 995 | not self.has_c_libraries()) |
| 996 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 997 | # -- Metadata query methods ---------------------------------------- |
| 998 | |
| 999 | # If you're looking for 'get_name()', 'get_version()', and so forth, |
| 1000 | # they are defined in a sneaky way: the constructor binds self.get_XXX |
| 1001 | # to self.metadata.get_XXX. The actual code is in the |
| 1002 | # DistributionMetadata class, below. |
| 1003 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1004 | class DistributionMetadata: |
| 1005 | """Dummy class to hold the distribution meta-data: name, version, |
Greg Ward | fd7b91e | 2000-09-26 01:52:25 +0000 | [diff] [blame] | 1006 | author, and so forth. |
| 1007 | """ |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1008 | |
Neil Schemenauer | a8aefe5 | 2001-09-03 15:47:21 +0000 | [diff] [blame] | 1009 | _METHOD_BASENAMES = ("name", "version", "author", "author_email", |
| 1010 | "maintainer", "maintainer_email", "url", |
| 1011 | "license", "description", "long_description", |
| 1012 | "keywords", "platforms", "fullname", "contact", |
Andrew M. Kuchling | a52b852 | 2003-03-03 20:07:27 +0000 | [diff] [blame] | 1013 | "contact_email", "license", "classifiers", |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1014 | "download_url", |
| 1015 | # PEP 314 |
| 1016 | "provides", "requires", "obsoletes", |
| 1017 | ) |
Neil Schemenauer | a8aefe5 | 2001-09-03 15:47:21 +0000 | [diff] [blame] | 1018 | |
Tarek Ziadé | b88a496 | 2009-12-08 09:45:25 +0000 | [diff] [blame] | 1019 | def __init__(self, path=None): |
| 1020 | if path is not None: |
| 1021 | self.read_pkg_file(open(path)) |
| 1022 | else: |
| 1023 | self.name = None |
| 1024 | self.version = None |
| 1025 | self.author = None |
| 1026 | self.author_email = None |
| 1027 | self.maintainer = None |
| 1028 | self.maintainer_email = None |
| 1029 | self.url = None |
| 1030 | self.license = None |
| 1031 | self.description = None |
| 1032 | self.long_description = None |
| 1033 | self.keywords = None |
| 1034 | self.platforms = None |
| 1035 | self.classifiers = None |
| 1036 | self.download_url = None |
| 1037 | # PEP 314 |
| 1038 | self.provides = None |
| 1039 | self.requires = None |
| 1040 | self.obsoletes = None |
| 1041 | |
| 1042 | def read_pkg_file(self, file): |
| 1043 | """Reads the metadata values from a file object.""" |
| 1044 | msg = message_from_file(file) |
| 1045 | |
| 1046 | def _read_field(name): |
| 1047 | value = msg[name] |
| 1048 | if value == 'UNKNOWN': |
| 1049 | return None |
| 1050 | return value |
| 1051 | |
| 1052 | def _read_list(name): |
| 1053 | values = msg.get_all(name, None) |
| 1054 | if values == []: |
| 1055 | return None |
| 1056 | return values |
| 1057 | |
| 1058 | metadata_version = msg['metadata-version'] |
| 1059 | self.name = _read_field('name') |
| 1060 | self.version = _read_field('version') |
| 1061 | self.description = _read_field('summary') |
| 1062 | # we are filling author only. |
| 1063 | self.author = _read_field('author') |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1064 | self.maintainer = None |
Tarek Ziadé | b88a496 | 2009-12-08 09:45:25 +0000 | [diff] [blame] | 1065 | self.author_email = _read_field('author-email') |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1066 | self.maintainer_email = None |
Tarek Ziadé | b88a496 | 2009-12-08 09:45:25 +0000 | [diff] [blame] | 1067 | self.url = _read_field('home-page') |
| 1068 | self.license = _read_field('license') |
| 1069 | |
| 1070 | if 'download-url' in msg: |
| 1071 | self.download_url = _read_field('download-url') |
| 1072 | else: |
| 1073 | self.download_url = None |
| 1074 | |
| 1075 | self.long_description = _read_field('description') |
| 1076 | self.description = _read_field('summary') |
| 1077 | |
| 1078 | if 'keywords' in msg: |
| 1079 | self.keywords = _read_field('keywords').split(',') |
| 1080 | |
| 1081 | self.platforms = _read_list('platform') |
| 1082 | self.classifiers = _read_list('classifier') |
| 1083 | |
| 1084 | # PEP 314 - these fields only exist in 1.1 |
| 1085 | if metadata_version == '1.1': |
| 1086 | self.requires = _read_list('requires') |
| 1087 | self.provides = _read_list('provides') |
| 1088 | self.obsoletes = _read_list('obsoletes') |
| 1089 | else: |
| 1090 | self.requires = None |
| 1091 | self.provides = None |
| 1092 | self.obsoletes = None |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 1093 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1094 | def write_pkg_info(self, base_dir): |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 1095 | """Write the PKG-INFO file into the release tree. |
| 1096 | """ |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 1097 | pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w') |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1098 | self.write_pkg_file(pkg_info) |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 1099 | pkg_info.close() |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 1100 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1101 | def write_pkg_file(self, file): |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1102 | """Write the PKG-INFO format data to a file object. |
| 1103 | """ |
| 1104 | version = '1.0' |
| 1105 | if self.provides or self.requires or self.obsoletes: |
| 1106 | version = '1.1' |
| 1107 | |
| 1108 | file.write('Metadata-Version: %s\n' % version) |
| 1109 | file.write('Name: %s\n' % self.get_name() ) |
| 1110 | file.write('Version: %s\n' % self.get_version() ) |
| 1111 | file.write('Summary: %s\n' % self.get_description() ) |
| 1112 | file.write('Home-page: %s\n' % self.get_url() ) |
| 1113 | file.write('Author: %s\n' % self.get_contact() ) |
| 1114 | file.write('Author-email: %s\n' % self.get_contact_email() ) |
| 1115 | file.write('License: %s\n' % self.get_license() ) |
| 1116 | if self.download_url: |
| 1117 | file.write('Download-URL: %s\n' % self.download_url) |
| 1118 | |
Tarek Ziadé | f11be75 | 2009-06-01 22:36:26 +0000 | [diff] [blame] | 1119 | long_desc = rfc822_escape(self.get_long_description()) |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1120 | file.write('Description: %s\n' % long_desc) |
| 1121 | |
Neal Norwitz | 9d72bb4 | 2007-04-17 08:48:32 +0000 | [diff] [blame] | 1122 | keywords = ','.join(self.get_keywords()) |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1123 | if keywords: |
| 1124 | file.write('Keywords: %s\n' % keywords ) |
| 1125 | |
| 1126 | self._write_list(file, 'Platform', self.get_platforms()) |
| 1127 | self._write_list(file, 'Classifier', self.get_classifiers()) |
| 1128 | |
| 1129 | # PEP 314 |
| 1130 | self._write_list(file, 'Requires', self.get_requires()) |
| 1131 | self._write_list(file, 'Provides', self.get_provides()) |
| 1132 | self._write_list(file, 'Obsoletes', self.get_obsoletes()) |
| 1133 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1134 | def _write_list(self, file, name, values): |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1135 | for value in values: |
| 1136 | file.write('%s: %s\n' % (name, value)) |
| 1137 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1138 | # -- Metadata query methods ---------------------------------------- |
| 1139 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1140 | def get_name(self): |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 1141 | return self.name or "UNKNOWN" |
| 1142 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1143 | def get_version(self): |
Thomas Heller | bcd8975 | 2001-12-06 20:44:19 +0000 | [diff] [blame] | 1144 | return self.version or "0.0.0" |
Greg Ward | fe6462c | 2000-04-04 01:40:52 +0000 | [diff] [blame] | 1145 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1146 | def get_fullname(self): |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1147 | return "%s-%s" % (self.get_name(), self.get_version()) |
| 1148 | |
| 1149 | def get_author(self): |
| 1150 | return self.author or "UNKNOWN" |
| 1151 | |
| 1152 | def get_author_email(self): |
| 1153 | return self.author_email or "UNKNOWN" |
| 1154 | |
| 1155 | def get_maintainer(self): |
| 1156 | return self.maintainer or "UNKNOWN" |
| 1157 | |
| 1158 | def get_maintainer_email(self): |
| 1159 | return self.maintainer_email or "UNKNOWN" |
| 1160 | |
| 1161 | def get_contact(self): |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1162 | return self.maintainer or self.author or "UNKNOWN" |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1163 | |
| 1164 | def get_contact_email(self): |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1165 | return self.maintainer_email or self.author_email or "UNKNOWN" |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1166 | |
| 1167 | def get_url(self): |
| 1168 | return self.url or "UNKNOWN" |
| 1169 | |
Andrew M. Kuchling | fa7dc57 | 2001-08-10 18:49:23 +0000 | [diff] [blame] | 1170 | def get_license(self): |
| 1171 | return self.license or "UNKNOWN" |
| 1172 | get_licence = get_license |
Fred Drake | b94b849 | 2001-12-06 20:51:35 +0000 | [diff] [blame] | 1173 | |
Greg Ward | 82715e1 | 2000-04-21 02:28:14 +0000 | [diff] [blame] | 1174 | def get_description(self): |
| 1175 | return self.description or "UNKNOWN" |
Greg Ward | e5a584e | 2000-04-26 02:26:55 +0000 | [diff] [blame] | 1176 | |
| 1177 | def get_long_description(self): |
| 1178 | return self.long_description or "UNKNOWN" |
| 1179 | |
Andrew M. Kuchling | a7210ed | 2001-03-22 03:06:52 +0000 | [diff] [blame] | 1180 | def get_keywords(self): |
| 1181 | return self.keywords or [] |
| 1182 | |
| 1183 | def get_platforms(self): |
| 1184 | return self.platforms or ["UNKNOWN"] |
| 1185 | |
Andrew M. Kuchling | 282e2c3 | 2003-01-03 15:24:36 +0000 | [diff] [blame] | 1186 | def get_classifiers(self): |
| 1187 | return self.classifiers or [] |
| 1188 | |
Andrew M. Kuchling | 188d85f | 2003-02-19 14:16:01 +0000 | [diff] [blame] | 1189 | def get_download_url(self): |
| 1190 | return self.download_url or "UNKNOWN" |
| 1191 | |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1192 | # PEP 314 |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1193 | def get_requires(self): |
| 1194 | return self.requires or [] |
| 1195 | |
| 1196 | def set_requires(self, value): |
| 1197 | import distutils.versionpredicate |
| 1198 | for v in value: |
| 1199 | distutils.versionpredicate.VersionPredicate(v) |
| 1200 | self.requires = value |
| 1201 | |
| 1202 | def get_provides(self): |
| 1203 | return self.provides or [] |
| 1204 | |
| 1205 | def set_provides(self, value): |
| 1206 | value = [v.strip() for v in value] |
| 1207 | for v in value: |
| 1208 | import distutils.versionpredicate |
Fred Drake | 227e8ff | 2005-03-21 06:36:32 +0000 | [diff] [blame] | 1209 | distutils.versionpredicate.split_provision(v) |
Fred Drake | db7b002 | 2005-03-20 22:19:47 +0000 | [diff] [blame] | 1210 | self.provides = value |
| 1211 | |
| 1212 | def get_obsoletes(self): |
| 1213 | return self.obsoletes or [] |
| 1214 | |
| 1215 | def set_obsoletes(self, value): |
| 1216 | import distutils.versionpredicate |
| 1217 | for v in value: |
| 1218 | distutils.versionpredicate.VersionPredicate(v) |
| 1219 | self.obsoletes = value |
| 1220 | |
Tarek Ziadé | 188789d | 2009-05-16 18:37:32 +0000 | [diff] [blame] | 1221 | def fix_help_options(options): |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 1222 | """Convert a 4-tuple 'help_options' list as found in various command |
| 1223 | classes to the 3-tuple form required by FancyGetopt. |
| 1224 | """ |
| 1225 | new_options = [] |
| 1226 | for help_tuple in options: |
| 1227 | new_options.append(help_tuple[0:3]) |
| 1228 | return new_options |