blob: 41d5dbbc0b38e42e80d12e6cf20a2f4113c4693d [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
209 # __init__ ()
210
211
Greg Ward0e48cfd2000-05-26 01:00:15 +0000212 def get_option_dict (self, command):
213 """Get the option dictionary for a given command. If that
214 command's option dictionary hasn't been created yet, then create it
215 and return the new dictionary; otherwise, return the existing
216 option dictionary.
217 """
218
219 dict = self.command_options.get(command)
220 if dict is None:
221 dict = self.command_options[command] = {}
222 return dict
223
224
Greg Wardc32d9a62000-05-28 23:53:06 +0000225 def dump_option_dicts (self, header=None, commands=None, indent=""):
226 from pprint import pformat
227
228 if commands is None: # dump all command option dicts
229 commands = self.command_options.keys()
230 commands.sort()
231
232 if header is not None:
233 print indent + header
234 indent = indent + " "
235
236 if not commands:
237 print indent + "no commands known yet"
238 return
239
240 for cmd_name in commands:
241 opt_dict = self.command_options.get(cmd_name)
242 if opt_dict is None:
243 print indent + "no option dict for '%s' command" % cmd_name
244 else:
245 print indent + "option dict for '%s' command:" % cmd_name
246 out = pformat(opt_dict)
247 for line in string.split(out, "\n"):
248 print indent + " " + line
249
250 # dump_option_dicts ()
251
252
253
Greg Wardd5d8a992000-05-23 01:42:17 +0000254 # -- Config file finding/parsing methods ---------------------------
255
Gregory P. Smith14263542000-05-12 00:41:33 +0000256 def find_config_files (self):
257 """Find as many configuration files as should be processed for this
258 platform, and return a list of filenames in the order in which they
259 should be parsed. The filenames returned are guaranteed to exist
260 (modulo nasty race conditions).
261
262 On Unix, there are three possible config files: pydistutils.cfg in
263 the Distutils installation directory (ie. where the top-level
264 Distutils __inst__.py file lives), .pydistutils.cfg in the user's
265 home directory, and setup.cfg in the current directory.
266
267 On Windows and Mac OS, there are two possible config files:
268 pydistutils.cfg in the Python installation directory (sys.prefix)
Greg Wardd5d8a992000-05-23 01:42:17 +0000269 and setup.cfg in the current directory.
270 """
Gregory P. Smith14263542000-05-12 00:41:33 +0000271 files = []
Greg Wardacf3f6a2000-06-07 02:26:19 +0000272 check_environ()
Gregory P. Smith14263542000-05-12 00:41:33 +0000273
Greg Ward11696872000-06-07 02:29:03 +0000274 # Where to look for the system-wide Distutils config file
275 sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
276
277 # Look for the system config file
278 sys_file = os.path.join(sys_dir, "distutils.cfg")
Greg Wardacf3f6a2000-06-07 02:26:19 +0000279 if os.path.isfile(sys_file):
280 files.append(sys_file)
Gregory P. Smith14263542000-05-12 00:41:33 +0000281
Greg Ward11696872000-06-07 02:29:03 +0000282 # What to call the per-user config file
283 if os.name == 'posix':
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000284 user_filename = ".pydistutils.cfg"
285 else:
286 user_filename = "pydistutils.cfg"
Greg Wardfa9ff762000-10-14 04:06:40 +0000287
Greg Ward11696872000-06-07 02:29:03 +0000288 # And look for the user config file
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000289 if os.environ.has_key('HOME'):
290 user_file = os.path.join(os.environ.get('HOME'), user_filename)
Gregory P. Smith14263542000-05-12 00:41:33 +0000291 if os.path.isfile(user_file):
292 files.append(user_file)
293
Gregory P. Smith14263542000-05-12 00:41:33 +0000294 # All platforms support local setup.cfg
295 local_file = "setup.cfg"
296 if os.path.isfile(local_file):
297 files.append(local_file)
298
299 return files
300
301 # find_config_files ()
302
303
304 def parse_config_files (self, filenames=None):
305
306 from ConfigParser import ConfigParser
Greg Ward2bd3f422000-06-02 01:59:33 +0000307 from distutils.core import DEBUG
Gregory P. Smith14263542000-05-12 00:41:33 +0000308
309 if filenames is None:
310 filenames = self.find_config_files()
311
Greg Ward2bd3f422000-06-02 01:59:33 +0000312 if DEBUG: print "Distribution.parse_config_files():"
Greg Ward47460772000-05-23 03:47:35 +0000313
Gregory P. Smith14263542000-05-12 00:41:33 +0000314 parser = ConfigParser()
Greg Wardd5d8a992000-05-23 01:42:17 +0000315 for filename in filenames:
Greg Ward2bd3f422000-06-02 01:59:33 +0000316 if DEBUG: print " reading", filename
Greg Wardd5d8a992000-05-23 01:42:17 +0000317 parser.read(filename)
318 for section in parser.sections():
319 options = parser.options(section)
Greg Ward0e48cfd2000-05-26 01:00:15 +0000320 opt_dict = self.get_option_dict(section)
Gregory P. Smith14263542000-05-12 00:41:33 +0000321
Greg Wardd5d8a992000-05-23 01:42:17 +0000322 for opt in options:
323 if opt != '__name__':
Greg Wardceb9e222000-09-25 01:23:52 +0000324 val = parser.get(section,opt)
325 opt = string.replace(opt, '-', '_')
326 opt_dict[opt] = (filename, val)
Gregory P. Smith14263542000-05-12 00:41:33 +0000327
Greg Ward47460772000-05-23 03:47:35 +0000328 # Make the ConfigParser forget everything (so we retain
329 # the original filenames that options come from) -- gag,
330 # retch, puke -- another good reason for a distutils-
331 # specific config parser (sigh...)
332 parser.__init__()
Gregory P. Smith14263542000-05-12 00:41:33 +0000333
Greg Wardceb9e222000-09-25 01:23:52 +0000334 # If there was a "global" section in the config file, use it
335 # to set Distribution options.
336
337 if self.command_options.has_key('global'):
338 for (opt, (src, val)) in self.command_options['global'].items():
339 alias = self.negative_opt.get(opt)
340 try:
341 if alias:
342 setattr(self, alias, not strtobool(val))
343 elif opt in ('verbose', 'dry_run'): # ugh!
344 setattr(self, opt, strtobool(val))
345 except ValueError, msg:
346 raise DistutilsOptionError, msg
347
348 # parse_config_files ()
349
Gregory P. Smith14263542000-05-12 00:41:33 +0000350
Greg Wardd5d8a992000-05-23 01:42:17 +0000351 # -- Command-line parsing methods ----------------------------------
352
Greg Ward9821bf42000-08-29 01:15:18 +0000353 def parse_command_line (self):
354 """Parse the setup script's command line, taken from the
355 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
356 -- see 'setup()' in core.py). This list is first processed for
357 "global options" -- options that set attributes of the Distribution
358 instance. Then, it is alternately scanned for Distutils commands
359 and options for that command. Each new command terminates the
360 options for the previous command. The allowed options for a
361 command are determined by the 'user_options' attribute of the
362 command class -- thus, we have to be able to load command classes
363 in order to parse the command line. Any error in that 'options'
364 attribute raises DistutilsGetoptError; any error on the
365 command-line raises DistutilsArgError. If no Distutils commands
366 were found on the command line, raises DistutilsArgError. Return
Greg Wardceb9e222000-09-25 01:23:52 +0000367 true if command-line was successfully parsed and we should carry
Greg Ward9821bf42000-08-29 01:15:18 +0000368 on with executing commands; false if no errors but we shouldn't
369 execute commands (currently, this only happens if user asks for
370 help).
Greg Wardd5d8a992000-05-23 01:42:17 +0000371 """
Andrew M. Kuchling3f819ec2001-01-15 16:09:35 +0000372 #
373 # We now have enough information to show the Macintosh dialog that allows
374 # the user to interactively specify the "command line".
375 #
376 if sys.platform == 'mac':
377 import EasyDialogs
378 cmdlist = self.get_command_list()
379 self.script_args = EasyDialogs.GetArgv(
380 self.global_options + self.display_options, cmdlist)
381
Greg Wardfe6462c2000-04-04 01:40:52 +0000382 # We have to parse the command line a bit at a time -- global
383 # options, then the first command, then its options, and so on --
384 # because each command will be handled by a different class, and
Greg Wardd5d8a992000-05-23 01:42:17 +0000385 # the options that are valid for a particular class aren't known
386 # until we have loaded the command class, which doesn't happen
387 # until we know what the command is.
Greg Wardfe6462c2000-04-04 01:40:52 +0000388
389 self.commands = []
Greg Wardfd7b91e2000-09-26 01:52:25 +0000390 parser = FancyGetopt(self.global_options + self.display_options)
391 parser.set_negative_aliases(self.negative_opt)
392 parser.set_aliases({'license': 'licence'})
393 args = parser.getopt(args=self.script_args, object=self)
Greg Ward82715e12000-04-21 02:28:14 +0000394 option_order = parser.get_option_order()
Greg Wardfe6462c2000-04-04 01:40:52 +0000395
Greg Ward82715e12000-04-21 02:28:14 +0000396 # for display options we return immediately
397 if self.handle_display_options(option_order):
Greg Wardfe6462c2000-04-04 01:40:52 +0000398 return
399
400 while args:
Greg Wardd5d8a992000-05-23 01:42:17 +0000401 args = self._parse_command_opts(parser, args)
402 if args is None: # user asked for help (and got it)
Greg Wardfe6462c2000-04-04 01:40:52 +0000403 return
Greg Wardfe6462c2000-04-04 01:40:52 +0000404
Greg Wardd5d8a992000-05-23 01:42:17 +0000405 # Handle the cases of --help as a "global" option, ie.
406 # "setup.py --help" and "setup.py --help command ...". For the
407 # former, we show global options (--verbose, --dry-run, etc.)
408 # and display-only options (--name, --version, etc.); for the
409 # latter, we omit the display-only options and show help for
410 # each command listed on the command line.
Greg Wardfe6462c2000-04-04 01:40:52 +0000411 if self.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000412 self._show_help(parser,
413 display_options=len(self.commands) == 0,
414 commands=self.commands)
Greg Wardfe6462c2000-04-04 01:40:52 +0000415 return
416
417 # Oops, no commands found -- an end-user error
418 if not self.commands:
419 raise DistutilsArgError, "no commands supplied"
420
421 # All is well: return true
422 return 1
423
424 # parse_command_line()
425
Greg Wardd5d8a992000-05-23 01:42:17 +0000426 def _parse_command_opts (self, parser, args):
Greg Wardd5d8a992000-05-23 01:42:17 +0000427 """Parse the command-line options for a single command.
428 'parser' must be a FancyGetopt instance; 'args' must be the list
429 of arguments, starting with the current command (whose options
430 we are about to parse). Returns a new version of 'args' with
431 the next command at the front of the list; will be the empty
432 list if there are no more commands on the command line. Returns
433 None if the user asked for help on this command.
434 """
435 # late import because of mutual dependence between these modules
436 from distutils.cmd import Command
437
438 # Pull the current command from the head of the command line
439 command = args[0]
Greg Wardfd7b91e2000-09-26 01:52:25 +0000440 if not command_re.match(command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000441 raise SystemExit, "invalid command name '%s'" % command
Greg Wardfd7b91e2000-09-26 01:52:25 +0000442 self.commands.append(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000443
444 # Dig up the command class that implements this command, so we
445 # 1) know that it's a valid command, and 2) know which options
446 # it takes.
447 try:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000448 cmd_class = self.get_command_class(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000449 except DistutilsModuleError, msg:
450 raise DistutilsArgError, msg
451
452 # Require that the command class be derived from Command -- want
453 # to be sure that the basic "command" interface is implemented.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000454 if not issubclass(cmd_class, Command):
Greg Wardd5d8a992000-05-23 01:42:17 +0000455 raise DistutilsClassError, \
456 "command class %s must subclass Command" % cmd_class
457
458 # Also make sure that the command object provides a list of its
459 # known options.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000460 if not (hasattr(cmd_class, 'user_options') and
461 type(cmd_class.user_options) is ListType):
Greg Wardd5d8a992000-05-23 01:42:17 +0000462 raise DistutilsClassError, \
463 ("command class %s must provide " +
464 "'user_options' attribute (a list of tuples)") % \
465 cmd_class
466
467 # If the command class has a list of negative alias options,
468 # merge it in with the global negative aliases.
469 negative_opt = self.negative_opt
Greg Wardfd7b91e2000-09-26 01:52:25 +0000470 if hasattr(cmd_class, 'negative_opt'):
471 negative_opt = copy(negative_opt)
472 negative_opt.update(cmd_class.negative_opt)
Greg Wardd5d8a992000-05-23 01:42:17 +0000473
Greg Wardfa9ff762000-10-14 04:06:40 +0000474 # Check for help_options in command class. They have a different
475 # format (tuple of four) so we need to preprocess them here.
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000476 if (hasattr(cmd_class, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000477 type(cmd_class.help_options) is ListType):
Greg Ward2ff78872000-06-24 00:23:20 +0000478 help_options = fix_help_options(cmd_class.help_options)
479 else:
Greg Ward55fced32000-06-24 01:22:41 +0000480 help_options = []
Greg Ward2ff78872000-06-24 00:23:20 +0000481
Greg Ward9d17a7a2000-06-07 03:00:06 +0000482
Greg Wardd5d8a992000-05-23 01:42:17 +0000483 # All commands support the global options too, just by adding
484 # in 'global_options'.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000485 parser.set_option_table(self.global_options +
486 cmd_class.user_options +
487 help_options)
488 parser.set_negative_aliases(negative_opt)
489 (args, opts) = parser.getopt(args[1:])
Greg Ward47460772000-05-23 03:47:35 +0000490 if hasattr(opts, 'help') and opts.help:
Greg Wardd5d8a992000-05-23 01:42:17 +0000491 self._show_help(parser, display_options=0, commands=[cmd_class])
492 return
493
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000494 if (hasattr(cmd_class, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000495 type(cmd_class.help_options) is ListType):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000496 help_option_found=0
497 for (help_option, short, desc, func) in cmd_class.help_options:
498 if hasattr(opts, parser.get_attr_name(help_option)):
499 help_option_found=1
Greg Wardfa9ff762000-10-14 04:06:40 +0000500 #print "showing help for option %s of command %s" % \
Greg Ward2ff78872000-06-24 00:23:20 +0000501 # (help_option[0],cmd_class)
Greg Ward55fced32000-06-24 01:22:41 +0000502
503 if callable(func):
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000504 func()
Greg Ward55fced32000-06-24 01:22:41 +0000505 else:
506 raise DistutilsClassError, \
507 ("invalid help function %s for help option '%s': "
508 "must be a callable object (function, etc.)") % \
509 (`func`, help_option)
510
511 if help_option_found:
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000512 return
Greg Ward9d17a7a2000-06-07 03:00:06 +0000513
Greg Wardd5d8a992000-05-23 01:42:17 +0000514 # Put the options from the command-line into their official
515 # holding pen, the 'command_options' dictionary.
Greg Ward0e48cfd2000-05-26 01:00:15 +0000516 opt_dict = self.get_option_dict(command)
Greg Wardd5d8a992000-05-23 01:42:17 +0000517 for (name, value) in vars(opts).items():
Greg Ward0e48cfd2000-05-26 01:00:15 +0000518 opt_dict[name] = ("command line", value)
Greg Wardd5d8a992000-05-23 01:42:17 +0000519
520 return args
521
522 # _parse_command_opts ()
523
524
525 def _show_help (self,
526 parser,
527 global_options=1,
528 display_options=1,
529 commands=[]):
530 """Show help for the setup script command-line in the form of
531 several lists of command-line options. 'parser' should be a
532 FancyGetopt instance; do not expect it to be returned in the
533 same state, as its option table will be reset to make it
534 generate the correct help text.
535
536 If 'global_options' is true, lists the global options:
537 --verbose, --dry-run, etc. If 'display_options' is true, lists
538 the "display-only" options: --name, --version, etc. Finally,
539 lists per-command help for every command name or command class
540 in 'commands'.
541 """
542 # late import because of mutual dependence between these modules
Greg Ward9821bf42000-08-29 01:15:18 +0000543 from distutils.core import gen_usage
Greg Wardd5d8a992000-05-23 01:42:17 +0000544 from distutils.cmd import Command
545
546 if global_options:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000547 parser.set_option_table(self.global_options)
548 parser.print_help("Global options:")
Greg Wardd5d8a992000-05-23 01:42:17 +0000549 print
550
551 if display_options:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000552 parser.set_option_table(self.display_options)
553 parser.print_help(
Greg Wardd5d8a992000-05-23 01:42:17 +0000554 "Information display options (just display " +
555 "information, ignore any commands)")
556 print
557
558 for command in self.commands:
559 if type(command) is ClassType and issubclass(klass, Command):
560 klass = command
561 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000562 klass = self.get_command_class(command)
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000563 if (hasattr(klass, 'help_options') and
Greg Wardfd7b91e2000-09-26 01:52:25 +0000564 type(klass.help_options) is ListType):
565 parser.set_option_table(klass.user_options +
566 fix_help_options(klass.help_options))
Jeremy Hylton65d6edb2000-07-07 20:45:21 +0000567 else:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000568 parser.set_option_table(klass.user_options)
569 parser.print_help("Options for '%s' command:" % klass.__name__)
Greg Wardd5d8a992000-05-23 01:42:17 +0000570 print
571
Greg Ward9821bf42000-08-29 01:15:18 +0000572 print gen_usage(self.script_name)
Greg Wardd5d8a992000-05-23 01:42:17 +0000573 return
574
575 # _show_help ()
Greg Wardfa9ff762000-10-14 04:06:40 +0000576
Greg Wardd5d8a992000-05-23 01:42:17 +0000577
Greg Ward82715e12000-04-21 02:28:14 +0000578 def handle_display_options (self, option_order):
579 """If there were any non-global "display-only" options
Greg Wardd5d8a992000-05-23 01:42:17 +0000580 (--help-commands or the metadata display options) on the command
581 line, display the requested info and return true; else return
582 false.
583 """
Greg Ward9821bf42000-08-29 01:15:18 +0000584 from distutils.core import gen_usage
Greg Ward82715e12000-04-21 02:28:14 +0000585
586 # User just wants a list of commands -- we'll print it out and stop
587 # processing now (ie. if they ran "setup --help-commands foo bar",
588 # we ignore "foo bar").
589 if self.help_commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000590 self.print_commands()
Greg Ward82715e12000-04-21 02:28:14 +0000591 print
Greg Ward9821bf42000-08-29 01:15:18 +0000592 print gen_usage(self.script_name)
Greg Ward82715e12000-04-21 02:28:14 +0000593 return 1
594
595 # If user supplied any of the "display metadata" options, then
596 # display that metadata in the order in which the user supplied the
597 # metadata options.
598 any_display_options = 0
599 is_display_option = {}
600 for option in self.display_options:
601 is_display_option[option[0]] = 1
602
603 for (opt, val) in option_order:
604 if val and is_display_option.get(opt):
Greg Ward2f2b6c62000-09-25 01:58:07 +0000605 opt = translate_longopt(opt)
Greg Ward82715e12000-04-21 02:28:14 +0000606 print getattr(self.metadata, "get_"+opt)()
607 any_display_options = 1
608
609 return any_display_options
610
611 # handle_display_options()
Greg Wardfe6462c2000-04-04 01:40:52 +0000612
613 def print_command_list (self, commands, header, max_length):
614 """Print a subset of the list of all commands -- used by
Greg Wardd5d8a992000-05-23 01:42:17 +0000615 'print_commands()'.
616 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000617
618 print header + ":"
619
620 for cmd in commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000621 klass = self.cmdclass.get(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000622 if not klass:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000623 klass = self.get_command_class(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000624 try:
625 description = klass.description
626 except AttributeError:
627 description = "(no description available)"
628
629 print " %-*s %s" % (max_length, cmd, description)
630
631 # print_command_list ()
632
633
634 def print_commands (self):
Greg Wardd5d8a992000-05-23 01:42:17 +0000635 """Print out a help message listing all available commands with a
636 description of each. The list is divided into "standard commands"
637 (listed in distutils.command.__all__) and "extra commands"
638 (mentioned in self.cmdclass, but not a standard command). The
639 descriptions come from the command class attribute
640 'description'.
641 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000642
643 import distutils.command
644 std_commands = distutils.command.__all__
645 is_std = {}
646 for cmd in std_commands:
647 is_std[cmd] = 1
648
649 extra_commands = []
650 for cmd in self.cmdclass.keys():
651 if not is_std.get(cmd):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000652 extra_commands.append(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000653
654 max_length = 0
655 for cmd in (std_commands + extra_commands):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000656 if len(cmd) > max_length:
657 max_length = len(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000658
Greg Wardfd7b91e2000-09-26 01:52:25 +0000659 self.print_command_list(std_commands,
660 "Standard commands",
661 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000662 if extra_commands:
663 print
Greg Wardfd7b91e2000-09-26 01:52:25 +0000664 self.print_command_list(extra_commands,
665 "Extra commands",
666 max_length)
Greg Wardfe6462c2000-04-04 01:40:52 +0000667
668 # print_commands ()
Greg Wardfe6462c2000-04-04 01:40:52 +0000669
Greg Wardf6fc8752000-11-11 02:47:11 +0000670 def get_command_list (self):
671 """Get a list of (command, description) tuples.
672 The list is divided into "standard commands" (listed in
673 distutils.command.__all__) and "extra commands" (mentioned in
674 self.cmdclass, but not a standard command). The descriptions come
675 from the command class attribute 'description'.
676 """
677 # Currently this is only used on Mac OS, for the Mac-only GUI
678 # Distutils interface (by Jack Jansen)
679
680 import distutils.command
681 std_commands = distutils.command.__all__
682 is_std = {}
683 for cmd in std_commands:
684 is_std[cmd] = 1
685
686 extra_commands = []
687 for cmd in self.cmdclass.keys():
688 if not is_std.get(cmd):
689 extra_commands.append(cmd)
690
691 rv = []
692 for cmd in (std_commands + extra_commands):
693 klass = self.cmdclass.get(cmd)
694 if not klass:
695 klass = self.get_command_class(cmd)
696 try:
697 description = klass.description
698 except AttributeError:
699 description = "(no description available)"
700 rv.append((cmd, description))
701 return rv
Greg Wardfe6462c2000-04-04 01:40:52 +0000702
703 # -- Command class/object methods ----------------------------------
704
Greg Wardd5d8a992000-05-23 01:42:17 +0000705 def get_command_class (self, command):
706 """Return the class that implements the Distutils command named by
707 'command'. First we check the 'cmdclass' dictionary; if the
708 command is mentioned there, we fetch the class object from the
709 dictionary and return it. Otherwise we load the command module
710 ("distutils.command." + command) and fetch the command class from
711 the module. The loaded class is also stored in 'cmdclass'
712 to speed future calls to 'get_command_class()'.
Greg Wardfe6462c2000-04-04 01:40:52 +0000713
Gregory P. Smith14263542000-05-12 00:41:33 +0000714 Raises DistutilsModuleError if the expected module could not be
Greg Wardd5d8a992000-05-23 01:42:17 +0000715 found, or if that module does not define the expected class.
716 """
717 klass = self.cmdclass.get(command)
718 if klass:
719 return klass
Greg Wardfe6462c2000-04-04 01:40:52 +0000720
721 module_name = 'distutils.command.' + command
722 klass_name = command
723
724 try:
725 __import__ (module_name)
726 module = sys.modules[module_name]
727 except ImportError:
728 raise DistutilsModuleError, \
729 "invalid command '%s' (no module named '%s')" % \
730 (command, module_name)
731
732 try:
Greg Wardd5d8a992000-05-23 01:42:17 +0000733 klass = getattr(module, klass_name)
734 except AttributeError:
Greg Wardfe6462c2000-04-04 01:40:52 +0000735 raise DistutilsModuleError, \
736 "invalid command '%s' (no class '%s' in module '%s')" \
737 % (command, klass_name, module_name)
738
Greg Wardd5d8a992000-05-23 01:42:17 +0000739 self.cmdclass[command] = klass
Greg Wardfe6462c2000-04-04 01:40:52 +0000740 return klass
741
Greg Wardd5d8a992000-05-23 01:42:17 +0000742 # get_command_class ()
Greg Wardfe6462c2000-04-04 01:40:52 +0000743
Greg Wardd5d8a992000-05-23 01:42:17 +0000744 def get_command_obj (self, command, create=1):
745 """Return the command object for 'command'. Normally this object
Greg Ward612eb9f2000-07-27 02:13:20 +0000746 is cached on a previous call to 'get_command_obj()'; if no command
Greg Wardd5d8a992000-05-23 01:42:17 +0000747 object for 'command' is in the cache, then we either create and
748 return it (if 'create' is true) or return None.
749 """
Greg Ward2bd3f422000-06-02 01:59:33 +0000750 from distutils.core import DEBUG
Greg Wardd5d8a992000-05-23 01:42:17 +0000751 cmd_obj = self.command_obj.get(command)
Greg Wardfe6462c2000-04-04 01:40:52 +0000752 if not cmd_obj and create:
Greg Ward2bd3f422000-06-02 01:59:33 +0000753 if DEBUG:
754 print "Distribution.get_command_obj(): " \
755 "creating '%s' command object" % command
Greg Ward47460772000-05-23 03:47:35 +0000756
Greg Wardd5d8a992000-05-23 01:42:17 +0000757 klass = self.get_command_class(command)
Greg Ward47460772000-05-23 03:47:35 +0000758 cmd_obj = self.command_obj[command] = klass(self)
759 self.have_run[command] = 0
760
761 # Set any options that were supplied in config files
762 # or on the command line. (NB. support for error
763 # reporting is lame here: any errors aren't reported
764 # until 'finalize_options()' is called, which means
765 # we won't report the source of the error.)
766 options = self.command_options.get(command)
767 if options:
Greg Wardc32d9a62000-05-28 23:53:06 +0000768 self._set_command_options(cmd_obj, options)
Greg Wardfe6462c2000-04-04 01:40:52 +0000769
770 return cmd_obj
771
Greg Wardc32d9a62000-05-28 23:53:06 +0000772 def _set_command_options (self, command_obj, option_dict=None):
Greg Wardc32d9a62000-05-28 23:53:06 +0000773 """Set the options for 'command_obj' from 'option_dict'. Basically
774 this means copying elements of a dictionary ('option_dict') to
775 attributes of an instance ('command').
776
Greg Wardceb9e222000-09-25 01:23:52 +0000777 'command_obj' must be a Command instance. If 'option_dict' is not
Greg Wardc32d9a62000-05-28 23:53:06 +0000778 supplied, uses the standard option dictionary for this command
779 (from 'self.command_options').
780 """
781 from distutils.core import DEBUG
782
783 command_name = command_obj.get_command_name()
784 if option_dict is None:
785 option_dict = self.get_option_dict(command_name)
786
787 if DEBUG: print " setting options for '%s' command:" % command_name
788 for (option, (source, value)) in option_dict.items():
789 if DEBUG: print " %s = %s (from %s)" % (option, value, source)
Greg Wardceb9e222000-09-25 01:23:52 +0000790 try:
Greg Ward2f2b6c62000-09-25 01:58:07 +0000791 bool_opts = map(translate_longopt, command_obj.boolean_options)
Greg Wardceb9e222000-09-25 01:23:52 +0000792 except AttributeError:
793 bool_opts = []
794 try:
795 neg_opt = command_obj.negative_opt
796 except AttributeError:
797 neg_opt = {}
798
799 try:
Greg Ward2c08cf02000-09-27 00:15:37 +0000800 is_string = type(value) is StringType
801 if neg_opt.has_key(option) and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000802 setattr(command_obj, neg_opt[option], not strtobool(value))
Greg Ward2c08cf02000-09-27 00:15:37 +0000803 elif option in bool_opts and is_string:
Greg Wardceb9e222000-09-25 01:23:52 +0000804 setattr(command_obj, option, strtobool(value))
805 elif hasattr(command_obj, option):
806 setattr(command_obj, option, value)
807 else:
808 raise DistutilsOptionError, \
809 ("error in %s: command '%s' has no such option '%s'"
810 % (source, command_name, option))
811 except ValueError, msg:
812 raise DistutilsOptionError, msg
Greg Wardc32d9a62000-05-28 23:53:06 +0000813
Greg Wardf449ea52000-09-16 15:23:28 +0000814 def reinitialize_command (self, command, reinit_subcommands=0):
Greg Wardc32d9a62000-05-28 23:53:06 +0000815 """Reinitializes a command to the state it was in when first
816 returned by 'get_command_obj()': ie., initialized but not yet
Greg Ward7d9c7052000-06-28 01:25:27 +0000817 finalized. This provides the opportunity to sneak option
Greg Wardc32d9a62000-05-28 23:53:06 +0000818 values in programmatically, overriding or supplementing
819 user-supplied values from the config files and command line.
820 You'll have to re-finalize the command object (by calling
821 'finalize_options()' or 'ensure_finalized()') before using it for
822 real.
823
Greg Wardf449ea52000-09-16 15:23:28 +0000824 'command' should be a command name (string) or command object. If
825 'reinit_subcommands' is true, also reinitializes the command's
826 sub-commands, as declared by the 'sub_commands' class attribute (if
827 it has one). See the "install" command for an example. Only
828 reinitializes the sub-commands that actually matter, ie. those
829 whose test predicates return true.
830
Greg Wardc32d9a62000-05-28 23:53:06 +0000831 Returns the reinitialized command object.
832 """
833 from distutils.cmd import Command
834 if not isinstance(command, Command):
835 command_name = command
836 command = self.get_command_obj(command_name)
837 else:
838 command_name = command.get_command_name()
839
840 if not command.finalized:
Greg Ward282c7a02000-06-01 01:09:47 +0000841 return command
Greg Wardc32d9a62000-05-28 23:53:06 +0000842 command.initialize_options()
843 command.finalized = 0
Greg Ward43955c92000-06-06 02:52:36 +0000844 self.have_run[command_name] = 0
Greg Wardc32d9a62000-05-28 23:53:06 +0000845 self._set_command_options(command)
Greg Wardf449ea52000-09-16 15:23:28 +0000846
Greg Wardf449ea52000-09-16 15:23:28 +0000847 if reinit_subcommands:
Greg Wardf449ea52000-09-16 15:23:28 +0000848 for sub in command.get_sub_commands():
849 self.reinitialize_command(sub, reinit_subcommands)
850
Greg Wardc32d9a62000-05-28 23:53:06 +0000851 return command
852
Greg Wardfe6462c2000-04-04 01:40:52 +0000853
854 # -- Methods that operate on the Distribution ----------------------
855
856 def announce (self, msg, level=1):
857 """Print 'msg' if 'level' is greater than or equal to the verbosity
Greg Wardd5d8a992000-05-23 01:42:17 +0000858 level recorded in the 'verbose' attribute (which, currently, can be
859 only 0 or 1).
860 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000861 if self.verbose >= level:
862 print msg
863
864
865 def run_commands (self):
Greg Ward82715e12000-04-21 02:28:14 +0000866 """Run each command that was seen on the setup script command line.
Greg Wardd5d8a992000-05-23 01:42:17 +0000867 Uses the list of commands found and cache of command objects
Greg Wardfd7b91e2000-09-26 01:52:25 +0000868 created by 'get_command_obj()'.
869 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000870 for cmd in self.commands:
Greg Wardfd7b91e2000-09-26 01:52:25 +0000871 self.run_command(cmd)
Greg Wardfe6462c2000-04-04 01:40:52 +0000872
873
Greg Wardfe6462c2000-04-04 01:40:52 +0000874 # -- Methods that operate on its Commands --------------------------
875
876 def run_command (self, command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000877 """Do whatever it takes to run a command (including nothing at all,
Greg Wardd5d8a992000-05-23 01:42:17 +0000878 if the command has already been run). Specifically: if we have
879 already created and run the command named by 'command', return
880 silently without doing anything. If the command named by 'command'
881 doesn't even have a command object yet, create one. Then invoke
882 'run()' on that command object (or an existing one).
883 """
Greg Wardfe6462c2000-04-04 01:40:52 +0000884 # Already been here, done that? then return silently.
Greg Wardfd7b91e2000-09-26 01:52:25 +0000885 if self.have_run.get(command):
Greg Wardfe6462c2000-04-04 01:40:52 +0000886 return
887
Greg Wardfd7b91e2000-09-26 01:52:25 +0000888 self.announce("running " + command)
889 cmd_obj = self.get_command_obj(command)
890 cmd_obj.ensure_finalized()
891 cmd_obj.run()
Greg Wardfe6462c2000-04-04 01:40:52 +0000892 self.have_run[command] = 1
893
894
Greg Wardfe6462c2000-04-04 01:40:52 +0000895 # -- Distribution query methods ------------------------------------
896
897 def has_pure_modules (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000898 return len(self.packages or self.py_modules or []) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000899
900 def has_ext_modules (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000901 return self.ext_modules and len(self.ext_modules) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000902
903 def has_c_libraries (self):
Greg Wardfd7b91e2000-09-26 01:52:25 +0000904 return self.libraries and len(self.libraries) > 0
Greg Wardfe6462c2000-04-04 01:40:52 +0000905
906 def has_modules (self):
907 return self.has_pure_modules() or self.has_ext_modules()
908
Greg Ward51def7d2000-05-27 01:36:14 +0000909 def has_headers (self):
910 return self.headers and len(self.headers) > 0
911
Greg Ward44a61bb2000-05-20 15:06:48 +0000912 def has_scripts (self):
913 return self.scripts and len(self.scripts) > 0
914
915 def has_data_files (self):
916 return self.data_files and len(self.data_files) > 0
917
Greg Wardfe6462c2000-04-04 01:40:52 +0000918 def is_pure (self):
919 return (self.has_pure_modules() and
920 not self.has_ext_modules() and
921 not self.has_c_libraries())
922
Greg Ward82715e12000-04-21 02:28:14 +0000923 # -- Metadata query methods ----------------------------------------
924
925 # If you're looking for 'get_name()', 'get_version()', and so forth,
926 # they are defined in a sneaky way: the constructor binds self.get_XXX
927 # to self.metadata.get_XXX. The actual code is in the
928 # DistributionMetadata class, below.
929
930# class Distribution
931
932
933class DistributionMetadata:
934 """Dummy class to hold the distribution meta-data: name, version,
Greg Wardfd7b91e2000-09-26 01:52:25 +0000935 author, and so forth.
936 """
Greg Ward82715e12000-04-21 02:28:14 +0000937
938 def __init__ (self):
939 self.name = None
940 self.version = None
941 self.author = None
942 self.author_email = None
943 self.maintainer = None
944 self.maintainer_email = None
945 self.url = None
946 self.licence = None
947 self.description = None
Greg Warde5a584e2000-04-26 02:26:55 +0000948 self.long_description = None
Greg Ward82715e12000-04-21 02:28:14 +0000949
950 # -- Metadata query methods ----------------------------------------
951
Greg Wardfe6462c2000-04-04 01:40:52 +0000952 def get_name (self):
953 return self.name or "UNKNOWN"
954
Greg Ward82715e12000-04-21 02:28:14 +0000955 def get_version(self):
956 return self.version or "???"
Greg Wardfe6462c2000-04-04 01:40:52 +0000957
Greg Ward82715e12000-04-21 02:28:14 +0000958 def get_fullname (self):
959 return "%s-%s" % (self.get_name(), self.get_version())
960
961 def get_author(self):
962 return self.author or "UNKNOWN"
963
964 def get_author_email(self):
965 return self.author_email or "UNKNOWN"
966
967 def get_maintainer(self):
968 return self.maintainer or "UNKNOWN"
969
970 def get_maintainer_email(self):
971 return self.maintainer_email or "UNKNOWN"
972
973 def get_contact(self):
974 return (self.maintainer or
975 self.author or
976 "UNKNOWN")
977
978 def get_contact_email(self):
979 return (self.maintainer_email or
980 self.author_email or
981 "UNKNOWN")
982
983 def get_url(self):
984 return self.url or "UNKNOWN"
985
986 def get_licence(self):
987 return self.licence or "UNKNOWN"
988
989 def get_description(self):
990 return self.description or "UNKNOWN"
Greg Warde5a584e2000-04-26 02:26:55 +0000991
992 def get_long_description(self):
993 return self.long_description or "UNKNOWN"
994
Greg Ward82715e12000-04-21 02:28:14 +0000995# class DistributionMetadata
Greg Wardfe6462c2000-04-04 01:40:52 +0000996
Greg Ward2ff78872000-06-24 00:23:20 +0000997
998def fix_help_options (options):
999 """Convert a 4-tuple 'help_options' list as found in various command
1000 classes to the 3-tuple form required by FancyGetopt.
1001 """
1002 new_options = []
1003 for help_tuple in options:
1004 new_options.append(help_tuple[0:3])
1005 return new_options
1006
1007
Greg Wardfe6462c2000-04-04 01:40:52 +00001008if __name__ == "__main__":
Greg Wardfd7b91e2000-09-26 01:52:25 +00001009 dist = Distribution()
Greg Wardfe6462c2000-04-04 01:40:52 +00001010 print "ok"