blob: 78c29ede6c2c4e3195d88cddfe3b211f2fcc596b [file] [log] [blame]
Greg Wardfe6462c2000-04-04 01:40:52 +00001"""distutils.dist
2
3Provides the Distribution class, which represents the module distribution
Greg Ward8ff5a3f2000-06-02 00:44:53 +00004being built/installed/distributed.
5"""
Greg Wardfe6462c2000-04-04 01:40:52 +00006
Jason R. Coombs7c456322014-07-02 08:36:19 -04007import sys
8import os
9import re
Jason R. Coombs3492e392013-11-10 18:15:03 -050010from email import message_from_file
Andrew M. Kuchlingff4ad9a2002-10-31 13:22:41 +000011
12try:
13 import warnings
Andrew M. Kuchlingccf4e422002-10-31 13:39:33 +000014except ImportError:
Andrew M. Kuchlingff4ad9a2002-10-31 13:22:41 +000015 warnings = None
16
Tarek Ziadé36797272010-07-22 12:50:05 +000017from distutils.errors import *
Greg Ward2f2b6c62000-09-25 01:58:07 +000018from distutils.fancy_getopt import FancyGetopt, translate_longopt
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +000019from distutils.util import check_environ, strtobool, rfc822_escape
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000020from distutils import log
Jeremy Hyltonfcd73532002-09-11 16:31:53 +000021from distutils.debug import DEBUG
Greg Wardfe6462c2000-04-04 01:40:52 +000022
23# Regex to define acceptable Distutils command names. This is not *quite*
24# the same as a Python NAME -- I don't allow leading underscores. The fact
25# that they're very similar is no coincidence; the default naming scheme is
26# to look for a Python module named after the command.
Jason R. Coombs7c456322014-07-02 08:36:19 -040027command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
Greg Wardfe6462c2000-04-04 01:40:52 +000028
29
30class Distribution:
Greg Ward8ff5a3f2000-06-02 00:44:53 +000031 """The core of the Distutils. Most of the work hiding behind 'setup'
32 is really done within a Distribution instance, which farms the work out
33 to the Distutils commands specified on the command line.
Greg Wardfe6462c2000-04-04 01:40:52 +000034
Greg Ward8ff5a3f2000-06-02 00:44:53 +000035 Setup scripts will almost never instantiate Distribution directly,
36 unless the 'setup()' function is totally inadequate to their needs.
37 However, it is conceivable that a setup script might wish to subclass
38 Distribution for some specialized purpose, and then pass the subclass
39 to 'setup()' as the 'distclass' keyword argument. If so, it is
40 necessary to respect the expectations that 'setup' has of Distribution.
41 See the code for 'setup()', in core.py, for details.
42 """
Greg Wardfe6462c2000-04-04 01:40:52 +000043
Greg Wardfe6462c2000-04-04 01:40:52 +000044 # 'global_options' describes the command-line options that may be
Greg Ward82715e12000-04-21 02:28:14 +000045 # supplied to the setup script prior to any actual commands.
46 # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
Greg Wardfe6462c2000-04-04 01:40:52 +000047 # these global options. This list should be kept to a bare minimum,
48 # since every global option is also valid as a command option -- and we
49 # don't want to pollute the commands with too many options that they
50 # have minimal control over.
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000051 # The fourth entry for verbose means that it can be repeated.
Jason R. Coombs7c456322014-07-02 08:36:19 -040052 global_options = [
53 ('verbose', 'v', "run verbosely (default)", 1),
54 ('quiet', 'q', "run quietly (turns verbosity off)"),
55 ('dry-run', 'n', "don't actually do anything"),
56 ('help', 'h', "show detailed help message"),
57 ('no-user-cfg', None,
58 'ignore pydistutils.cfg in your home directory'),
Andrew Kuchling2a1838b2013-11-10 18:11:00 -050059 ]
Greg Ward82715e12000-04-21 02:28:14 +000060
Martin v. Löwis8ed338a2005-03-03 08:12:27 +000061 # 'common_usage' is a short (2-3 line) string describing the common
62 # usage of the setup script.
63 common_usage = """\
64Common commands: (see '--help-commands' for more)
65
66 setup.py build will build the package underneath 'build/'
67 setup.py install will install the package
68"""
69
Greg Ward82715e12000-04-21 02:28:14 +000070 # options that are not propagated to the commands
71 display_options = [
72 ('help-commands', None,
73 "list all available commands"),
74 ('name', None,
75 "print package name"),
76 ('version', 'V',
77 "print package version"),
78 ('fullname', None,
79 "print <package name>-<version>"),
80 ('author', None,
81 "print the author's name"),
82 ('author-email', None,
83 "print the author's email address"),
84 ('maintainer', None,
85 "print the maintainer's name"),
86 ('maintainer-email', None,
87 "print the maintainer's email address"),
88 ('contact', None,
Greg Wardd5d8a992000-05-23 01:42:17 +000089 "print the maintainer's name if known, else the author's"),
Greg Ward82715e12000-04-21 02:28:14 +000090 ('contact-email', None,
Greg Wardd5d8a992000-05-23 01:42:17 +000091 "print the maintainer's email address if known, else the author's"),
Greg Ward82715e12000-04-21 02:28:14 +000092 ('url', None,
93 "print the URL for this package"),
Greg Ward82715e12000-04-21 02:28:14 +000094 ('license', None,
Andrew M. Kuchlingfa7dc572001-08-10 18:49:23 +000095 "print the license of the package"),
96 ('licence', None,
97 "alias for --license"),
Greg Ward82715e12000-04-21 02:28:14 +000098 ('description', None,
99 "print the package description"),
Greg Warde5a584e2000-04-26 02:26:55 +0000100 ('long-description', None,
101 "print the long package description"),
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000102 ('platforms', None,
103 "print the list of platforms"),
Andrew M. Kuchling282e2c32003-01-03 15:24:36 +0000104 ('classifiers', None,
105 "print the list of classifiers"),
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000106 ('keywords', None,
107 "print the list of keywords"),
Fred Drakedb7b0022005-03-20 22:19:47 +0000108 ('provides', None,
109 "print the list of packages/modules provided"),
110 ('requires', None,
111 "print the list of packages/modules required"),
112 ('obsoletes', None,
113 "print the list of packages/modules made obsolete")
Greg Ward82715e12000-04-21 02:28:14 +0000114 ]
Guido van Rossumc1f779c2007-07-03 08:25:58 +0000115 display_option_names = [translate_longopt(x[0]) for x in display_options]
Greg Ward82715e12000-04-21 02:28:14 +0000116
117 # negative options are options that exclude other options
Greg Wardfe6462c2000-04-04 01:40:52 +0000118 negative_opt = {'quiet': 'verbose'}
119
Greg Wardfe6462c2000-04-04 01:40:52 +0000120 # -- Creation/initialization methods -------------------------------
Fred Drakeb94b8492001-12-06 20:51:35 +0000121
Jason R. Coombs7c456322014-07-02 08:36:19 -0400122 def __init__(self, attrs=None):
Greg Wardfe6462c2000-04-04 01:40:52 +0000123 """Construct a new Distribution instance: initialize all the
Greg Ward8ff5a3f2000-06-02 00:44:53 +0000124 attributes of a Distribution, and then use 'attrs' (a dictionary
125 mapping attribute names to values) to assign some of those
126 attributes their "real" values. (Any attributes not mentioned in
127 'attrs' will be assigned to some null value: 0, None, an empty list
128 or dictionary, etc.) Most importantly, initialize the
129 'command_obj' attribute to the empty dictionary; this will be
130 filled in with real command objects by 'parse_command_line()'.
131 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000132
133 # Default values for our command-line options
134 self.verbose = 1
135 self.dry_run = 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000136 self.help = 0
Greg Ward82715e12000-04-21 02:28:14 +0000137 for attr in self.display_option_names:
138 setattr(self, attr, 0)
Greg Wardfe6462c2000-04-04 01:40:52 +0000139
Greg Ward82715e12000-04-21 02:28:14 +0000140 # Store the distribution meta-data (name, version, author, and so
141 # forth) in a separate object -- we're getting to have enough
142 # information here (and enough command-line options) that it's
143 # worth it. Also delegate 'get_XXX()' methods to the 'metadata'
144 # object in a sneaky and underhanded (but efficient!) way.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000145 self.metadata = DistributionMetadata()
Neil Schemenauera8aefe52001-09-03 15:47:21 +0000146 for basename in self.metadata._METHOD_BASENAMES:
Greg Ward4982f982000-04-22 02:52:44 +0000147 method_name = "get_" + basename
148 setattr(self, method_name, getattr(self.metadata, method_name))
Greg Wardfe6462c2000-04-04 01:40:52 +0000149
150 # 'cmdclass' maps command names to class objects, so we
151 # can 1) quickly figure out which class to instantiate when
152 # we need to create a new command object, and 2) have a way
Greg Ward82715e12000-04-21 02:28:14 +0000153 # for the setup script to override command classes
Greg Wardfe6462c2000-04-04 01:40:52 +0000154 self.cmdclass = {}
155
Fred Draked04573f2004-08-03 16:37:40 +0000156 # 'command_packages' is a list of packages in which commands
157 # are searched for. The factory for command 'foo' is expected
158 # to be named 'foo' in the module 'foo' in one of the packages
159 # named here. This list is searched from the left; an error
160 # is raised if no named package provides the command being
161 # searched for. (Always access using get_command_packages().)
162 self.command_packages = None
163
Greg Ward9821bf42000-08-29 01:15:18 +0000164 # 'script_name' and 'script_args' are usually set to sys.argv[0]
165 # and sys.argv[1:], but they can be overridden when the caller is
166 # not necessarily a setup script run from the command-line.
167 self.script_name = None
168 self.script_args = None
169
Greg Wardd5d8a992000-05-23 01:42:17 +0000170 # 'command_options' is where we store command options between
171 # parsing them (from config files, the command-line, etc.) and when
172 # they are actually needed -- ie. when the command in question is
173 # instantiated. It is a dictionary of dictionaries of 2-tuples:
174 # command_options = { command_name : { option : (source, value) } }
Gregory P. Smith14263542000-05-12 00:41:33 +0000175 self.command_options = {}
176
Martin v. Löwis98da5622005-03-23 18:54:36 +0000177 # 'dist_files' is the list of (command, pyversion, file) that
178 # have been created by any dist commands run so far. This is
179 # filled regardless of whether the run is dry or not. pyversion
180 # gives sysconfig.get_python_version() if the dist file is
181 # specific to a Python version, 'any' if it is good for all
182 # Python versions on the target platform, and '' for a source
183 # file. pyversion should not be used to specify minimum or
184 # maximum required Python versions; use the metainfo for that
185 # instead.
Martin v. Löwis55f1bb82005-03-21 20:56:35 +0000186 self.dist_files = []
187
Greg Wardfe6462c2000-04-04 01:40:52 +0000188 # These options are really the business of various commands, rather
189 # than of the Distribution itself. We provide aliases for them in
190 # Distribution as a convenience to the developer.
Greg Wardfe6462c2000-04-04 01:40:52 +0000191 self.packages = None
Fred Drake0eb32a62004-06-11 21:50:33 +0000192 self.package_data = {}
Greg Wardfe6462c2000-04-04 01:40:52 +0000193 self.package_dir = None
194 self.py_modules = None
195 self.libraries = None
Greg Ward51def7d2000-05-27 01:36:14 +0000196 self.headers = None
Greg Wardfe6462c2000-04-04 01:40:52 +0000197 self.ext_modules = None
198 self.ext_package = None
199 self.include_dirs = None
200 self.extra_path = None
Gregory P. Smithb2e3bb32000-05-12 00:52:23 +0000201 self.scripts = None
Gregory P. Smith6a901dd2000-05-13 03:09:50 +0000202 self.data_files = None
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000203 self.password = ''
Greg Wardfe6462c2000-04-04 01:40:52 +0000204
205 # And now initialize bookkeeping stuff that can't be supplied by
206 # the caller at all. 'command_obj' maps command names to
207 # Command instances -- that's how we enforce that every command
208 # class is a singleton.
209 self.command_obj = {}
210
211 # 'have_run' maps command names to boolean values; it keeps track
212 # of whether we have actually run a particular command, to make it
213 # cheap to "run" a command whenever we think we might need to -- if
214 # it's already been done, no need for expensive filesystem
215 # operations, we just check the 'have_run' dictionary and carry on.
216 # It's only safe to query 'have_run' for a command class that has
217 # been instantiated -- a false value will be inserted when the
218 # command object is created, and replaced with a true value when
Greg Ward612eb9f2000-07-27 02:13:20 +0000219 # the command is successfully run. Thus it's probably best to use
Greg Wardfe6462c2000-04-04 01:40:52 +0000220 # '.get()' rather than a straight lookup.
221 self.have_run = {}
222
223 # Now we'll use the attrs dictionary (ultimately, keyword args from
Greg Ward82715e12000-04-21 02:28:14 +0000224 # the setup script) to possibly override any or all of these
225 # distribution options.
226
Greg Wardfe6462c2000-04-04 01:40:52 +0000227 if attrs:
Greg Wardfe6462c2000-04-04 01:40:52 +0000228 # Pull out the set of command options and work on them
229 # specifically. Note that this order guarantees that aliased
230 # command options will override any supplied redundantly
231 # through the general options dictionary.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000232 options = attrs.get('options')
Tarek Ziadé4450dcf2008-12-29 22:38:38 +0000233 if options is not None:
Greg Wardfe6462c2000-04-04 01:40:52 +0000234 del attrs['options']
235 for (command, cmd_options) in options.items():
Greg Ward0e48cfd2000-05-26 01:00:15 +0000236 opt_dict = self.get_option_dict(command)
237 for (opt, val) in cmd_options.items():
238 opt_dict[opt] = ("setup script", val)
Greg Wardfe6462c2000-04-04 01:40:52 +0000239
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000240 if 'licence' in attrs:
Andrew M. Kuchlinga52b8522003-03-03 20:07:27 +0000241 attrs['license'] = attrs['licence']
242 del attrs['licence']
243 msg = "'licence' distribution option is deprecated; use 'license'"
244 if warnings is not None:
245 warnings.warn(msg)
246 else:
247 sys.stderr.write(msg + "\n")
248
Greg Wardfe6462c2000-04-04 01:40:52 +0000249 # Now work on the rest of the attributes. Any attribute that's
250 # not already defined is invalid!
Tarek Ziadéf11be752009-06-01 22:36:26 +0000251 for (key, val) in attrs.items():
Fred Drakedb7b0022005-03-20 22:19:47 +0000252 if hasattr(self.metadata, "set_" + key):
253 getattr(self.metadata, "set_" + key)(val)
254 elif hasattr(self.metadata, key):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000255 setattr(self.metadata, key, val)
256 elif hasattr(self, key):
257 setattr(self, key, val)
Anthony Baxter73cc8472004-10-13 13:22:34 +0000258 else:
Andrew M. Kuchlingff4ad9a2002-10-31 13:22:41 +0000259 msg = "Unknown distribution option: %s" % repr(key)
260 if warnings is not None:
261 warnings.warn(msg)
262 else:
263 sys.stderr.write(msg + "\n")
Greg Wardfe6462c2000-04-04 01:40:52 +0000264
Andrew Kuchling2a1838b2013-11-10 18:11:00 -0500265 # no-user-cfg is handled before other command line args
266 # because other args override the config files, and this
267 # one is needed before we can load the config files.
268 # If attrs['script_args'] wasn't passed, assume false.
269 #
270 # This also make sure we just look at the global options
271 self.want_user_cfg = True
272
273 if self.script_args is not None:
274 for arg in self.script_args:
275 if not arg.startswith('-'):
276 break
277 if arg == '--no-user-cfg':
278 self.want_user_cfg = False
279 break
280
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000281 self.finalize_options()
Fred Drakeb94b8492001-12-06 20:51:35 +0000282
Tarek Ziadé188789d2009-05-16 18:37:32 +0000283 def get_option_dict(self, command):
Greg Ward0e48cfd2000-05-26 01:00:15 +0000284 """Get the option dictionary for a given command. If that
285 command's option dictionary hasn't been created yet, then create it
286 and return the new dictionary; otherwise, return the existing
287 option dictionary.
288 """
Greg Ward0e48cfd2000-05-26 01:00:15 +0000289 dict = self.command_options.get(command)
290 if dict is None:
291 dict = self.command_options[command] = {}
292 return dict
293
Tarek Ziadé188789d2009-05-16 18:37:32 +0000294 def dump_option_dicts(self, header=None, commands=None, indent=""):
Greg Wardc32d9a62000-05-28 23:53:06 +0000295 from pprint import pformat
296
297 if commands is None: # dump all command option dicts
Guido van Rossumd4ee1672007-10-15 01:27:53 +0000298 commands = sorted(self.command_options.keys())
Greg Wardc32d9a62000-05-28 23:53:06 +0000299
300 if header is not None:
Tarek Ziadéf11be752009-06-01 22:36:26 +0000301 self.announce(indent + header)
Greg Wardc32d9a62000-05-28 23:53:06 +0000302 indent = indent + " "
303
304 if not commands:
Tarek Ziadéf11be752009-06-01 22:36:26 +0000305 self.announce(indent + "no commands known yet")
Greg Wardc32d9a62000-05-28 23:53:06 +0000306 return
307
308 for cmd_name in commands:
309 opt_dict = self.command_options.get(cmd_name)
310 if opt_dict is None:
Tarek Ziadéf11be752009-06-01 22:36:26 +0000311 self.announce(indent +
312 "no option dict for '%s' command" % cmd_name)
Greg Wardc32d9a62000-05-28 23:53:06 +0000313 else:
Tarek Ziadéf11be752009-06-01 22:36:26 +0000314 self.announce(indent +
315 "option dict for '%s' command:" % cmd_name)
Greg Wardc32d9a62000-05-28 23:53:06 +0000316 out = pformat(opt_dict)
Tarek Ziadéf11be752009-06-01 22:36:26 +0000317 for line in out.split('\n'):
318 self.announce(indent + " " + line)
Greg Wardc32d9a62000-05-28 23:53:06 +0000319
Greg Wardd5d8a992000-05-23 01:42:17 +0000320 # -- Config file finding/parsing methods ---------------------------
321
Tarek Ziadé188789d2009-05-16 18:37:32 +0000322 def find_config_files(self):
Gregory P. Smith14263542000-05-12 00:41:33 +0000323 """Find as many configuration files as should be processed for this
324 platform, and return a list of filenames in the order in which they
325 should be parsed. The filenames returned are guaranteed to exist
326 (modulo nasty race conditions).
327
Andrew M. Kuchlingd303b612001-12-06 16:32:05 +0000328 There are three possible config files: distutils.cfg in the
329 Distutils installation directory (ie. where the top-level
330 Distutils __inst__.py file lives), a file in the user's home
331 directory named .pydistutils.cfg on Unix and pydistutils.cfg
Andrew Kuchling2a1838b2013-11-10 18:11:00 -0500332 on Windows/Mac; and setup.cfg in the current directory.
333
334 The file in the user's home directory can be disabled with the
335 --no-user-cfg option.
Greg Wardd5d8a992000-05-23 01:42:17 +0000336 """
Gregory P. Smith14263542000-05-12 00:41:33 +0000337 files = []
Greg Wardacf3f6a2000-06-07 02:26:19 +0000338 check_environ()
Gregory P. Smith14263542000-05-12 00:41:33 +0000339
Greg Ward11696872000-06-07 02:29:03 +0000340 # Where to look for the system-wide Distutils config file
341 sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
342
343 # Look for the system config file
344 sys_file = os.path.join(sys_dir, "distutils.cfg")
Greg Wardacf3f6a2000-06-07 02:26:19 +0000345 if os.path.isfile(sys_file):
346 files.append(sys_file)
Gregory P. Smith14263542000-05-12 00:41:33 +0000347
Greg Ward11696872000-06-07 02:29:03 +0000348 # What to call the per-user config file
349 if os.name == 'posix':
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000350 user_filename = ".pydistutils.cfg"
351 else:
352 user_filename = "pydistutils.cfg"
Greg Wardfa9ff762000-10-14 04:06:40 +0000353
Greg Ward11696872000-06-07 02:29:03 +0000354 # And look for the user config file
Andrew Kuchling2a1838b2013-11-10 18:11:00 -0500355 if self.want_user_cfg:
356 user_file = os.path.join(os.path.expanduser('~'), user_filename)
357 if os.path.isfile(user_file):
358 files.append(user_file)
Gregory P. Smith14263542000-05-12 00:41:33 +0000359
Gregory P. Smith14263542000-05-12 00:41:33 +0000360 # All platforms support local setup.cfg
361 local_file = "setup.cfg"
362 if os.path.isfile(local_file):
363 files.append(local_file)
364
Andrew Kuchling2a1838b2013-11-10 18:11:00 -0500365 if DEBUG:
366 self.announce("using config files: %s" % ', '.join(files))
367
Gregory P. Smith14263542000-05-12 00:41:33 +0000368 return files
369
Tarek Ziadé188789d2009-05-16 18:37:32 +0000370 def parse_config_files(self, filenames=None):
Alexandre Vassalotti1d1eaa42008-05-14 22:59:42 +0000371 from configparser import ConfigParser
Gregory P. Smith14263542000-05-12 00:41:33 +0000372
Georg Brandl521ed522013-05-12 12:36:07 +0200373 # Ignore install directory options if we have a venv
374 if sys.prefix != sys.base_prefix:
375 ignore_options = [
376 'install-base', 'install-platbase', 'install-lib',
377 'install-platlib', 'install-purelib', 'install-headers',
378 'install-scripts', 'install-data', 'prefix', 'exec-prefix',
379 'home', 'user', 'root']
380 else:
381 ignore_options = []
382
383 ignore_options = frozenset(ignore_options)
384
Gregory P. Smith14263542000-05-12 00:41:33 +0000385 if filenames is None:
386 filenames = self.find_config_files()
387
Tarek Ziadéf11be752009-06-01 22:36:26 +0000388 if DEBUG:
389 self.announce("Distribution.parse_config_files():")
Greg Ward47460772000-05-23 03:47:35 +0000390
Gregory P. Smith14263542000-05-12 00:41:33 +0000391 parser = ConfigParser()
Greg Wardd5d8a992000-05-23 01:42:17 +0000392 for filename in filenames:
Tarek Ziadéf11be752009-06-01 22:36:26 +0000393 if DEBUG:
Tarek Ziadé31d46072009-09-21 13:55:19 +0000394 self.announce(" reading %s" % filename)
Greg Wardd5d8a992000-05-23 01:42:17 +0000395 parser.read(filename)
396 for section in parser.sections():
397 options = parser.options(section)
Greg Ward0e48cfd2000-05-26 01:00:15 +0000398 opt_dict = self.get_option_dict(section)
Gregory P. Smith14263542000-05-12 00:41:33 +0000399
Greg Wardd5d8a992000-05-23 01:42:17 +0000400 for opt in options:
Georg Brandl521ed522013-05-12 12:36:07 +0200401 if opt != '__name__' and opt not in ignore_options:
Greg Wardceb9e222000-09-25 01:23:52 +0000402 val = parser.get(section,opt)
Neal Norwitz9d72bb42007-04-17 08:48:32 +0000403 opt = opt.replace('-', '_')
Greg Wardceb9e222000-09-25 01:23:52 +0000404 opt_dict[opt] = (filename, val)
Gregory P. Smith14263542000-05-12 00:41:33 +0000405
Greg Ward47460772000-05-23 03:47:35 +0000406 # Make the ConfigParser forget everything (so we retain
Fred Drakef06116d2004-02-17 22:35:19 +0000407 # the original filenames that options come from)
Greg Ward47460772000-05-23 03:47:35 +0000408 parser.__init__()
Gregory P. Smith14263542000-05-12 00:41:33 +0000409
Greg Wardceb9e222000-09-25 01:23:52 +0000410 # If there was a "global" section in the config file, use it
411 # to set Distribution options.
412
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000413 if 'global' in self.command_options:
Greg Wardceb9e222000-09-25 01:23:52 +0000414 for (opt, (src, val)) in self.command_options['global'].items():
415 alias = self.negative_opt.get(opt)
416 try:
417 if alias:
418 setattr(self, alias, not strtobool(val))
419 elif opt in ('verbose', 'dry_run'): # ugh!
420 setattr(self, opt, strtobool(val))
Fred Draked04573f2004-08-03 16:37:40 +0000421 else:
422 setattr(self, opt, val)
Guido van Rossumb940e112007-01-10 16:19:56 +0000423 except ValueError as msg:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000424 raise DistutilsOptionError(msg)
Greg Wardceb9e222000-09-25 01:23:52 +0000425
Greg Wardd5d8a992000-05-23 01:42:17 +0000426 # -- Command-line parsing methods ----------------------------------
427
Tarek Ziadé188789d2009-05-16 18:37:32 +0000428 def parse_command_line(self):
Greg Ward9821bf42000-08-29 01:15:18 +0000429 """Parse the setup script's command line, taken from the
430 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
431 -- see 'setup()' in core.py). This list is first processed for
432 "global options" -- options that set attributes of the Distribution
433 instance. Then, it is alternately scanned for Distutils commands
434 and options for that command. Each new command terminates the
435 options for the previous command. The allowed options for a
436 command are determined by the 'user_options' attribute of the
437 command class -- thus, we have to be able to load command classes
438 in order to parse the command line. Any error in that 'options'
439 attribute raises DistutilsGetoptError; any error on the
440 command-line raises DistutilsArgError. If no Distutils commands
441 were found on the command line, raises DistutilsArgError. Return
Greg Wardceb9e222000-09-25 01:23:52 +0000442 true if command-line was successfully parsed and we should carry
Greg Ward9821bf42000-08-29 01:15:18 +0000443 on with executing commands; false if no errors but we shouldn't
444 execute commands (currently, this only happens if user asks for
445 help).
Greg Wardd5d8a992000-05-23 01:42:17 +0000446 """
Andrew M. Kuchling3f819ec2001-01-15 16:09:35 +0000447 #
Fred Drake981a1782001-08-10 18:59:30 +0000448 # We now have enough information to show the Macintosh dialog
449 # that allows the user to interactively specify the "command line".
Andrew M. Kuchling3f819ec2001-01-15 16:09:35 +0000450 #
Fred Draked04573f2004-08-03 16:37:40 +0000451 toplevel_options = self._get_toplevel_options()
Fred Drakeb94b8492001-12-06 20:51:35 +0000452
Greg Wardfe6462c2000-04-04 01:40:52 +0000453 # We have to parse the command line a bit at a time -- global
454 # options, then the first command, then its options, and so on --
455 # because each command will be handled by a different class, and
Greg Wardd5d8a992000-05-23 01:42:17 +0000456 # the options that are valid for a particular class aren't known
457 # until we have loaded the command class, which doesn't happen
458 # until we know what the command is.
Greg Wardfe6462c2000-04-04 01:40:52 +0000459
460 self.commands = []
Fred Draked04573f2004-08-03 16:37:40 +0000461 parser = FancyGetopt(toplevel_options + self.display_options)
Greg Wardfd7b91e2000-09-26 01:52:25 +0000462 parser.set_negative_aliases(self.negative_opt)
Andrew M. Kuchlingfa7dc572001-08-10 18:49:23 +0000463 parser.set_aliases({'licence': 'license'})
Greg Wardfd7b91e2000-09-26 01:52:25 +0000464 args = parser.getopt(args=self.script_args, object=self)
Greg Ward82715e12000-04-21 02:28:14 +0000465 option_order = parser.get_option_order()
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000466 log.set_verbosity(self.verbose)
Greg Wardfe6462c2000-04-04 01:40:52 +0000467
Greg Ward82715e12000-04-21 02:28:14 +0000468 # for display options we return immediately
469 if self.handle_display_options(option_order):
Greg Wardfe6462c2000-04-04 01:40:52 +0000470 return
Greg Wardfe6462c2000-04-04 01:40:52 +0000471 while args:
Greg Wardd5d8a992000-05-23 01:42:17 +0000472 args = self._parse_command_opts(parser, args)
473 if args is None: # user asked for help (and got it)
Greg Wardfe6462c2000-04-04 01:40:52 +0000474 return
Greg Wardfe6462c2000-04-04 01:40:52 +0000475
Greg Wardd5d8a992000-05-23 01:42:17 +0000476 # Handle the cases of --help as a "global" option, ie.
477 # "setup.py --help" and "setup.py --help command ...". For the
478 # former, we show global options (--verbose, --dry-run, etc.)
479 # and display-only options (--name, --version, etc.); for the
480 # latter, we omit the display-only options and show help for
481 # each command listed on the command line.
Greg Wardfe6462c2000-04-04 01:40:52 +0000482 if self.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000483 self._show_help(parser,
484 display_options=len(self.commands) == 0,
485 commands=self.commands)
Greg Wardfe6462c2000-04-04 01:40:52 +0000486 return
487
488 # Oops, no commands found -- an end-user error
489 if not self.commands:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000490 raise DistutilsArgError("no commands supplied")
Greg Wardfe6462c2000-04-04 01:40:52 +0000491
492 # All is well: return true
Collin Winter5b7e9d72007-08-30 03:52:21 +0000493 return True
Greg Wardfe6462c2000-04-04 01:40:52 +0000494
Tarek Ziadé188789d2009-05-16 18:37:32 +0000495 def _get_toplevel_options(self):
Fred Draked04573f2004-08-03 16:37:40 +0000496 """Return the non-display options recognized at the top level.
497
498 This includes options that are recognized *only* at the top
499 level as well as options recognized for commands.
500 """
501 return self.global_options + [
502 ("command-packages=", None,
503 "list of packages that provide distutils commands"),
504 ]
505
Tarek Ziadé188789d2009-05-16 18:37:32 +0000506 def _parse_command_opts(self, parser, args):
Greg Wardd5d8a992000-05-23 01:42:17 +0000507 """Parse the command-line options for a single command.
508 'parser' must be a FancyGetopt instance; 'args' must be the list
509 of arguments, starting with the current command (whose options
510 we are about to parse). Returns a new version of 'args' with
511 the next command at the front of the list; will be the empty
512 list if there are no more commands on the command line. Returns
513 None if the user asked for help on this command.
514 """
515 # late import because of mutual dependence between these modules
516 from distutils.cmd import Command
517
518 # Pull the current command from the head of the command line
519 command = args[0]
Greg Wardfd7b91e2000-09-26 01:52:25 +0000520 if not command_re.match(command):
Collin Winter5b7e9d72007-08-30 03:52:21 +0000521 raise SystemExit("invalid command name '%s'" % command)
Greg Wardfd7b91e2000-09-26 01:52:25 +0000522 self.commands.append(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000523
524 # Dig up the command class that implements this command, so we
525 # 1) know that it's a valid command, and 2) know which options
526 # it takes.
527 try:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000528 cmd_class = self.get_command_class(command)
Guido van Rossumb940e112007-01-10 16:19:56 +0000529 except DistutilsModuleError as msg:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000530 raise DistutilsArgError(msg)
Greg Wardd5d8a992000-05-23 01:42:17 +0000531
532 # Require that the command class be derived from Command -- want
533 # to be sure that the basic "command" interface is implemented.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000534 if not issubclass(cmd_class, Command):
Collin Winter5b7e9d72007-08-30 03:52:21 +0000535 raise DistutilsClassError(
Jason R. Coombs7c456322014-07-02 08:36:19 -0400536 "command class %s must subclass Command" % cmd_class)
Greg Wardd5d8a992000-05-23 01:42:17 +0000537
538 # Also make sure that the command object provides a list of its
539 # known options.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000540 if not (hasattr(cmd_class, 'user_options') and
Guido van Rossum13257902007-06-07 23:15:56 +0000541 isinstance(cmd_class.user_options, list)):
Jason R. Coombs7c456322014-07-02 08:36:19 -0400542 msg = ("command class %s must provide "
543 "'user_options' attribute (a list of tuples)")
544 raise DistutilsClassError(msg % cmd_class)
Greg Wardd5d8a992000-05-23 01:42:17 +0000545
546 # If the command class has a list of negative alias options,
547 # merge it in with the global negative aliases.
548 negative_opt = self.negative_opt
Greg Wardfd7b91e2000-09-26 01:52:25 +0000549 if hasattr(cmd_class, 'negative_opt'):
Antoine Pitrou56a00de2009-05-15 17:34:21 +0000550 negative_opt = negative_opt.copy()
Greg Wardfd7b91e2000-09-26 01:52:25 +0000551 negative_opt.update(cmd_class.negative_opt)
Greg Wardd5d8a992000-05-23 01:42:17 +0000552
Greg Wardfa9ff762000-10-14 04:06:40 +0000553 # Check for help_options in command class. They have a different
554 # format (tuple of four) so we need to preprocess them here.
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000555 if (hasattr(cmd_class, 'help_options') and
Jason R. Coombs7c456322014-07-02 08:36:19 -0400556 isinstance(cmd_class.help_options, list)):
Greg Ward2ff78872000-06-24 00:23:20 +0000557 help_options = fix_help_options(cmd_class.help_options)
558 else:
Greg Ward55fced32000-06-24 01:22:41 +0000559 help_options = []
Greg Ward2ff78872000-06-24 00:23:20 +0000560
Greg Wardd5d8a992000-05-23 01:42:17 +0000561 # All commands support the global options too, just by adding
562 # in 'global_options'.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000563 parser.set_option_table(self.global_options +
564 cmd_class.user_options +
565 help_options)
566 parser.set_negative_aliases(negative_opt)
567 (args, opts) = parser.getopt(args[1:])
Greg Ward47460772000-05-23 03:47:35 +0000568 if hasattr(opts, 'help') and opts.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000569 self._show_help(parser, display_options=0, commands=[cmd_class])
570 return
571
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000572 if (hasattr(cmd_class, 'help_options') and
Jason R. Coombs7c456322014-07-02 08:36:19 -0400573 isinstance(cmd_class.help_options, list)):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000574 help_option_found=0
575 for (help_option, short, desc, func) in cmd_class.help_options:
576 if hasattr(opts, parser.get_attr_name(help_option)):
577 help_option_found=1
Florent Xicluna5d1155c2011-10-28 14:45:05 +0200578 if callable(func):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000579 func()
Greg Ward55fced32000-06-24 01:22:41 +0000580 else:
Fred Drake981a1782001-08-10 18:59:30 +0000581 raise DistutilsClassError(
Walter Dörwald70a6b492004-02-12 17:35:32 +0000582 "invalid help function %r for help option '%s': "
Fred Drake981a1782001-08-10 18:59:30 +0000583 "must be a callable object (function, etc.)"
Walter Dörwald70a6b492004-02-12 17:35:32 +0000584 % (func, help_option))
Greg Ward55fced32000-06-24 01:22:41 +0000585
Fred Drakeb94b8492001-12-06 20:51:35 +0000586 if help_option_found:
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000587 return
Greg Ward9d17a7a2000-06-07 03:00:06 +0000588
Greg Wardd5d8a992000-05-23 01:42:17 +0000589 # Put the options from the command-line into their official
590 # holding pen, the 'command_options' dictionary.
Greg Ward0e48cfd2000-05-26 01:00:15 +0000591 opt_dict = self.get_option_dict(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000592 for (name, value) in vars(opts).items():
Greg Ward0e48cfd2000-05-26 01:00:15 +0000593 opt_dict[name] = ("command line", value)
Greg Wardd5d8a992000-05-23 01:42:17 +0000594
595 return args
596
Tarek Ziadé188789d2009-05-16 18:37:32 +0000597 def finalize_options(self):
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000598 """Set final values for all the options on the Distribution
599 instance, analogous to the .finalize_options() method of Command
600 objects.
601 """
Tarek Ziadéf11be752009-06-01 22:36:26 +0000602 for attr in ('keywords', 'platforms'):
603 value = getattr(self.metadata, attr)
604 if value is None:
605 continue
606 if isinstance(value, str):
607 value = [elm.strip() for elm in value.split(',')]
608 setattr(self.metadata, attr, value)
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000609
Tarek Ziadé188789d2009-05-16 18:37:32 +0000610 def _show_help(self, parser, global_options=1, display_options=1,
611 commands=[]):
Greg Wardd5d8a992000-05-23 01:42:17 +0000612 """Show help for the setup script command-line in the form of
613 several lists of command-line options. 'parser' should be a
614 FancyGetopt instance; do not expect it to be returned in the
615 same state, as its option table will be reset to make it
616 generate the correct help text.
617
618 If 'global_options' is true, lists the global options:
619 --verbose, --dry-run, etc. If 'display_options' is true, lists
620 the "display-only" options: --name, --version, etc. Finally,
621 lists per-command help for every command name or command class
622 in 'commands'.
623 """
624 # late import because of mutual dependence between these modules
Greg Ward9821bf42000-08-29 01:15:18 +0000625 from distutils.core import gen_usage
Greg Wardd5d8a992000-05-23 01:42:17 +0000626 from distutils.cmd import Command
627
628 if global_options:
Fred Draked04573f2004-08-03 16:37:40 +0000629 if display_options:
630 options = self._get_toplevel_options()
631 else:
632 options = self.global_options
633 parser.set_option_table(options)
Martin v. Löwis8ed338a2005-03-03 08:12:27 +0000634 parser.print_help(self.common_usage + "\nGlobal options:")
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000635 print('')
Greg Wardd5d8a992000-05-23 01:42:17 +0000636
637 if display_options:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000638 parser.set_option_table(self.display_options)
639 parser.print_help(
Greg Wardd5d8a992000-05-23 01:42:17 +0000640 "Information display options (just display " +
641 "information, ignore any commands)")
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000642 print('')
Greg Wardd5d8a992000-05-23 01:42:17 +0000643
644 for command in self.commands:
Guido van Rossum13257902007-06-07 23:15:56 +0000645 if isinstance(command, type) and issubclass(command, Command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000646 klass = command
647 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000648 klass = self.get_command_class(command)
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000649 if (hasattr(klass, 'help_options') and
Jason R. Coombs7c456322014-07-02 08:36:19 -0400650 isinstance(klass.help_options, list)):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000651 parser.set_option_table(klass.user_options +
652 fix_help_options(klass.help_options))
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000653 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000654 parser.set_option_table(klass.user_options)
655 parser.print_help("Options for '%s' command:" % klass.__name__)
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000656 print('')
Greg Wardd5d8a992000-05-23 01:42:17 +0000657
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000658 print(gen_usage(self.script_name))
Greg Wardd5d8a992000-05-23 01:42:17 +0000659
Tarek Ziadé188789d2009-05-16 18:37:32 +0000660 def handle_display_options(self, option_order):
Greg Ward82715e12000-04-21 02:28:14 +0000661 """If there were any non-global "display-only" options
Greg Wardd5d8a992000-05-23 01:42:17 +0000662 (--help-commands or the metadata display options) on the command
663 line, display the requested info and return true; else return
664 false.
665 """
Greg Ward9821bf42000-08-29 01:15:18 +0000666 from distutils.core import gen_usage
Greg Ward82715e12000-04-21 02:28:14 +0000667
668 # User just wants a list of commands -- we'll print it out and stop
669 # processing now (ie. if they ran "setup --help-commands foo bar",
670 # we ignore "foo bar").
671 if self.help_commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000672 self.print_commands()
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000673 print('')
674 print(gen_usage(self.script_name))
Greg Ward82715e12000-04-21 02:28:14 +0000675 return 1
676
677 # If user supplied any of the "display metadata" options, then
678 # display that metadata in the order in which the user supplied the
679 # metadata options.
680 any_display_options = 0
681 is_display_option = {}
682 for option in self.display_options:
683 is_display_option[option[0]] = 1
684
685 for (opt, val) in option_order:
686 if val and is_display_option.get(opt):
Greg Ward2f2b6c62000-09-25 01:58:07 +0000687 opt = translate_longopt(opt)
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000688 value = getattr(self.metadata, "get_"+opt)()
689 if opt in ['keywords', 'platforms']:
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000690 print(','.join(value))
Fred Drakedb7b0022005-03-20 22:19:47 +0000691 elif opt in ('classifiers', 'provides', 'requires',
692 'obsoletes'):
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000693 print('\n'.join(value))
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +0000694 else:
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000695 print(value)
Greg Ward82715e12000-04-21 02:28:14 +0000696 any_display_options = 1
697
698 return any_display_options
699
Tarek Ziadé188789d2009-05-16 18:37:32 +0000700 def print_command_list(self, commands, header, max_length):
Greg Wardfe6462c2000-04-04 01:40:52 +0000701 """Print a subset of the list of all commands -- used by
Greg Wardd5d8a992000-05-23 01:42:17 +0000702 'print_commands()'.
703 """
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000704 print(header + ":")
Greg Wardfe6462c2000-04-04 01:40:52 +0000705
706 for cmd in commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000707 klass = self.cmdclass.get(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000708 if not klass:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000709 klass = self.get_command_class(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000710 try:
711 description = klass.description
712 except AttributeError:
713 description = "(no description available)"
714
Tarek Ziadé0d3fa832009-07-04 03:00:50 +0000715 print(" %-*s %s" % (max_length, cmd, description))
Greg Wardfe6462c2000-04-04 01:40:52 +0000716
Tarek Ziadé188789d2009-05-16 18:37:32 +0000717 def print_commands(self):
Greg Wardd5d8a992000-05-23 01:42:17 +0000718 """Print out a help message listing all available commands with a
719 description of each. The list is divided into "standard commands"
720 (listed in distutils.command.__all__) and "extra commands"
721 (mentioned in self.cmdclass, but not a standard command). The
722 descriptions come from the command class attribute
723 'description'.
724 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000725 import distutils.command
726 std_commands = distutils.command.__all__
727 is_std = {}
728 for cmd in std_commands:
729 is_std[cmd] = 1
730
731 extra_commands = []
732 for cmd in self.cmdclass.keys():
733 if not is_std.get(cmd):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000734 extra_commands.append(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000735
736 max_length = 0
737 for cmd in (std_commands + extra_commands):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000738 if len(cmd) > max_length:
739 max_length = len(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000740
Greg Wardfd7b91e2000-09-26 01:52:25 +0000741 self.print_command_list(std_commands,
742 "Standard commands",
743 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000744 if extra_commands:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000745 print()
Greg Wardfd7b91e2000-09-26 01:52:25 +0000746 self.print_command_list(extra_commands,
747 "Extra commands",
748 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000749
Tarek Ziadé188789d2009-05-16 18:37:32 +0000750 def get_command_list(self):
Greg Wardf6fc8752000-11-11 02:47:11 +0000751 """Get a list of (command, description) tuples.
752 The list is divided into "standard commands" (listed in
753 distutils.command.__all__) and "extra commands" (mentioned in
754 self.cmdclass, but not a standard command). The descriptions come
755 from the command class attribute 'description'.
756 """
757 # Currently this is only used on Mac OS, for the Mac-only GUI
758 # Distutils interface (by Jack Jansen)
Greg Wardf6fc8752000-11-11 02:47:11 +0000759 import distutils.command
760 std_commands = distutils.command.__all__
761 is_std = {}
762 for cmd in std_commands:
763 is_std[cmd] = 1
764
765 extra_commands = []
766 for cmd in self.cmdclass.keys():
767 if not is_std.get(cmd):
768 extra_commands.append(cmd)
769
770 rv = []
771 for cmd in (std_commands + extra_commands):
772 klass = self.cmdclass.get(cmd)
773 if not klass:
774 klass = self.get_command_class(cmd)
775 try:
776 description = klass.description
777 except AttributeError:
778 description = "(no description available)"
779 rv.append((cmd, description))
780 return rv
Greg Wardfe6462c2000-04-04 01:40:52 +0000781
782 # -- Command class/object methods ----------------------------------
783
Tarek Ziadé188789d2009-05-16 18:37:32 +0000784 def get_command_packages(self):
Fred Draked04573f2004-08-03 16:37:40 +0000785 """Return a list of packages from which commands are loaded."""
786 pkgs = self.command_packages
Tarek Ziadéf11be752009-06-01 22:36:26 +0000787 if not isinstance(pkgs, list):
788 if pkgs is None:
789 pkgs = ''
790 pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
Fred Draked04573f2004-08-03 16:37:40 +0000791 if "distutils.command" not in pkgs:
792 pkgs.insert(0, "distutils.command")
793 self.command_packages = pkgs
794 return pkgs
795
Tarek Ziadé188789d2009-05-16 18:37:32 +0000796 def get_command_class(self, command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000797 """Return the class that implements the Distutils command named by
798 'command'. First we check the 'cmdclass' dictionary; if the
799 command is mentioned there, we fetch the class object from the
800 dictionary and return it. Otherwise we load the command module
801 ("distutils.command." + command) and fetch the command class from
802 the module. The loaded class is also stored in 'cmdclass'
803 to speed future calls to 'get_command_class()'.
Greg Wardfe6462c2000-04-04 01:40:52 +0000804
Gregory P. Smith14263542000-05-12 00:41:33 +0000805 Raises DistutilsModuleError if the expected module could not be
Greg Wardd5d8a992000-05-23 01:42:17 +0000806 found, or if that module does not define the expected class.
807 """
808 klass = self.cmdclass.get(command)
809 if klass:
810 return klass
Greg Wardfe6462c2000-04-04 01:40:52 +0000811
Fred Draked04573f2004-08-03 16:37:40 +0000812 for pkgname in self.get_command_packages():
813 module_name = "%s.%s" % (pkgname, command)
814 klass_name = command
Greg Wardfe6462c2000-04-04 01:40:52 +0000815
Fred Draked04573f2004-08-03 16:37:40 +0000816 try:
Jason R. Coombs7c456322014-07-02 08:36:19 -0400817 __import__(module_name)
Fred Draked04573f2004-08-03 16:37:40 +0000818 module = sys.modules[module_name]
819 except ImportError:
820 continue
Greg Wardfe6462c2000-04-04 01:40:52 +0000821
Fred Draked04573f2004-08-03 16:37:40 +0000822 try:
823 klass = getattr(module, klass_name)
824 except AttributeError:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000825 raise DistutilsModuleError(
Jason R. Coombs7c456322014-07-02 08:36:19 -0400826 "invalid command '%s' (no class '%s' in module '%s')"
827 % (command, klass_name, module_name))
Greg Wardfe6462c2000-04-04 01:40:52 +0000828
Fred Draked04573f2004-08-03 16:37:40 +0000829 self.cmdclass[command] = klass
830 return klass
831
832 raise DistutilsModuleError("invalid command '%s'" % command)
833
Tarek Ziadé188789d2009-05-16 18:37:32 +0000834 def get_command_obj(self, command, create=1):
Greg Wardd5d8a992000-05-23 01:42:17 +0000835 """Return the command object for 'command'. Normally this object
Greg Ward612eb9f2000-07-27 02:13:20 +0000836 is cached on a previous call to 'get_command_obj()'; if no command
Greg Wardd5d8a992000-05-23 01:42:17 +0000837 object for 'command' is in the cache, then we either create and
838 return it (if 'create' is true) or return None.
839 """
840 cmd_obj = self.command_obj.get(command)
Greg Wardfe6462c2000-04-04 01:40:52 +0000841 if not cmd_obj and create:
Greg Ward2bd3f422000-06-02 01:59:33 +0000842 if DEBUG:
Jason R. Coombs7c456322014-07-02 08:36:19 -0400843 self.announce("Distribution.get_command_obj(): "
Tarek Ziadéf11be752009-06-01 22:36:26 +0000844 "creating '%s' command object" % command)
Greg Ward47460772000-05-23 03:47:35 +0000845
Greg Wardd5d8a992000-05-23 01:42:17 +0000846 klass = self.get_command_class(command)
Greg Ward47460772000-05-23 03:47:35 +0000847 cmd_obj = self.command_obj[command] = klass(self)
848 self.have_run[command] = 0
849
850 # Set any options that were supplied in config files
851 # or on the command line. (NB. support for error
852 # reporting is lame here: any errors aren't reported
853 # until 'finalize_options()' is called, which means
854 # we won't report the source of the error.)
855 options = self.command_options.get(command)
856 if options:
Greg Wardc32d9a62000-05-28 23:53:06 +0000857 self._set_command_options(cmd_obj, options)
Greg Wardfe6462c2000-04-04 01:40:52 +0000858
859 return cmd_obj
860
Tarek Ziadé188789d2009-05-16 18:37:32 +0000861 def _set_command_options(self, command_obj, option_dict=None):
Greg Wardc32d9a62000-05-28 23:53:06 +0000862 """Set the options for 'command_obj' from 'option_dict'. Basically
863 this means copying elements of a dictionary ('option_dict') to
864 attributes of an instance ('command').
865
Greg Wardceb9e222000-09-25 01:23:52 +0000866 'command_obj' must be a Command instance. If 'option_dict' is not
Greg Wardc32d9a62000-05-28 23:53:06 +0000867 supplied, uses the standard option dictionary for this command
868 (from 'self.command_options').
869 """
Greg Wardc32d9a62000-05-28 23:53:06 +0000870 command_name = command_obj.get_command_name()
871 if option_dict is None:
872 option_dict = self.get_option_dict(command_name)
873
Tarek Ziadéf11be752009-06-01 22:36:26 +0000874 if DEBUG:
875 self.announce(" setting options for '%s' command:" % command_name)
Greg Wardc32d9a62000-05-28 23:53:06 +0000876 for (option, (source, value)) in option_dict.items():
Tarek Ziadéf11be752009-06-01 22:36:26 +0000877 if DEBUG:
878 self.announce(" %s = %s (from %s)" % (option, value,
879 source))
Greg Wardceb9e222000-09-25 01:23:52 +0000880 try:
Amaury Forgeot d'Arc61cb0872008-07-26 20:09:45 +0000881 bool_opts = [translate_longopt(o)
882 for o in command_obj.boolean_options]
Greg Wardceb9e222000-09-25 01:23:52 +0000883 except AttributeError:
884 bool_opts = []
885 try:
886 neg_opt = command_obj.negative_opt
887 except AttributeError:
888 neg_opt = {}
889
890 try:
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000891 is_string = isinstance(value, str)
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000892 if option in neg_opt and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000893 setattr(command_obj, neg_opt[option], not strtobool(value))
Greg Ward2c08cf02000-09-27 00:15:37 +0000894 elif option in bool_opts and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000895 setattr(command_obj, option, strtobool(value))
896 elif hasattr(command_obj, option):
897 setattr(command_obj, option, value)
898 else:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000899 raise DistutilsOptionError(
Jason R. Coombs7c456322014-07-02 08:36:19 -0400900 "error in %s: command '%s' has no such option '%s'"
901 % (source, command_name, option))
Guido van Rossumb940e112007-01-10 16:19:56 +0000902 except ValueError as msg:
Collin Winter5b7e9d72007-08-30 03:52:21 +0000903 raise DistutilsOptionError(msg)
Greg Wardc32d9a62000-05-28 23:53:06 +0000904
Tarek Ziadé188789d2009-05-16 18:37:32 +0000905 def reinitialize_command(self, command, reinit_subcommands=0):
Greg Wardc32d9a62000-05-28 23:53:06 +0000906 """Reinitializes a command to the state it was in when first
907 returned by 'get_command_obj()': ie., initialized but not yet
Greg Ward7d9c7052000-06-28 01:25:27 +0000908 finalized. This provides the opportunity to sneak option
Greg Wardc32d9a62000-05-28 23:53:06 +0000909 values in programmatically, overriding or supplementing
910 user-supplied values from the config files and command line.
911 You'll have to re-finalize the command object (by calling
912 'finalize_options()' or 'ensure_finalized()') before using it for
Fred Drakeb94b8492001-12-06 20:51:35 +0000913 real.
Greg Wardc32d9a62000-05-28 23:53:06 +0000914
Greg Wardf449ea52000-09-16 15:23:28 +0000915 'command' should be a command name (string) or command object. If
916 'reinit_subcommands' is true, also reinitializes the command's
917 sub-commands, as declared by the 'sub_commands' class attribute (if
918 it has one). See the "install" command for an example. Only
919 reinitializes the sub-commands that actually matter, ie. those
920 whose test predicates return true.
921
Greg Wardc32d9a62000-05-28 23:53:06 +0000922 Returns the reinitialized command object.
923 """
924 from distutils.cmd import Command
925 if not isinstance(command, Command):
926 command_name = command
927 command = self.get_command_obj(command_name)
928 else:
929 command_name = command.get_command_name()
930
931 if not command.finalized:
Greg Ward282c7a02000-06-01 01:09:47 +0000932 return command
Greg Wardc32d9a62000-05-28 23:53:06 +0000933 command.initialize_options()
934 command.finalized = 0
Greg Ward43955c92000-06-06 02:52:36 +0000935 self.have_run[command_name] = 0
Greg Wardc32d9a62000-05-28 23:53:06 +0000936 self._set_command_options(command)
Greg Wardf449ea52000-09-16 15:23:28 +0000937
Greg Wardf449ea52000-09-16 15:23:28 +0000938 if reinit_subcommands:
Greg Wardf449ea52000-09-16 15:23:28 +0000939 for sub in command.get_sub_commands():
Fred Drakeb94b8492001-12-06 20:51:35 +0000940 self.reinitialize_command(sub, reinit_subcommands)
Greg Wardf449ea52000-09-16 15:23:28 +0000941
Greg Wardc32d9a62000-05-28 23:53:06 +0000942 return command
943
Greg Wardfe6462c2000-04-04 01:40:52 +0000944 # -- Methods that operate on the Distribution ----------------------
945
Tarek Ziadé05bf01a2009-07-04 02:04:21 +0000946 def announce(self, msg, level=log.INFO):
947 log.log(level, msg)
Greg Wardfe6462c2000-04-04 01:40:52 +0000948
Tarek Ziadé188789d2009-05-16 18:37:32 +0000949 def run_commands(self):
Greg Ward82715e12000-04-21 02:28:14 +0000950 """Run each command that was seen on the setup script command line.
Greg Wardd5d8a992000-05-23 01:42:17 +0000951 Uses the list of commands found and cache of command objects
Greg Wardfd7b91e2000-09-26 01:52:25 +0000952 created by 'get_command_obj()'.
953 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000954 for cmd in self.commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000955 self.run_command(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000956
Greg Wardfe6462c2000-04-04 01:40:52 +0000957 # -- Methods that operate on its Commands --------------------------
958
Tarek Ziadé188789d2009-05-16 18:37:32 +0000959 def run_command(self, command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000960 """Do whatever it takes to run a command (including nothing at all,
Greg Wardd5d8a992000-05-23 01:42:17 +0000961 if the command has already been run). Specifically: if we have
962 already created and run the command named by 'command', return
963 silently without doing anything. If the command named by 'command'
964 doesn't even have a command object yet, create one. Then invoke
965 'run()' on that command object (or an existing one).
966 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000967 # Already been here, done that? then return silently.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000968 if self.have_run.get(command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000969 return
970
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000971 log.info("running %s", command)
Greg Wardfd7b91e2000-09-26 01:52:25 +0000972 cmd_obj = self.get_command_obj(command)
973 cmd_obj.ensure_finalized()
974 cmd_obj.run()
Greg Wardfe6462c2000-04-04 01:40:52 +0000975 self.have_run[command] = 1
976
Greg Wardfe6462c2000-04-04 01:40:52 +0000977 # -- Distribution query methods ------------------------------------
978
Tarek Ziadé188789d2009-05-16 18:37:32 +0000979 def has_pure_modules(self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000980 return len(self.packages or self.py_modules or []) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000981
Tarek Ziadé188789d2009-05-16 18:37:32 +0000982 def has_ext_modules(self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000983 return self.ext_modules and len(self.ext_modules) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000984
Tarek Ziadé188789d2009-05-16 18:37:32 +0000985 def has_c_libraries(self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000986 return self.libraries and len(self.libraries) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000987
Tarek Ziadé188789d2009-05-16 18:37:32 +0000988 def has_modules(self):
Greg Wardfe6462c2000-04-04 01:40:52 +0000989 return self.has_pure_modules() or self.has_ext_modules()
990
Tarek Ziadé188789d2009-05-16 18:37:32 +0000991 def has_headers(self):
Greg Ward51def7d2000-05-27 01:36:14 +0000992 return self.headers and len(self.headers) > 0
993
Tarek Ziadé188789d2009-05-16 18:37:32 +0000994 def has_scripts(self):
Greg Ward44a61bb2000-05-20 15:06:48 +0000995 return self.scripts and len(self.scripts) > 0
996
Tarek Ziadé188789d2009-05-16 18:37:32 +0000997 def has_data_files(self):
Greg Ward44a61bb2000-05-20 15:06:48 +0000998 return self.data_files and len(self.data_files) > 0
999
Tarek Ziadé188789d2009-05-16 18:37:32 +00001000 def is_pure(self):
Greg Wardfe6462c2000-04-04 01:40:52 +00001001 return (self.has_pure_modules() and
1002 not self.has_ext_modules() and
1003 not self.has_c_libraries())
1004
Greg Ward82715e12000-04-21 02:28:14 +00001005 # -- Metadata query methods ----------------------------------------
1006
1007 # If you're looking for 'get_name()', 'get_version()', and so forth,
1008 # they are defined in a sneaky way: the constructor binds self.get_XXX
1009 # to self.metadata.get_XXX. The actual code is in the
1010 # DistributionMetadata class, below.
1011
Greg Ward82715e12000-04-21 02:28:14 +00001012class DistributionMetadata:
1013 """Dummy class to hold the distribution meta-data: name, version,
Greg Wardfd7b91e2000-09-26 01:52:25 +00001014 author, and so forth.
1015 """
Greg Ward82715e12000-04-21 02:28:14 +00001016
Neil Schemenauera8aefe52001-09-03 15:47:21 +00001017 _METHOD_BASENAMES = ("name", "version", "author", "author_email",
1018 "maintainer", "maintainer_email", "url",
1019 "license", "description", "long_description",
1020 "keywords", "platforms", "fullname", "contact",
Berker Peksagce18d8c2016-04-24 01:55:09 +03001021 "contact_email", "classifiers", "download_url",
Fred Drakedb7b0022005-03-20 22:19:47 +00001022 # PEP 314
1023 "provides", "requires", "obsoletes",
1024 )
Neil Schemenauera8aefe52001-09-03 15:47:21 +00001025
Jason R. Coombs3492e392013-11-10 18:15:03 -05001026 def __init__(self, path=None):
1027 if path is not None:
1028 self.read_pkg_file(open(path))
1029 else:
1030 self.name = None
1031 self.version = None
1032 self.author = None
1033 self.author_email = None
1034 self.maintainer = None
1035 self.maintainer_email = None
1036 self.url = None
1037 self.license = None
1038 self.description = None
1039 self.long_description = None
1040 self.keywords = None
1041 self.platforms = None
1042 self.classifiers = None
1043 self.download_url = None
1044 # PEP 314
1045 self.provides = None
1046 self.requires = None
1047 self.obsoletes = None
1048
1049 def read_pkg_file(self, file):
1050 """Reads the metadata values from a file object."""
1051 msg = message_from_file(file)
1052
1053 def _read_field(name):
1054 value = msg[name]
1055 if value == 'UNKNOWN':
1056 return None
1057 return value
1058
1059 def _read_list(name):
1060 values = msg.get_all(name, None)
1061 if values == []:
1062 return None
1063 return values
1064
1065 metadata_version = msg['metadata-version']
1066 self.name = _read_field('name')
1067 self.version = _read_field('version')
1068 self.description = _read_field('summary')
1069 # we are filling author only.
1070 self.author = _read_field('author')
Greg Ward82715e12000-04-21 02:28:14 +00001071 self.maintainer = None
Jason R. Coombs3492e392013-11-10 18:15:03 -05001072 self.author_email = _read_field('author-email')
Greg Ward82715e12000-04-21 02:28:14 +00001073 self.maintainer_email = None
Jason R. Coombs3492e392013-11-10 18:15:03 -05001074 self.url = _read_field('home-page')
1075 self.license = _read_field('license')
1076
1077 if 'download-url' in msg:
1078 self.download_url = _read_field('download-url')
1079 else:
1080 self.download_url = None
1081
1082 self.long_description = _read_field('description')
1083 self.description = _read_field('summary')
1084
1085 if 'keywords' in msg:
1086 self.keywords = _read_field('keywords').split(',')
1087
1088 self.platforms = _read_list('platform')
1089 self.classifiers = _read_list('classifier')
1090
1091 # PEP 314 - these fields only exist in 1.1
1092 if metadata_version == '1.1':
1093 self.requires = _read_list('requires')
1094 self.provides = _read_list('provides')
1095 self.obsoletes = _read_list('obsoletes')
1096 else:
1097 self.requires = None
1098 self.provides = None
1099 self.obsoletes = None
Fred Drakeb94b8492001-12-06 20:51:35 +00001100
Tarek Ziadé188789d2009-05-16 18:37:32 +00001101 def write_pkg_info(self, base_dir):
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +00001102 """Write the PKG-INFO file into the release tree.
1103 """
Victor Stinnera1bea6e2011-09-05 23:44:56 +02001104 with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
1105 encoding='UTF-8') as pkg_info:
Éric Araujobee5cef2010-11-05 23:51:56 +00001106 self.write_pkg_file(pkg_info)
Fred Drakeb94b8492001-12-06 20:51:35 +00001107
Tarek Ziadé188789d2009-05-16 18:37:32 +00001108 def write_pkg_file(self, file):
Fred Drakedb7b0022005-03-20 22:19:47 +00001109 """Write the PKG-INFO format data to a file object.
1110 """
1111 version = '1.0'
Éric Araujo13e8c8e2011-09-10 01:51:40 +02001112 if (self.provides or self.requires or self.obsoletes or
Jason R. Coombs7c456322014-07-02 08:36:19 -04001113 self.classifiers or self.download_url):
Fred Drakedb7b0022005-03-20 22:19:47 +00001114 version = '1.1'
1115
1116 file.write('Metadata-Version: %s\n' % version)
Jason R. Coombs7c456322014-07-02 08:36:19 -04001117 file.write('Name: %s\n' % self.get_name())
1118 file.write('Version: %s\n' % self.get_version())
1119 file.write('Summary: %s\n' % self.get_description())
1120 file.write('Home-page: %s\n' % self.get_url())
1121 file.write('Author: %s\n' % self.get_contact())
1122 file.write('Author-email: %s\n' % self.get_contact_email())
1123 file.write('License: %s\n' % self.get_license())
Fred Drakedb7b0022005-03-20 22:19:47 +00001124 if self.download_url:
1125 file.write('Download-URL: %s\n' % self.download_url)
1126
Tarek Ziadéf11be752009-06-01 22:36:26 +00001127 long_desc = rfc822_escape(self.get_long_description())
Fred Drakedb7b0022005-03-20 22:19:47 +00001128 file.write('Description: %s\n' % long_desc)
1129
Neal Norwitz9d72bb42007-04-17 08:48:32 +00001130 keywords = ','.join(self.get_keywords())
Fred Drakedb7b0022005-03-20 22:19:47 +00001131 if keywords:
Jason R. Coombs7c456322014-07-02 08:36:19 -04001132 file.write('Keywords: %s\n' % keywords)
Fred Drakedb7b0022005-03-20 22:19:47 +00001133
1134 self._write_list(file, 'Platform', self.get_platforms())
1135 self._write_list(file, 'Classifier', self.get_classifiers())
1136
1137 # PEP 314
1138 self._write_list(file, 'Requires', self.get_requires())
1139 self._write_list(file, 'Provides', self.get_provides())
1140 self._write_list(file, 'Obsoletes', self.get_obsoletes())
1141
Tarek Ziadé188789d2009-05-16 18:37:32 +00001142 def _write_list(self, file, name, values):
Fred Drakedb7b0022005-03-20 22:19:47 +00001143 for value in values:
1144 file.write('%s: %s\n' % (name, value))
1145
Greg Ward82715e12000-04-21 02:28:14 +00001146 # -- Metadata query methods ----------------------------------------
1147
Tarek Ziadé188789d2009-05-16 18:37:32 +00001148 def get_name(self):
Greg Wardfe6462c2000-04-04 01:40:52 +00001149 return self.name or "UNKNOWN"
1150
Greg Ward82715e12000-04-21 02:28:14 +00001151 def get_version(self):
Thomas Hellerbcd89752001-12-06 20:44:19 +00001152 return self.version or "0.0.0"
Greg Wardfe6462c2000-04-04 01:40:52 +00001153
Tarek Ziadé188789d2009-05-16 18:37:32 +00001154 def get_fullname(self):
Greg Ward82715e12000-04-21 02:28:14 +00001155 return "%s-%s" % (self.get_name(), self.get_version())
1156
1157 def get_author(self):
1158 return self.author or "UNKNOWN"
1159
1160 def get_author_email(self):
1161 return self.author_email or "UNKNOWN"
1162
1163 def get_maintainer(self):
1164 return self.maintainer or "UNKNOWN"
1165
1166 def get_maintainer_email(self):
1167 return self.maintainer_email or "UNKNOWN"
1168
1169 def get_contact(self):
Tarek Ziadé188789d2009-05-16 18:37:32 +00001170 return self.maintainer or self.author or "UNKNOWN"
Greg Ward82715e12000-04-21 02:28:14 +00001171
1172 def get_contact_email(self):
Tarek Ziadé188789d2009-05-16 18:37:32 +00001173 return self.maintainer_email or self.author_email or "UNKNOWN"
Greg Ward82715e12000-04-21 02:28:14 +00001174
1175 def get_url(self):
1176 return self.url or "UNKNOWN"
1177
Andrew M. Kuchlingfa7dc572001-08-10 18:49:23 +00001178 def get_license(self):
1179 return self.license or "UNKNOWN"
1180 get_licence = get_license
Fred Drakeb94b8492001-12-06 20:51:35 +00001181
Greg Ward82715e12000-04-21 02:28:14 +00001182 def get_description(self):
1183 return self.description or "UNKNOWN"
Greg Warde5a584e2000-04-26 02:26:55 +00001184
1185 def get_long_description(self):
1186 return self.long_description or "UNKNOWN"
1187
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +00001188 def get_keywords(self):
1189 return self.keywords or []
1190
Berker Peksagdcaed6b2017-11-23 21:34:20 +03001191 def set_keywords(self, value):
1192 # If 'keywords' is a string, it will be converted to a list
1193 # by Distribution.finalize_options(). To maintain backwards
1194 # compatibility, do not raise an exception if 'keywords' is
1195 # a string.
1196 if not isinstance(value, (list, str)):
1197 msg = "'keywords' should be a 'list', not %r"
1198 raise TypeError(msg % type(value).__name__)
1199 self.keywords = value
1200
Andrew M. Kuchlinga7210ed2001-03-22 03:06:52 +00001201 def get_platforms(self):
1202 return self.platforms or ["UNKNOWN"]
1203
Berker Peksagdcaed6b2017-11-23 21:34:20 +03001204 def set_platforms(self, value):
1205 # If 'platforms' is a string, it will be converted to a list
1206 # by Distribution.finalize_options(). To maintain backwards
1207 # compatibility, do not raise an exception if 'platforms' is
1208 # a string.
1209 if not isinstance(value, (list, str)):
1210 msg = "'platforms' should be a 'list', not %r"
1211 raise TypeError(msg % type(value).__name__)
1212 self.platforms = value
1213
Andrew M. Kuchling282e2c32003-01-03 15:24:36 +00001214 def get_classifiers(self):
1215 return self.classifiers or []
1216
Berker Peksagdcaed6b2017-11-23 21:34:20 +03001217 def set_classifiers(self, value):
1218 if not isinstance(value, list):
1219 msg = "'classifiers' should be a 'list', not %r"
1220 raise TypeError(msg % type(value).__name__)
1221 self.classifiers = value
1222
Andrew M. Kuchling188d85f2003-02-19 14:16:01 +00001223 def get_download_url(self):
1224 return self.download_url or "UNKNOWN"
1225
Fred Drakedb7b0022005-03-20 22:19:47 +00001226 # PEP 314
Fred Drakedb7b0022005-03-20 22:19:47 +00001227 def get_requires(self):
1228 return self.requires or []
1229
1230 def set_requires(self, value):
1231 import distutils.versionpredicate
1232 for v in value:
1233 distutils.versionpredicate.VersionPredicate(v)
1234 self.requires = value
1235
1236 def get_provides(self):
1237 return self.provides or []
1238
1239 def set_provides(self, value):
1240 value = [v.strip() for v in value]
1241 for v in value:
1242 import distutils.versionpredicate
Fred Drake227e8ff2005-03-21 06:36:32 +00001243 distutils.versionpredicate.split_provision(v)
Fred Drakedb7b0022005-03-20 22:19:47 +00001244 self.provides = value
1245
1246 def get_obsoletes(self):
1247 return self.obsoletes or []
1248
1249 def set_obsoletes(self, value):
1250 import distutils.versionpredicate
1251 for v in value:
1252 distutils.versionpredicate.VersionPredicate(v)
1253 self.obsoletes = value
1254
Tarek Ziadé188789d2009-05-16 18:37:32 +00001255def fix_help_options(options):
Greg Ward2ff78872000-06-24 00:23:20 +00001256 """Convert a 4-tuple 'help_options' list as found in various command
1257 classes to the 3-tuple form required by FancyGetopt.
1258 """
1259 new_options = []
1260 for help_tuple in options:
1261 new_options.append(help_tuple[0:3])
1262 return new_options