blob: 6bda869e2e8e84781310e02405965217cd4d8ab1 [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
7# created 2000/04/03, Greg Ward
8# (extricated from core.py; actually dates back to the beginning)
9
10__revision__ = "$Id$"
11
Gregory P. Smith14263542000-05-12 00:41:33 +000012import sys, os, string, re
Greg Wardfe6462c2000-04-04 01:40:52 +000013from types import *
14from copy import copy
15from distutils.errors import *
Greg Ward36c36fe2000-05-20 14:07:59 +000016from distutils import sysconfig
Greg Ward2f2b6c62000-09-25 01:58:07 +000017from distutils.fancy_getopt import FancyGetopt, translate_longopt
Greg Wardceb9e222000-09-25 01:23:52 +000018from distutils.util import check_environ, strtobool
Greg Wardfe6462c2000-04-04 01:40:52 +000019
20
21# Regex to define acceptable Distutils command names. This is not *quite*
22# the same as a Python NAME -- I don't allow leading underscores. The fact
23# that they're very similar is no coincidence; the default naming scheme is
24# to look for a Python module named after the command.
25command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
26
27
28class Distribution:
Greg Ward8ff5a3f2000-06-02 00:44:53 +000029 """The core of the Distutils. Most of the work hiding behind 'setup'
30 is really done within a Distribution instance, which farms the work out
31 to the Distutils commands specified on the command line.
Greg Wardfe6462c2000-04-04 01:40:52 +000032
Greg Ward8ff5a3f2000-06-02 00:44:53 +000033 Setup scripts will almost never instantiate Distribution directly,
34 unless the 'setup()' function is totally inadequate to their needs.
35 However, it is conceivable that a setup script might wish to subclass
36 Distribution for some specialized purpose, and then pass the subclass
37 to 'setup()' as the 'distclass' keyword argument. If so, it is
38 necessary to respect the expectations that 'setup' has of Distribution.
39 See the code for 'setup()', in core.py, for details.
40 """
Greg Wardfe6462c2000-04-04 01:40:52 +000041
42
43 # 'global_options' describes the command-line options that may be
Greg Ward82715e12000-04-21 02:28:14 +000044 # supplied to the setup script prior to any actual commands.
45 # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
Greg Wardfe6462c2000-04-04 01:40:52 +000046 # these global options. This list should be kept to a bare minimum,
47 # since every global option is also valid as a command option -- and we
48 # don't want to pollute the commands with too many options that they
49 # have minimal control over.
Greg Wardd5d8a992000-05-23 01:42:17 +000050 global_options = [('verbose', 'v', "run verbosely (default)"),
51 ('quiet', 'q', "run quietly (turns verbosity off)"),
52 ('dry-run', 'n', "don't actually do anything"),
53 ('help', 'h', "show detailed help message"),
Greg Wardfe6462c2000-04-04 01:40:52 +000054 ]
Greg Ward82715e12000-04-21 02:28:14 +000055
56 # options that are not propagated to the commands
57 display_options = [
58 ('help-commands', None,
59 "list all available commands"),
60 ('name', None,
61 "print package name"),
62 ('version', 'V',
63 "print package version"),
64 ('fullname', None,
65 "print <package name>-<version>"),
66 ('author', None,
67 "print the author's name"),
68 ('author-email', None,
69 "print the author's email address"),
70 ('maintainer', None,
71 "print the maintainer's name"),
72 ('maintainer-email', None,
73 "print the maintainer's email address"),
74 ('contact', None,
Greg Wardd5d8a992000-05-23 01:42:17 +000075 "print the maintainer's name if known, else the author's"),
Greg Ward82715e12000-04-21 02:28:14 +000076 ('contact-email', None,
Greg Wardd5d8a992000-05-23 01:42:17 +000077 "print the maintainer's email address if known, else the author's"),
Greg Ward82715e12000-04-21 02:28:14 +000078 ('url', None,
79 "print the URL for this package"),
80 ('licence', None,
81 "print the licence of the package"),
82 ('license', None,
83 "alias for --licence"),
84 ('description', None,
85 "print the package description"),
Greg Warde5a584e2000-04-26 02:26:55 +000086 ('long-description', None,
87 "print the long package description"),
Greg Ward82715e12000-04-21 02:28:14 +000088 ]
Greg Ward2f2b6c62000-09-25 01:58:07 +000089 display_option_names = map(lambda x: translate_longopt(x[0]),
90 display_options)
Greg Ward82715e12000-04-21 02:28:14 +000091
92 # negative options are options that exclude other options
Greg Wardfe6462c2000-04-04 01:40:52 +000093 negative_opt = {'quiet': 'verbose'}
94
95
96 # -- Creation/initialization methods -------------------------------
97
98 def __init__ (self, attrs=None):
99 """Construct a new Distribution instance: initialize all the
Greg Ward8ff5a3f2000-06-02 00:44:53 +0000100 attributes of a Distribution, and then use 'attrs' (a dictionary
101 mapping attribute names to values) to assign some of those
102 attributes their "real" values. (Any attributes not mentioned in
103 'attrs' will be assigned to some null value: 0, None, an empty list
104 or dictionary, etc.) Most importantly, initialize the
105 'command_obj' attribute to the empty dictionary; this will be
106 filled in with real command objects by 'parse_command_line()'.
107 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000108
109 # Default values for our command-line options
110 self.verbose = 1
111 self.dry_run = 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000112 self.help = 0
Greg Ward82715e12000-04-21 02:28:14 +0000113 for attr in self.display_option_names:
114 setattr(self, attr, 0)
Greg Wardfe6462c2000-04-04 01:40:52 +0000115
Greg Ward82715e12000-04-21 02:28:14 +0000116 # Store the distribution meta-data (name, version, author, and so
117 # forth) in a separate object -- we're getting to have enough
118 # information here (and enough command-line options) that it's
119 # worth it. Also delegate 'get_XXX()' methods to the 'metadata'
120 # object in a sneaky and underhanded (but efficient!) way.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000121 self.metadata = DistributionMetadata()
Greg Ward4982f982000-04-22 02:52:44 +0000122 method_basenames = dir(self.metadata) + \
123 ['fullname', 'contact', 'contact_email']
124 for basename in method_basenames:
125 method_name = "get_" + basename
126 setattr(self, method_name, getattr(self.metadata, method_name))
Greg Wardfe6462c2000-04-04 01:40:52 +0000127
128 # 'cmdclass' maps command names to class objects, so we
129 # can 1) quickly figure out which class to instantiate when
130 # we need to create a new command object, and 2) have a way
Greg Ward82715e12000-04-21 02:28:14 +0000131 # for the setup script to override command classes
Greg Wardfe6462c2000-04-04 01:40:52 +0000132 self.cmdclass = {}
133
Greg Ward9821bf42000-08-29 01:15:18 +0000134 # 'script_name' and 'script_args' are usually set to sys.argv[0]
135 # and sys.argv[1:], but they can be overridden when the caller is
136 # not necessarily a setup script run from the command-line.
137 self.script_name = None
138 self.script_args = None
139
Greg Wardd5d8a992000-05-23 01:42:17 +0000140 # 'command_options' is where we store command options between
141 # parsing them (from config files, the command-line, etc.) and when
142 # they are actually needed -- ie. when the command in question is
143 # instantiated. It is a dictionary of dictionaries of 2-tuples:
144 # command_options = { command_name : { option : (source, value) } }
Gregory P. Smith14263542000-05-12 00:41:33 +0000145 self.command_options = {}
146
Greg Wardfe6462c2000-04-04 01:40:52 +0000147 # These options are really the business of various commands, rather
148 # than of the Distribution itself. We provide aliases for them in
149 # Distribution as a convenience to the developer.
Greg Wardfe6462c2000-04-04 01:40:52 +0000150 self.packages = None
151 self.package_dir = None
152 self.py_modules = None
153 self.libraries = None
Greg Ward51def7d2000-05-27 01:36:14 +0000154 self.headers = None
Greg Wardfe6462c2000-04-04 01:40:52 +0000155 self.ext_modules = None
156 self.ext_package = None
157 self.include_dirs = None
158 self.extra_path = None
Gregory P. Smithb2e3bb32000-05-12 00:52:23 +0000159 self.scripts = None
Gregory P. Smith6a901dd2000-05-13 03:09:50 +0000160 self.data_files = None
Greg Wardfe6462c2000-04-04 01:40:52 +0000161
162 # And now initialize bookkeeping stuff that can't be supplied by
163 # the caller at all. 'command_obj' maps command names to
164 # Command instances -- that's how we enforce that every command
165 # class is a singleton.
166 self.command_obj = {}
167
168 # 'have_run' maps command names to boolean values; it keeps track
169 # of whether we have actually run a particular command, to make it
170 # cheap to "run" a command whenever we think we might need to -- if
171 # it's already been done, no need for expensive filesystem
172 # operations, we just check the 'have_run' dictionary and carry on.
173 # It's only safe to query 'have_run' for a command class that has
174 # been instantiated -- a false value will be inserted when the
175 # command object is created, and replaced with a true value when
Greg Ward612eb9f2000-07-27 02:13:20 +0000176 # the command is successfully run. Thus it's probably best to use
Greg Wardfe6462c2000-04-04 01:40:52 +0000177 # '.get()' rather than a straight lookup.
178 self.have_run = {}
179
180 # Now we'll use the attrs dictionary (ultimately, keyword args from
Greg Ward82715e12000-04-21 02:28:14 +0000181 # the setup script) to possibly override any or all of these
182 # distribution options.
183
Greg Wardfe6462c2000-04-04 01:40:52 +0000184 if attrs:
185
186 # Pull out the set of command options and work on them
187 # specifically. Note that this order guarantees that aliased
188 # command options will override any supplied redundantly
189 # through the general options dictionary.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000190 options = attrs.get('options')
Greg Wardfe6462c2000-04-04 01:40:52 +0000191 if options:
192 del attrs['options']
193 for (command, cmd_options) in options.items():
Greg Ward0e48cfd2000-05-26 01:00:15 +0000194 opt_dict = self.get_option_dict(command)
195 for (opt, val) in cmd_options.items():
196 opt_dict[opt] = ("setup script", val)
Greg Wardfe6462c2000-04-04 01:40:52 +0000197
198 # Now work on the rest of the attributes. Any attribute that's
199 # not already defined is invalid!
200 for (key,val) in attrs.items():
Greg Wardfd7b91e2000-09-26 01:52:25 +0000201 if hasattr(self.metadata, key):
202 setattr(self.metadata, key, val)
203 elif hasattr(self, key):
204 setattr(self, key, val)
Greg Wardfe6462c2000-04-04 01:40:52 +0000205 else:
Greg Ward02a1a2b2000-04-15 22:15:07 +0000206 raise DistutilsSetupError, \
Greg Wardfe6462c2000-04-04 01:40:52 +0000207 "invalid distribution option '%s'" % key
208
Andrew M. Kuchling898f0992001-03-17 19:59:26 +0000209 if self.metadata.version is None:
210 raise DistutilsSetupError, \
211 "No version number specified for distribution"
212
Greg Wardfe6462c2000-04-04 01:40:52 +0000213 # __init__ ()
214
215
Greg Ward0e48cfd2000-05-26 01:00:15 +0000216 def get_option_dict (self, command):
217 """Get the option dictionary for a given command. If that
218 command's option dictionary hasn't been created yet, then create it
219 and return the new dictionary; otherwise, return the existing
220 option dictionary.
221 """
222
223 dict = self.command_options.get(command)
224 if dict is None:
225 dict = self.command_options[command] = {}
226 return dict
227
228
Greg Wardc32d9a62000-05-28 23:53:06 +0000229 def dump_option_dicts (self, header=None, commands=None, indent=""):
230 from pprint import pformat
231
232 if commands is None: # dump all command option dicts
233 commands = self.command_options.keys()
234 commands.sort()
235
236 if header is not None:
237 print indent + header
238 indent = indent + " "
239
240 if not commands:
241 print indent + "no commands known yet"
242 return
243
244 for cmd_name in commands:
245 opt_dict = self.command_options.get(cmd_name)
246 if opt_dict is None:
247 print indent + "no option dict for '%s' command" % cmd_name
248 else:
249 print indent + "option dict for '%s' command:" % cmd_name
250 out = pformat(opt_dict)
251 for line in string.split(out, "\n"):
252 print indent + " " + line
253
254 # dump_option_dicts ()
255
256
257
Greg Wardd5d8a992000-05-23 01:42:17 +0000258 # -- Config file finding/parsing methods ---------------------------
259
Gregory P. Smith14263542000-05-12 00:41:33 +0000260 def find_config_files (self):
261 """Find as many configuration files as should be processed for this
262 platform, and return a list of filenames in the order in which they
263 should be parsed. The filenames returned are guaranteed to exist
264 (modulo nasty race conditions).
265
266 On Unix, there are three possible config files: pydistutils.cfg in
267 the Distutils installation directory (ie. where the top-level
268 Distutils __inst__.py file lives), .pydistutils.cfg in the user's
269 home directory, and setup.cfg in the current directory.
270
271 On Windows and Mac OS, there are two possible config files:
272 pydistutils.cfg in the Python installation directory (sys.prefix)
Greg Wardd5d8a992000-05-23 01:42:17 +0000273 and setup.cfg in the current directory.
274 """
Gregory P. Smith14263542000-05-12 00:41:33 +0000275 files = []
Greg Wardacf3f6a2000-06-07 02:26:19 +0000276 check_environ()
Gregory P. Smith14263542000-05-12 00:41:33 +0000277
Greg Ward11696872000-06-07 02:29:03 +0000278 # Where to look for the system-wide Distutils config file
279 sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
280
281 # Look for the system config file
282 sys_file = os.path.join(sys_dir, "distutils.cfg")
Greg Wardacf3f6a2000-06-07 02:26:19 +0000283 if os.path.isfile(sys_file):
284 files.append(sys_file)
Gregory P. Smith14263542000-05-12 00:41:33 +0000285
Greg Ward11696872000-06-07 02:29:03 +0000286 # What to call the per-user config file
287 if os.name == 'posix':
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000288 user_filename = ".pydistutils.cfg"
289 else:
290 user_filename = "pydistutils.cfg"
Greg Wardfa9ff762000-10-14 04:06:40 +0000291
Greg Ward11696872000-06-07 02:29:03 +0000292 # And look for the user config file
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000293 if os.environ.has_key('HOME'):
294 user_file = os.path.join(os.environ.get('HOME'), user_filename)
Gregory P. Smith14263542000-05-12 00:41:33 +0000295 if os.path.isfile(user_file):
296 files.append(user_file)
297
Gregory P. Smith14263542000-05-12 00:41:33 +0000298 # All platforms support local setup.cfg
299 local_file = "setup.cfg"
300 if os.path.isfile(local_file):
301 files.append(local_file)
302
303 return files
304
305 # find_config_files ()
306
307
308 def parse_config_files (self, filenames=None):
309
310 from ConfigParser import ConfigParser
Greg Ward2bd3f422000-06-02 01:59:33 +0000311 from distutils.core import DEBUG
Gregory P. Smith14263542000-05-12 00:41:33 +0000312
313 if filenames is None:
314 filenames = self.find_config_files()
315
Greg Ward2bd3f422000-06-02 01:59:33 +0000316 if DEBUG: print "Distribution.parse_config_files():"
Greg Ward47460772000-05-23 03:47:35 +0000317
Gregory P. Smith14263542000-05-12 00:41:33 +0000318 parser = ConfigParser()
Greg Wardd5d8a992000-05-23 01:42:17 +0000319 for filename in filenames:
Greg Ward2bd3f422000-06-02 01:59:33 +0000320 if DEBUG: print " reading", filename
Greg Wardd5d8a992000-05-23 01:42:17 +0000321 parser.read(filename)
322 for section in parser.sections():
323 options = parser.options(section)
Greg Ward0e48cfd2000-05-26 01:00:15 +0000324 opt_dict = self.get_option_dict(section)
Gregory P. Smith14263542000-05-12 00:41:33 +0000325
Greg Wardd5d8a992000-05-23 01:42:17 +0000326 for opt in options:
327 if opt != '__name__':
Greg Wardceb9e222000-09-25 01:23:52 +0000328 val = parser.get(section,opt)
329 opt = string.replace(opt, '-', '_')
330 opt_dict[opt] = (filename, val)
Gregory P. Smith14263542000-05-12 00:41:33 +0000331
Greg Ward47460772000-05-23 03:47:35 +0000332 # Make the ConfigParser forget everything (so we retain
333 # the original filenames that options come from) -- gag,
334 # retch, puke -- another good reason for a distutils-
335 # specific config parser (sigh...)
336 parser.__init__()
Gregory P. Smith14263542000-05-12 00:41:33 +0000337
Greg Wardceb9e222000-09-25 01:23:52 +0000338 # If there was a "global" section in the config file, use it
339 # to set Distribution options.
340
341 if self.command_options.has_key('global'):
342 for (opt, (src, val)) in self.command_options['global'].items():
343 alias = self.negative_opt.get(opt)
344 try:
345 if alias:
346 setattr(self, alias, not strtobool(val))
347 elif opt in ('verbose', 'dry_run'): # ugh!
348 setattr(self, opt, strtobool(val))
349 except ValueError, msg:
350 raise DistutilsOptionError, msg
351
352 # parse_config_files ()
353
Gregory P. Smith14263542000-05-12 00:41:33 +0000354
Greg Wardd5d8a992000-05-23 01:42:17 +0000355 # -- Command-line parsing methods ----------------------------------
356
Greg Ward9821bf42000-08-29 01:15:18 +0000357 def parse_command_line (self):
358 """Parse the setup script's command line, taken from the
359 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
360 -- see 'setup()' in core.py). This list is first processed for
361 "global options" -- options that set attributes of the Distribution
362 instance. Then, it is alternately scanned for Distutils commands
363 and options for that command. Each new command terminates the
364 options for the previous command. The allowed options for a
365 command are determined by the 'user_options' attribute of the
366 command class -- thus, we have to be able to load command classes
367 in order to parse the command line. Any error in that 'options'
368 attribute raises DistutilsGetoptError; any error on the
369 command-line raises DistutilsArgError. If no Distutils commands
370 were found on the command line, raises DistutilsArgError. Return
Greg Wardceb9e222000-09-25 01:23:52 +0000371 true if command-line was successfully parsed and we should carry
Greg Ward9821bf42000-08-29 01:15:18 +0000372 on with executing commands; false if no errors but we shouldn't
373 execute commands (currently, this only happens if user asks for
374 help).
Greg Wardd5d8a992000-05-23 01:42:17 +0000375 """
Andrew M. Kuchling3f819ec2001-01-15 16:09:35 +0000376 #
377 # We now have enough information to show the Macintosh dialog that allows
378 # the user to interactively specify the "command line".
379 #
380 if sys.platform == 'mac':
381 import EasyDialogs
382 cmdlist = self.get_command_list()
383 self.script_args = EasyDialogs.GetArgv(
384 self.global_options + self.display_options, cmdlist)
385
Greg Wardfe6462c2000-04-04 01:40:52 +0000386 # We have to parse the command line a bit at a time -- global
387 # options, then the first command, then its options, and so on --
388 # because each command will be handled by a different class, and
Greg Wardd5d8a992000-05-23 01:42:17 +0000389 # the options that are valid for a particular class aren't known
390 # until we have loaded the command class, which doesn't happen
391 # until we know what the command is.
Greg Wardfe6462c2000-04-04 01:40:52 +0000392
393 self.commands = []
Greg Wardfd7b91e2000-09-26 01:52:25 +0000394 parser = FancyGetopt(self.global_options + self.display_options)
395 parser.set_negative_aliases(self.negative_opt)
396 parser.set_aliases({'license': 'licence'})
397 args = parser.getopt(args=self.script_args, object=self)
Greg Ward82715e12000-04-21 02:28:14 +0000398 option_order = parser.get_option_order()
Greg Wardfe6462c2000-04-04 01:40:52 +0000399
Greg Ward82715e12000-04-21 02:28:14 +0000400 # for display options we return immediately
401 if self.handle_display_options(option_order):
Greg Wardfe6462c2000-04-04 01:40:52 +0000402 return
403
404 while args:
Greg Wardd5d8a992000-05-23 01:42:17 +0000405 args = self._parse_command_opts(parser, args)
406 if args is None: # user asked for help (and got it)
Greg Wardfe6462c2000-04-04 01:40:52 +0000407 return
Greg Wardfe6462c2000-04-04 01:40:52 +0000408
Greg Wardd5d8a992000-05-23 01:42:17 +0000409 # Handle the cases of --help as a "global" option, ie.
410 # "setup.py --help" and "setup.py --help command ...". For the
411 # former, we show global options (--verbose, --dry-run, etc.)
412 # and display-only options (--name, --version, etc.); for the
413 # latter, we omit the display-only options and show help for
414 # each command listed on the command line.
Greg Wardfe6462c2000-04-04 01:40:52 +0000415 if self.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000416 self._show_help(parser,
417 display_options=len(self.commands) == 0,
418 commands=self.commands)
Greg Wardfe6462c2000-04-04 01:40:52 +0000419 return
420
421 # Oops, no commands found -- an end-user error
422 if not self.commands:
423 raise DistutilsArgError, "no commands supplied"
424
425 # All is well: return true
426 return 1
427
428 # parse_command_line()
429
Greg Wardd5d8a992000-05-23 01:42:17 +0000430 def _parse_command_opts (self, parser, args):
Greg Wardd5d8a992000-05-23 01:42:17 +0000431 """Parse the command-line options for a single command.
432 'parser' must be a FancyGetopt instance; 'args' must be the list
433 of arguments, starting with the current command (whose options
434 we are about to parse). Returns a new version of 'args' with
435 the next command at the front of the list; will be the empty
436 list if there are no more commands on the command line. Returns
437 None if the user asked for help on this command.
438 """
439 # late import because of mutual dependence between these modules
440 from distutils.cmd import Command
441
442 # Pull the current command from the head of the command line
443 command = args[0]
Greg Wardfd7b91e2000-09-26 01:52:25 +0000444 if not command_re.match(command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000445 raise SystemExit, "invalid command name '%s'" % command
Greg Wardfd7b91e2000-09-26 01:52:25 +0000446 self.commands.append(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000447
448 # Dig up the command class that implements this command, so we
449 # 1) know that it's a valid command, and 2) know which options
450 # it takes.
451 try:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000452 cmd_class = self.get_command_class(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000453 except DistutilsModuleError, msg:
454 raise DistutilsArgError, msg
455
456 # Require that the command class be derived from Command -- want
457 # to be sure that the basic "command" interface is implemented.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000458 if not issubclass(cmd_class, Command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000459 raise DistutilsClassError, \
460 "command class %s must subclass Command" % cmd_class
461
462 # Also make sure that the command object provides a list of its
463 # known options.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000464 if not (hasattr(cmd_class, 'user_options') and
465 type(cmd_class.user_options) is ListType):
Greg Wardd5d8a992000-05-23 01:42:17 +0000466 raise DistutilsClassError, \
467 ("command class %s must provide " +
468 "'user_options' attribute (a list of tuples)") % \
469 cmd_class
470
471 # If the command class has a list of negative alias options,
472 # merge it in with the global negative aliases.
473 negative_opt = self.negative_opt
Greg Wardfd7b91e2000-09-26 01:52:25 +0000474 if hasattr(cmd_class, 'negative_opt'):
475 negative_opt = copy(negative_opt)
476 negative_opt.update(cmd_class.negative_opt)
Greg Wardd5d8a992000-05-23 01:42:17 +0000477
Greg Wardfa9ff762000-10-14 04:06:40 +0000478 # Check for help_options in command class. They have a different
479 # format (tuple of four) so we need to preprocess them here.
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000480 if (hasattr(cmd_class, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000481 type(cmd_class.help_options) is ListType):
Greg Ward2ff78872000-06-24 00:23:20 +0000482 help_options = fix_help_options(cmd_class.help_options)
483 else:
Greg Ward55fced32000-06-24 01:22:41 +0000484 help_options = []
Greg Ward2ff78872000-06-24 00:23:20 +0000485
Greg Ward9d17a7a2000-06-07 03:00:06 +0000486
Greg Wardd5d8a992000-05-23 01:42:17 +0000487 # All commands support the global options too, just by adding
488 # in 'global_options'.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000489 parser.set_option_table(self.global_options +
490 cmd_class.user_options +
491 help_options)
492 parser.set_negative_aliases(negative_opt)
493 (args, opts) = parser.getopt(args[1:])
Greg Ward47460772000-05-23 03:47:35 +0000494 if hasattr(opts, 'help') and opts.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000495 self._show_help(parser, display_options=0, commands=[cmd_class])
496 return
497
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000498 if (hasattr(cmd_class, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000499 type(cmd_class.help_options) is ListType):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000500 help_option_found=0
501 for (help_option, short, desc, func) in cmd_class.help_options:
502 if hasattr(opts, parser.get_attr_name(help_option)):
503 help_option_found=1
Greg Wardfa9ff762000-10-14 04:06:40 +0000504 #print "showing help for option %s of command %s" % \
Greg Ward2ff78872000-06-24 00:23:20 +0000505 # (help_option[0],cmd_class)
Greg Ward55fced32000-06-24 01:22:41 +0000506
507 if callable(func):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000508 func()
Greg Ward55fced32000-06-24 01:22:41 +0000509 else:
510 raise DistutilsClassError, \
511 ("invalid help function %s for help option '%s': "
512 "must be a callable object (function, etc.)") % \
513 (`func`, help_option)
514
515 if help_option_found:
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000516 return
Greg Ward9d17a7a2000-06-07 03:00:06 +0000517
Greg Wardd5d8a992000-05-23 01:42:17 +0000518 # Put the options from the command-line into their official
519 # holding pen, the 'command_options' dictionary.
Greg Ward0e48cfd2000-05-26 01:00:15 +0000520 opt_dict = self.get_option_dict(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000521 for (name, value) in vars(opts).items():
Greg Ward0e48cfd2000-05-26 01:00:15 +0000522 opt_dict[name] = ("command line", value)
Greg Wardd5d8a992000-05-23 01:42:17 +0000523
524 return args
525
526 # _parse_command_opts ()
527
528
529 def _show_help (self,
530 parser,
531 global_options=1,
532 display_options=1,
533 commands=[]):
534 """Show help for the setup script command-line in the form of
535 several lists of command-line options. 'parser' should be a
536 FancyGetopt instance; do not expect it to be returned in the
537 same state, as its option table will be reset to make it
538 generate the correct help text.
539
540 If 'global_options' is true, lists the global options:
541 --verbose, --dry-run, etc. If 'display_options' is true, lists
542 the "display-only" options: --name, --version, etc. Finally,
543 lists per-command help for every command name or command class
544 in 'commands'.
545 """
546 # late import because of mutual dependence between these modules
Greg Ward9821bf42000-08-29 01:15:18 +0000547 from distutils.core import gen_usage
Greg Wardd5d8a992000-05-23 01:42:17 +0000548 from distutils.cmd import Command
549
550 if global_options:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000551 parser.set_option_table(self.global_options)
552 parser.print_help("Global options:")
Greg Wardd5d8a992000-05-23 01:42:17 +0000553 print
554
555 if display_options:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000556 parser.set_option_table(self.display_options)
557 parser.print_help(
Greg Wardd5d8a992000-05-23 01:42:17 +0000558 "Information display options (just display " +
559 "information, ignore any commands)")
560 print
561
562 for command in self.commands:
563 if type(command) is ClassType and issubclass(klass, Command):
564 klass = command
565 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000566 klass = self.get_command_class(command)
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000567 if (hasattr(klass, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000568 type(klass.help_options) is ListType):
569 parser.set_option_table(klass.user_options +
570 fix_help_options(klass.help_options))
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000571 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000572 parser.set_option_table(klass.user_options)
573 parser.print_help("Options for '%s' command:" % klass.__name__)
Greg Wardd5d8a992000-05-23 01:42:17 +0000574 print
575
Greg Ward9821bf42000-08-29 01:15:18 +0000576 print gen_usage(self.script_name)
Greg Wardd5d8a992000-05-23 01:42:17 +0000577 return
578
579 # _show_help ()
Greg Wardfa9ff762000-10-14 04:06:40 +0000580
Greg Wardd5d8a992000-05-23 01:42:17 +0000581
Greg Ward82715e12000-04-21 02:28:14 +0000582 def handle_display_options (self, option_order):
583 """If there were any non-global "display-only" options
Greg Wardd5d8a992000-05-23 01:42:17 +0000584 (--help-commands or the metadata display options) on the command
585 line, display the requested info and return true; else return
586 false.
587 """
Greg Ward9821bf42000-08-29 01:15:18 +0000588 from distutils.core import gen_usage
Greg Ward82715e12000-04-21 02:28:14 +0000589
590 # User just wants a list of commands -- we'll print it out and stop
591 # processing now (ie. if they ran "setup --help-commands foo bar",
592 # we ignore "foo bar").
593 if self.help_commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000594 self.print_commands()
Greg Ward82715e12000-04-21 02:28:14 +0000595 print
Greg Ward9821bf42000-08-29 01:15:18 +0000596 print gen_usage(self.script_name)
Greg Ward82715e12000-04-21 02:28:14 +0000597 return 1
598
599 # If user supplied any of the "display metadata" options, then
600 # display that metadata in the order in which the user supplied the
601 # metadata options.
602 any_display_options = 0
603 is_display_option = {}
604 for option in self.display_options:
605 is_display_option[option[0]] = 1
606
607 for (opt, val) in option_order:
608 if val and is_display_option.get(opt):
Greg Ward2f2b6c62000-09-25 01:58:07 +0000609 opt = translate_longopt(opt)
Greg Ward82715e12000-04-21 02:28:14 +0000610 print getattr(self.metadata, "get_"+opt)()
611 any_display_options = 1
612
613 return any_display_options
614
615 # handle_display_options()
Greg Wardfe6462c2000-04-04 01:40:52 +0000616
617 def print_command_list (self, commands, header, max_length):
618 """Print a subset of the list of all commands -- used by
Greg Wardd5d8a992000-05-23 01:42:17 +0000619 'print_commands()'.
620 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000621
622 print header + ":"
623
624 for cmd in commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000625 klass = self.cmdclass.get(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000626 if not klass:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000627 klass = self.get_command_class(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000628 try:
629 description = klass.description
630 except AttributeError:
631 description = "(no description available)"
632
633 print " %-*s %s" % (max_length, cmd, description)
634
635 # print_command_list ()
636
637
638 def print_commands (self):
Greg Wardd5d8a992000-05-23 01:42:17 +0000639 """Print out a help message listing all available commands with a
640 description of each. The list is divided into "standard commands"
641 (listed in distutils.command.__all__) and "extra commands"
642 (mentioned in self.cmdclass, but not a standard command). The
643 descriptions come from the command class attribute
644 'description'.
645 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000646
647 import distutils.command
648 std_commands = distutils.command.__all__
649 is_std = {}
650 for cmd in std_commands:
651 is_std[cmd] = 1
652
653 extra_commands = []
654 for cmd in self.cmdclass.keys():
655 if not is_std.get(cmd):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000656 extra_commands.append(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000657
658 max_length = 0
659 for cmd in (std_commands + extra_commands):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000660 if len(cmd) > max_length:
661 max_length = len(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000662
Greg Wardfd7b91e2000-09-26 01:52:25 +0000663 self.print_command_list(std_commands,
664 "Standard commands",
665 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000666 if extra_commands:
667 print
Greg Wardfd7b91e2000-09-26 01:52:25 +0000668 self.print_command_list(extra_commands,
669 "Extra commands",
670 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000671
672 # print_commands ()
Greg Wardfe6462c2000-04-04 01:40:52 +0000673
Greg Wardf6fc8752000-11-11 02:47:11 +0000674 def get_command_list (self):
675 """Get a list of (command, description) tuples.
676 The list is divided into "standard commands" (listed in
677 distutils.command.__all__) and "extra commands" (mentioned in
678 self.cmdclass, but not a standard command). The descriptions come
679 from the command class attribute 'description'.
680 """
681 # Currently this is only used on Mac OS, for the Mac-only GUI
682 # Distutils interface (by Jack Jansen)
683
684 import distutils.command
685 std_commands = distutils.command.__all__
686 is_std = {}
687 for cmd in std_commands:
688 is_std[cmd] = 1
689
690 extra_commands = []
691 for cmd in self.cmdclass.keys():
692 if not is_std.get(cmd):
693 extra_commands.append(cmd)
694
695 rv = []
696 for cmd in (std_commands + extra_commands):
697 klass = self.cmdclass.get(cmd)
698 if not klass:
699 klass = self.get_command_class(cmd)
700 try:
701 description = klass.description
702 except AttributeError:
703 description = "(no description available)"
704 rv.append((cmd, description))
705 return rv
Greg Wardfe6462c2000-04-04 01:40:52 +0000706
707 # -- Command class/object methods ----------------------------------
708
Greg Wardd5d8a992000-05-23 01:42:17 +0000709 def get_command_class (self, command):
710 """Return the class that implements the Distutils command named by
711 'command'. First we check the 'cmdclass' dictionary; if the
712 command is mentioned there, we fetch the class object from the
713 dictionary and return it. Otherwise we load the command module
714 ("distutils.command." + command) and fetch the command class from
715 the module. The loaded class is also stored in 'cmdclass'
716 to speed future calls to 'get_command_class()'.
Greg Wardfe6462c2000-04-04 01:40:52 +0000717
Gregory P. Smith14263542000-05-12 00:41:33 +0000718 Raises DistutilsModuleError if the expected module could not be
Greg Wardd5d8a992000-05-23 01:42:17 +0000719 found, or if that module does not define the expected class.
720 """
721 klass = self.cmdclass.get(command)
722 if klass:
723 return klass
Greg Wardfe6462c2000-04-04 01:40:52 +0000724
725 module_name = 'distutils.command.' + command
726 klass_name = command
727
728 try:
729 __import__ (module_name)
730 module = sys.modules[module_name]
731 except ImportError:
732 raise DistutilsModuleError, \
733 "invalid command '%s' (no module named '%s')" % \
734 (command, module_name)
735
736 try:
Greg Wardd5d8a992000-05-23 01:42:17 +0000737 klass = getattr(module, klass_name)
738 except AttributeError:
Greg Wardfe6462c2000-04-04 01:40:52 +0000739 raise DistutilsModuleError, \
740 "invalid command '%s' (no class '%s' in module '%s')" \
741 % (command, klass_name, module_name)
742
Greg Wardd5d8a992000-05-23 01:42:17 +0000743 self.cmdclass[command] = klass
Greg Wardfe6462c2000-04-04 01:40:52 +0000744 return klass
745
Greg Wardd5d8a992000-05-23 01:42:17 +0000746 # get_command_class ()
Greg Wardfe6462c2000-04-04 01:40:52 +0000747
Greg Wardd5d8a992000-05-23 01:42:17 +0000748 def get_command_obj (self, command, create=1):
749 """Return the command object for 'command'. Normally this object
Greg Ward612eb9f2000-07-27 02:13:20 +0000750 is cached on a previous call to 'get_command_obj()'; if no command
Greg Wardd5d8a992000-05-23 01:42:17 +0000751 object for 'command' is in the cache, then we either create and
752 return it (if 'create' is true) or return None.
753 """
Greg Ward2bd3f422000-06-02 01:59:33 +0000754 from distutils.core import DEBUG
Greg Wardd5d8a992000-05-23 01:42:17 +0000755 cmd_obj = self.command_obj.get(command)
Greg Wardfe6462c2000-04-04 01:40:52 +0000756 if not cmd_obj and create:
Greg Ward2bd3f422000-06-02 01:59:33 +0000757 if DEBUG:
758 print "Distribution.get_command_obj(): " \
759 "creating '%s' command object" % command
Greg Ward47460772000-05-23 03:47:35 +0000760
Greg Wardd5d8a992000-05-23 01:42:17 +0000761 klass = self.get_command_class(command)
Greg Ward47460772000-05-23 03:47:35 +0000762 cmd_obj = self.command_obj[command] = klass(self)
763 self.have_run[command] = 0
764
765 # Set any options that were supplied in config files
766 # or on the command line. (NB. support for error
767 # reporting is lame here: any errors aren't reported
768 # until 'finalize_options()' is called, which means
769 # we won't report the source of the error.)
770 options = self.command_options.get(command)
771 if options:
Greg Wardc32d9a62000-05-28 23:53:06 +0000772 self._set_command_options(cmd_obj, options)
Greg Wardfe6462c2000-04-04 01:40:52 +0000773
774 return cmd_obj
775
Greg Wardc32d9a62000-05-28 23:53:06 +0000776 def _set_command_options (self, command_obj, option_dict=None):
Greg Wardc32d9a62000-05-28 23:53:06 +0000777 """Set the options for 'command_obj' from 'option_dict'. Basically
778 this means copying elements of a dictionary ('option_dict') to
779 attributes of an instance ('command').
780
Greg Wardceb9e222000-09-25 01:23:52 +0000781 'command_obj' must be a Command instance. If 'option_dict' is not
Greg Wardc32d9a62000-05-28 23:53:06 +0000782 supplied, uses the standard option dictionary for this command
783 (from 'self.command_options').
784 """
785 from distutils.core import DEBUG
786
787 command_name = command_obj.get_command_name()
788 if option_dict is None:
789 option_dict = self.get_option_dict(command_name)
790
791 if DEBUG: print " setting options for '%s' command:" % command_name
792 for (option, (source, value)) in option_dict.items():
793 if DEBUG: print " %s = %s (from %s)" % (option, value, source)
Greg Wardceb9e222000-09-25 01:23:52 +0000794 try:
Greg Ward2f2b6c62000-09-25 01:58:07 +0000795 bool_opts = map(translate_longopt, command_obj.boolean_options)
Greg Wardceb9e222000-09-25 01:23:52 +0000796 except AttributeError:
797 bool_opts = []
798 try:
799 neg_opt = command_obj.negative_opt
800 except AttributeError:
801 neg_opt = {}
802
803 try:
Greg Ward2c08cf02000-09-27 00:15:37 +0000804 is_string = type(value) is StringType
805 if neg_opt.has_key(option) and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000806 setattr(command_obj, neg_opt[option], not strtobool(value))
Greg Ward2c08cf02000-09-27 00:15:37 +0000807 elif option in bool_opts and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000808 setattr(command_obj, option, strtobool(value))
809 elif hasattr(command_obj, option):
810 setattr(command_obj, option, value)
811 else:
812 raise DistutilsOptionError, \
813 ("error in %s: command '%s' has no such option '%s'"
814 % (source, command_name, option))
815 except ValueError, msg:
816 raise DistutilsOptionError, msg
Greg Wardc32d9a62000-05-28 23:53:06 +0000817
Greg Wardf449ea52000-09-16 15:23:28 +0000818 def reinitialize_command (self, command, reinit_subcommands=0):
Greg Wardc32d9a62000-05-28 23:53:06 +0000819 """Reinitializes a command to the state it was in when first
820 returned by 'get_command_obj()': ie., initialized but not yet
Greg Ward7d9c7052000-06-28 01:25:27 +0000821 finalized. This provides the opportunity to sneak option
Greg Wardc32d9a62000-05-28 23:53:06 +0000822 values in programmatically, overriding or supplementing
823 user-supplied values from the config files and command line.
824 You'll have to re-finalize the command object (by calling
825 'finalize_options()' or 'ensure_finalized()') before using it for
826 real.
827
Greg Wardf449ea52000-09-16 15:23:28 +0000828 'command' should be a command name (string) or command object. If
829 'reinit_subcommands' is true, also reinitializes the command's
830 sub-commands, as declared by the 'sub_commands' class attribute (if
831 it has one). See the "install" command for an example. Only
832 reinitializes the sub-commands that actually matter, ie. those
833 whose test predicates return true.
834
Greg Wardc32d9a62000-05-28 23:53:06 +0000835 Returns the reinitialized command object.
836 """
837 from distutils.cmd import Command
838 if not isinstance(command, Command):
839 command_name = command
840 command = self.get_command_obj(command_name)
841 else:
842 command_name = command.get_command_name()
843
844 if not command.finalized:
Greg Ward282c7a02000-06-01 01:09:47 +0000845 return command
Greg Wardc32d9a62000-05-28 23:53:06 +0000846 command.initialize_options()
847 command.finalized = 0
Greg Ward43955c92000-06-06 02:52:36 +0000848 self.have_run[command_name] = 0
Greg Wardc32d9a62000-05-28 23:53:06 +0000849 self._set_command_options(command)
Greg Wardf449ea52000-09-16 15:23:28 +0000850
Greg Wardf449ea52000-09-16 15:23:28 +0000851 if reinit_subcommands:
Greg Wardf449ea52000-09-16 15:23:28 +0000852 for sub in command.get_sub_commands():
853 self.reinitialize_command(sub, reinit_subcommands)
854
Greg Wardc32d9a62000-05-28 23:53:06 +0000855 return command
856
Greg Wardfe6462c2000-04-04 01:40:52 +0000857
858 # -- Methods that operate on the Distribution ----------------------
859
860 def announce (self, msg, level=1):
861 """Print 'msg' if 'level' is greater than or equal to the verbosity
Greg Wardd5d8a992000-05-23 01:42:17 +0000862 level recorded in the 'verbose' attribute (which, currently, can be
863 only 0 or 1).
864 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000865 if self.verbose >= level:
866 print msg
867
868
869 def run_commands (self):
Greg Ward82715e12000-04-21 02:28:14 +0000870 """Run each command that was seen on the setup script command line.
Greg Wardd5d8a992000-05-23 01:42:17 +0000871 Uses the list of commands found and cache of command objects
Greg Wardfd7b91e2000-09-26 01:52:25 +0000872 created by 'get_command_obj()'.
873 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000874 for cmd in self.commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000875 self.run_command(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000876
877
Greg Wardfe6462c2000-04-04 01:40:52 +0000878 # -- Methods that operate on its Commands --------------------------
879
880 def run_command (self, command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000881 """Do whatever it takes to run a command (including nothing at all,
Greg Wardd5d8a992000-05-23 01:42:17 +0000882 if the command has already been run). Specifically: if we have
883 already created and run the command named by 'command', return
884 silently without doing anything. If the command named by 'command'
885 doesn't even have a command object yet, create one. Then invoke
886 'run()' on that command object (or an existing one).
887 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000888 # Already been here, done that? then return silently.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000889 if self.have_run.get(command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000890 return
891
Greg Wardfd7b91e2000-09-26 01:52:25 +0000892 self.announce("running " + command)
893 cmd_obj = self.get_command_obj(command)
894 cmd_obj.ensure_finalized()
895 cmd_obj.run()
Greg Wardfe6462c2000-04-04 01:40:52 +0000896 self.have_run[command] = 1
897
898
Greg Wardfe6462c2000-04-04 01:40:52 +0000899 # -- Distribution query methods ------------------------------------
900
901 def has_pure_modules (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000902 return len(self.packages or self.py_modules or []) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000903
904 def has_ext_modules (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000905 return self.ext_modules and len(self.ext_modules) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000906
907 def has_c_libraries (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000908 return self.libraries and len(self.libraries) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000909
910 def has_modules (self):
911 return self.has_pure_modules() or self.has_ext_modules()
912
Greg Ward51def7d2000-05-27 01:36:14 +0000913 def has_headers (self):
914 return self.headers and len(self.headers) > 0
915
Greg Ward44a61bb2000-05-20 15:06:48 +0000916 def has_scripts (self):
917 return self.scripts and len(self.scripts) > 0
918
919 def has_data_files (self):
920 return self.data_files and len(self.data_files) > 0
921
Greg Wardfe6462c2000-04-04 01:40:52 +0000922 def is_pure (self):
923 return (self.has_pure_modules() and
924 not self.has_ext_modules() and
925 not self.has_c_libraries())
926
Greg Ward82715e12000-04-21 02:28:14 +0000927 # -- Metadata query methods ----------------------------------------
928
929 # If you're looking for 'get_name()', 'get_version()', and so forth,
930 # they are defined in a sneaky way: the constructor binds self.get_XXX
931 # to self.metadata.get_XXX. The actual code is in the
932 # DistributionMetadata class, below.
933
934# class Distribution
935
936
937class DistributionMetadata:
938 """Dummy class to hold the distribution meta-data: name, version,
Greg Wardfd7b91e2000-09-26 01:52:25 +0000939 author, and so forth.
940 """
Greg Ward82715e12000-04-21 02:28:14 +0000941
942 def __init__ (self):
943 self.name = None
944 self.version = None
945 self.author = None
946 self.author_email = None
947 self.maintainer = None
948 self.maintainer_email = None
949 self.url = None
950 self.licence = None
951 self.description = None
Greg Warde5a584e2000-04-26 02:26:55 +0000952 self.long_description = None
Greg Ward82715e12000-04-21 02:28:14 +0000953
954 # -- Metadata query methods ----------------------------------------
955
Greg Wardfe6462c2000-04-04 01:40:52 +0000956 def get_name (self):
957 return self.name or "UNKNOWN"
958
Greg Ward82715e12000-04-21 02:28:14 +0000959 def get_version(self):
960 return self.version or "???"
Greg Wardfe6462c2000-04-04 01:40:52 +0000961
Greg Ward82715e12000-04-21 02:28:14 +0000962 def get_fullname (self):
963 return "%s-%s" % (self.get_name(), self.get_version())
964
965 def get_author(self):
966 return self.author or "UNKNOWN"
967
968 def get_author_email(self):
969 return self.author_email or "UNKNOWN"
970
971 def get_maintainer(self):
972 return self.maintainer or "UNKNOWN"
973
974 def get_maintainer_email(self):
975 return self.maintainer_email or "UNKNOWN"
976
977 def get_contact(self):
978 return (self.maintainer or
979 self.author or
980 "UNKNOWN")
981
982 def get_contact_email(self):
983 return (self.maintainer_email or
984 self.author_email or
985 "UNKNOWN")
986
987 def get_url(self):
988 return self.url or "UNKNOWN"
989
990 def get_licence(self):
991 return self.licence or "UNKNOWN"
992
993 def get_description(self):
994 return self.description or "UNKNOWN"
Greg Warde5a584e2000-04-26 02:26:55 +0000995
996 def get_long_description(self):
997 return self.long_description or "UNKNOWN"
998
Greg Ward82715e12000-04-21 02:28:14 +0000999# class DistributionMetadata
Greg Wardfe6462c2000-04-04 01:40:52 +00001000
Greg Ward2ff78872000-06-24 00:23:20 +00001001
1002def fix_help_options (options):
1003 """Convert a 4-tuple 'help_options' list as found in various command
1004 classes to the 3-tuple form required by FancyGetopt.
1005 """
1006 new_options = []
1007 for help_tuple in options:
1008 new_options.append(help_tuple[0:3])
1009 return new_options
1010
1011
Greg Wardfe6462c2000-04-04 01:40:52 +00001012if __name__ == "__main__":
Greg Wardfd7b91e2000-09-26 01:52:25 +00001013 dist = Distribution()
Greg Wardfe6462c2000-04-04 01:40:52 +00001014 print "ok"