annotate Lib/distutils/dist.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents f2538183d262
children d5071d9f7408
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.dist
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
2
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
3 Provides the Distribution class, which represents the module distribution
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
4 being built/installed/distributed.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
5 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
6
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
7 __revision__ = "$Id$"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
8
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
9 import sys, os, string, re
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
10 from types import *
25973
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
11
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
12 try:
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
13 import warnings
25975
b6478d463555 Catch only ImportError
Andrew M. Kuchling <amk@amk.ca>
parents: 25973
diff changeset
14 except ImportError:
25973
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
15 warnings = None
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
16
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
17 from distutils.errors import *
14832
54adb7b4f8c8 Change to use the new 'translate_longopt()' function from fancy_getopt, rather
Greg Ward <gward@python.net>
parents: 14827
diff changeset
18 from distutils.fancy_getopt import FancyGetopt, translate_longopt
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
19 from distutils.util import check_environ, strtobool, rfc822_escape
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
20 from distutils import log
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23681
diff changeset
21 from distutils.debug import DEBUG
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
22
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
23 # Encoding used for the PKG-INFO files
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
24 PKG_INFO_ENCODING = 'utf-8'
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
25
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
26 # Regex to define acceptable Distutils command names. This is not *quite*
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
27 # the same as a Python NAME -- I don't allow leading underscores. The fact
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
28 # that they're very similar is no coincidence; the default naming scheme is
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
29 # to look for a Python module named after the command.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
30 command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
31
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
32
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
33 class Distribution:
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
34 """The core of the Distutils. Most of the work hiding behind 'setup'
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
35 is really done within a Distribution instance, which farms the work out
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
36 to the Distutils commands specified on the command line.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
37
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
38 Setup scripts will almost never instantiate Distribution directly,
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
39 unless the 'setup()' function is totally inadequate to their needs.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
40 However, it is conceivable that a setup script might wish to subclass
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
41 Distribution for some specialized purpose, and then pass the subclass
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
42 to 'setup()' as the 'distclass' keyword argument. If so, it is
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
43 necessary to respect the expectations that 'setup' has of Distribution.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
44 See the code for 'setup()', in core.py, for details.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
45 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
46
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
47
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
48 # 'global_options' describes the command-line options that may be
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
49 # supplied to the setup script prior to any actual commands.
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
50 # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
51 # these global options. This list should be kept to a bare minimum,
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
52 # since every global option is also valid as a command option -- and we
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
53 # don't want to pollute the commands with too many options that they
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
54 # have minimal control over.
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
55 # The fourth entry for verbose means that it can be repeated.
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
56 global_options = [('verbose', 'v', "run verbosely (default)", 1),
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
57 ('quiet', 'q', "run quietly (turns verbosity off)"),
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
58 ('dry-run', 'n', "don't actually do anything"),
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
59 ('help', 'h', "show detailed help message"),
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
60 ]
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
61
34648
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
62 # 'common_usage' is a short (2-3 line) string describing the common
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
63 # usage of the setup script.
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
64 common_usage = """\
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
65 Common commands: (see '--help-commands' for more)
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
66
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
67 setup.py build will build the package underneath 'build/'
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
68 setup.py install will install the package
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
69 """
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
70
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
71 # options that are not propagated to the commands
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
72 display_options = [
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
73 ('help-commands', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
74 "list all available commands"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
75 ('name', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
76 "print package name"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
77 ('version', 'V',
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
78 "print package version"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
79 ('fullname', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
80 "print <package name>-<version>"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
81 ('author', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
82 "print the author's name"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
83 ('author-email', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
84 "print the author's email address"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
85 ('maintainer', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
86 "print the maintainer's name"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
87 ('maintainer-email', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
88 "print the maintainer's email address"),
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
89 ('contact', None,
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
90 "print the maintainer's name if known, else the author's"),
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
91 ('contact-email', None,
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
92 "print the maintainer's email address if known, else the author's"),
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
93 ('url', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
94 "print the URL for this package"),
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
95 ('license', None,
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
96 "print the license of the package"),
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
97 ('licence', None,
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
98 "alias for --license"),
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
99 ('description', None,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
100 "print the package description"),
12496
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
101 ('long-description', None,
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
102 "print the long package description"),
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
103 ('platforms', None,
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
104 "print the list of platforms"),
27048
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
105 ('classifiers', None,
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
106 "print the list of classifiers"),
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
107 ('keywords', None,
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
108 "print the list of keywords"),
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
109 ('provides', None,
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
110 "print the list of packages/modules provided"),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
111 ('requires', None,
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
112 "print the list of packages/modules required"),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
113 ('obsoletes', None,
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
114 "print the list of packages/modules made obsolete")
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
115 ]
14832
54adb7b4f8c8 Change to use the new 'translate_longopt()' function from fancy_getopt, rather
Greg Ward <gward@python.net>
parents: 14827
diff changeset
116 display_option_names = map(lambda x: translate_longopt(x[0]),
54adb7b4f8c8 Change to use the new 'translate_longopt()' function from fancy_getopt, rather
Greg Ward <gward@python.net>
parents: 14827
diff changeset
117 display_options)
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
118
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
119 # negative options are options that exclude other options
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
120 negative_opt = {'quiet': 'verbose'}
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
121
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
122
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
123 # -- Creation/initialization methods -------------------------------
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
124
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
125 def __init__ (self, attrs=None):
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
126 """Construct a new Distribution instance: initialize all the
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
127 attributes of a Distribution, and then use 'attrs' (a dictionary
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
128 mapping attribute names to values) to assign some of those
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
129 attributes their "real" values. (Any attributes not mentioned in
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
130 'attrs' will be assigned to some null value: 0, None, an empty list
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
131 or dictionary, etc.) Most importantly, initialize the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
132 'command_obj' attribute to the empty dictionary; this will be
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
133 filled in with real command objects by 'parse_command_line()'.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12811
diff changeset
134 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
135
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
136 # Default values for our command-line options
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
137 self.verbose = 1
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
138 self.dry_run = 0
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
139 self.help = 0
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
140 for attr in self.display_option_names:
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
141 setattr(self, attr, 0)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
142
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
143 # Store the distribution meta-data (name, version, author, and so
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
144 # forth) in a separate object -- we're getting to have enough
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
145 # information here (and enough command-line options) that it's
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
146 # worth it. Also delegate 'get_XXX()' methods to the 'metadata'
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
147 # object in a sneaky and underhanded (but efficient!) way.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
148 self.metadata = DistributionMetadata()
19669
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
149 for basename in self.metadata._METHOD_BASENAMES:
12448
e3bb239b2dbf Fix how we generate the meta-data query methods to include 'get_fullname()'
Greg Ward <gward@python.net>
parents: 12430
diff changeset
150 method_name = "get_" + basename
e3bb239b2dbf Fix how we generate the meta-data query methods to include 'get_fullname()'
Greg Ward <gward@python.net>
parents: 12430
diff changeset
151 setattr(self, method_name, getattr(self.metadata, method_name))
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
152
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
153 # 'cmdclass' maps command names to class objects, so we
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
154 # can 1) quickly figure out which class to instantiate when
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
155 # we need to create a new command object, and 2) have a way
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
156 # for the setup script to override command classes
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
157 self.cmdclass = {}
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
158
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
159 # 'command_packages' is a list of packages in which commands
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
160 # are searched for. The factory for command 'foo' is expected
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
161 # to be named 'foo' in the module 'foo' in one of the packages
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
162 # named here. This list is searched from the left; an error
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
163 # is raised if no named package provides the command being
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
164 # searched for. (Always access using get_command_packages().)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
165 self.command_packages = None
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
166
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
167 # 'script_name' and 'script_args' are usually set to sys.argv[0]
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
168 # and sys.argv[1:], but they can be overridden when the caller is
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
169 # not necessarily a setup script run from the command-line.
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
170 self.script_name = None
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
171 self.script_args = None
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
172
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
173 # 'command_options' is where we store command options between
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
174 # parsing them (from config files, the command-line, etc.) and when
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
175 # they are actually needed -- ie. when the command in question is
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
176 # instantiated. It is a dictionary of dictionaries of 2-tuples:
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
177 # command_options = { command_name : { option : (source, value) } }
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
178 self.command_options = {}
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
179
34805
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
180 # 'dist_files' is the list of (command, pyversion, file) that
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
181 # have been created by any dist commands run so far. This is
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
182 # filled regardless of whether the run is dry or not. pyversion
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
183 # gives sysconfig.get_python_version() if the dist file is
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
184 # specific to a Python version, 'any' if it is good for all
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
185 # Python versions on the target platform, and '' for a source
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
186 # file. pyversion should not be used to specify minimum or
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
187 # maximum required Python versions; use the metainfo for that
b8ff9bc023e6 Make dist_files a triple, with the Python target version included,
Martin v. Löwis <martin@v.loewis.de>
parents: 34793
diff changeset
188 # instead.
34793
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents: 34788
diff changeset
189 self.dist_files = []
3da21fdc2ee7 Add the upload command. Make all dist commands register their
Martin v. Löwis <martin@v.loewis.de>
parents: 34788
diff changeset
190
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
191 # These options are really the business of various commands, rather
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
192 # than of the Distribution itself. We provide aliases for them in
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
193 # Distribution as a convenience to the developer.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
194 self.packages = None
32328
f49471953689 Add support for package data.
Fred Drake <fdrake@acm.org>
parents: 31777
diff changeset
195 self.package_data = {}
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
196 self.package_dir = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
197 self.py_modules = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
198 self.libraries = None
12780
9335daa9ddd3 Support for the "install_headers" command: distribution option 'headers'
Greg Ward <gward@python.net>
parents: 12762
diff changeset
199 self.headers = None
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
200 self.ext_modules = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
201 self.ext_package = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
202 self.include_dirs = None
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
203 self.extra_path = None
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12673
diff changeset
204 self.scripts = None
12704
6059a9279d99 List data files are listed in the Distribution attribute 'data_files',
Gregory P. Smith <greg@mad-scientist.com>
parents: 12675
diff changeset
205 self.data_files = None
50637
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50366
diff changeset
206 self.password = ''
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
207
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
208 # And now initialize bookkeeping stuff that can't be supplied by
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
209 # the caller at all. 'command_obj' maps command names to
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
210 # Command instances -- that's how we enforce that every command
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
211 # class is a singleton.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
212 self.command_obj = {}
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
213
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
214 # 'have_run' maps command names to boolean values; it keeps track
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
215 # of whether we have actually run a particular command, to make it
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
216 # cheap to "run" a command whenever we think we might need to -- if
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
217 # it's already been done, no need for expensive filesystem
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
218 # operations, we just check the 'have_run' dictionary and carry on.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
219 # It's only safe to query 'have_run' for a command class that has
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
220 # been instantiated -- a false value will be inserted when the
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
221 # command object is created, and replaced with a true value when
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 13413
diff changeset
222 # the command is successfully run. Thus it's probably best to use
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
223 # '.get()' rather than a straight lookup.
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
224 self.have_run = {}
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
226 # Now we'll use the attrs dictionary (ultimately, keyword args from
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
227 # the setup script) to possibly override any or all of these
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
228 # distribution options.
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
229
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
230 if attrs:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
231 # Pull out the set of command options and work on them
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
232 # specifically. Note that this order guarantees that aliased
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
233 # command options will override any supplied redundantly
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
234 # through the general options dictionary.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
235 options = attrs.get('options')
50366
ad20b69b18b7 Merged revisions 68033 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 48981
diff changeset
236 if options is not None:
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
237 del attrs['options']
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
238 for (command, cmd_options) in options.items():
12762
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
239 opt_dict = self.get_option_dict(command)
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
240 for (opt, val) in cmd_options.items():
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
241 opt_dict[opt] = ("setup script", val)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
242
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34805
diff changeset
243 if 'licence' in attrs:
28155
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
244 attrs['license'] = attrs['licence']
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
245 del attrs['licence']
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
246 msg = "'licence' distribution option is deprecated; use 'license'"
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
247 if warnings is not None:
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
248 warnings.warn(msg)
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
249 else:
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
250 sys.stderr.write(msg + "\n")
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
251
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
252 # Now work on the rest of the attributes. Any attribute that's
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
253 # not already defined is invalid!
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
254 for (key,val) in attrs.items():
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
255 if hasattr(self.metadata, "set_" + key):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
256 getattr(self.metadata, "set_" + key)(val)
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
257 elif hasattr(self.metadata, key):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
258 setattr(self.metadata, key, val)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
259 elif hasattr(self, key):
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
260 setattr(self, key, val)
33745
74ceb6fcb432 oops. how did _that_ happen?
Anthony Baxter <anthonybaxter@gmail.com>
parents: 33744
diff changeset
261 else:
25973
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
262 msg = "Unknown distribution option: %s" % repr(key)
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
263 if warnings is not None:
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
264 warnings.warn(msg)
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
265 else:
a68c6d62fe78 Make the Distribution() constructor forgiving of unknown keyword
Andrew M. Kuchling <amk@amk.ca>
parents: 25212
diff changeset
266 sys.stderr.write(msg + "\n")
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
267
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
268 self.finalize_options()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
269
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
270 def get_option_dict(self, command):
12762
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
271 """Get the option dictionary for a given command. If that
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
272 command's option dictionary hasn't been created yet, then create it
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
273 and return the new dictionary; otherwise, return the existing
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
274 option dictionary.
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
275 """
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
276 dict = self.command_options.get(command)
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
277 if dict is None:
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
278 dict = self.command_options[command] = {}
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
279 return dict
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
280
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
281 def dump_option_dicts(self, header=None, commands=None, indent=""):
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
282 from pprint import pformat
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
283
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
284 if commands is None: # dump all command option dicts
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
285 commands = self.command_options.keys()
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
286 commands.sort()
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
287
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
288 if header is not None:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
289 print indent + header
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
290 indent = indent + " "
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
291
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
292 if not commands:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
293 print indent + "no commands known yet"
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
294 return
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
295
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
296 for cmd_name in commands:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
297 opt_dict = self.command_options.get(cmd_name)
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
298 if opt_dict is None:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
299 print indent + "no option dict for '%s' command" % cmd_name
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
300 else:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
301 print indent + "option dict for '%s' command:" % cmd_name
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
302 out = pformat(opt_dict)
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
303 for line in string.split(out, "\n"):
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
304 print indent + " " + line
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
305
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
306 # -- Config file finding/parsing methods ---------------------------
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
307
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
308 def find_config_files(self):
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
309 """Find as many configuration files as should be processed for this
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
310 platform, and return a list of filenames in the order in which they
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
311 should be parsed. The filenames returned are guaranteed to exist
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
312 (modulo nasty race conditions).
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
313
21257
08dbf6b3c316 [Bug #459270] Fix incorrect docstring
Andrew M. Kuchling <amk@amk.ca>
parents: 19669
diff changeset
314 There are three possible config files: distutils.cfg in the
08dbf6b3c316 [Bug #459270] Fix incorrect docstring
Andrew M. Kuchling <amk@amk.ca>
parents: 19669
diff changeset
315 Distutils installation directory (ie. where the top-level
08dbf6b3c316 [Bug #459270] Fix incorrect docstring
Andrew M. Kuchling <amk@amk.ca>
parents: 19669
diff changeset
316 Distutils __inst__.py file lives), a file in the user's home
08dbf6b3c316 [Bug #459270] Fix incorrect docstring
Andrew M. Kuchling <amk@amk.ca>
parents: 19669
diff changeset
317 directory named .pydistutils.cfg on Unix and pydistutils.cfg
08dbf6b3c316 [Bug #459270] Fix incorrect docstring
Andrew M. Kuchling <amk@amk.ca>
parents: 19669
diff changeset
318 on Windows/Mac, and setup.cfg in the current directory.
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
319 """
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
320 files = []
12867
e04649c3ced0 Patch from Rene Liebscher:
Greg Ward <gward@python.net>
parents: 12863
diff changeset
321 check_environ()
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
322
12868
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
323 # Where to look for the system-wide Distutils config file
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
324 sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
325
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
326 # Look for the system config file
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
327 sys_file = os.path.join(sys_dir, "distutils.cfg")
12867
e04649c3ced0 Patch from Rene Liebscher:
Greg Ward <gward@python.net>
parents: 12863
diff changeset
328 if os.path.isfile(sys_file):
e04649c3ced0 Patch from Rene Liebscher:
Greg Ward <gward@python.net>
parents: 12863
diff changeset
329 files.append(sys_file)
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
330
12868
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
331 # What to call the per-user config file
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
332 if os.name == 'posix':
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
333 user_filename = ".pydistutils.cfg"
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
334 else:
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
335 user_filename = "pydistutils.cfg"
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14886
diff changeset
336
12868
f4b487e35214 Always look for the system config file in the Distutils module directory,
Greg Ward <gward@python.net>
parents: 12867
diff changeset
337 # And look for the user config file
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
338 user_file = os.path.join(os.path.expanduser('~'), user_filename)
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
339 if os.path.isfile(user_file):
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
340 files.append(user_file)
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
341
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
342 # All platforms support local setup.cfg
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
343 local_file = "setup.cfg"
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
344 if os.path.isfile(local_file):
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
345 files.append(local_file)
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
346
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
347 return files
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
348
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
349 def parse_config_files(self, filenames=None):
47252
e534ee0a4cd0 ConfigParser renaming reversal part 3: move module into place and adapt imports.
Georg Brandl <georg@python.org>
parents: 47078
diff changeset
350 from ConfigParser import ConfigParser
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
351
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
352 if filenames is None:
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
353 filenames = self.find_config_files()
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
354
12826
7d2a0063e26d Only print debugging output if DEBUG true (and deleted some of the more
Greg Ward <gward@python.net>
parents: 12822
diff changeset
355 if DEBUG: print "Distribution.parse_config_files():"
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
356
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
357 parser = ConfigParser()
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
358 for filename in filenames:
12826
7d2a0063e26d Only print debugging output if DEBUG true (and deleted some of the more
Greg Ward <gward@python.net>
parents: 12822
diff changeset
359 if DEBUG: print " reading", filename
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
360 parser.read(filename)
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
361 for section in parser.sections():
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
362 options = parser.options(section)
12762
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
363 opt_dict = self.get_option_dict(section)
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
364
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
365 for opt in options:
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
366 if opt != '__name__':
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
367 val = parser.get(section,opt)
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
368 opt = string.replace(opt, '-', '_')
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
369 opt_dict[opt] = (filename, val)
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
370
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
371 # Make the ConfigParser forget everything (so we retain
31546
2c8a43063d82 commentary about how bad ConfigParser is doesn't help here, and the
Fred Drake <fdrake@acm.org>
parents: 31515
diff changeset
372 # the original filenames that options come from)
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
373 parser.__init__()
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
374
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
375 # If there was a "global" section in the config file, use it
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
376 # to set Distribution options.
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
377
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34805
diff changeset
378 if 'global' in self.command_options:
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
379 for (opt, (src, val)) in self.command_options['global'].items():
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
380 alias = self.negative_opt.get(opt)
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
381 try:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
382 if alias:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
383 setattr(self, alias, not strtobool(val))
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
384 elif opt in ('verbose', 'dry_run'): # ugh!
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
385 setattr(self, opt, strtobool(val))
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
386 else:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
387 setattr(self, opt, val)
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
388 except ValueError, msg:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
389 raise DistutilsOptionError, msg
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
390
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
391 # -- Command-line parsing methods ----------------------------------
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
392
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
393 def parse_command_line(self):
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
394 """Parse the setup script's command line, taken from the
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
395 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
396 -- see 'setup()' in core.py). This list is first processed for
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
397 "global options" -- options that set attributes of the Distribution
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
398 instance. Then, it is alternately scanned for Distutils commands
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
399 and options for that command. Each new command terminates the
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
400 options for the previous command. The allowed options for a
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
401 command are determined by the 'user_options' attribute of the
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
402 command class -- thus, we have to be able to load command classes
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
403 in order to parse the command line. Any error in that 'options'
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
404 attribute raises DistutilsGetoptError; any error on the
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
405 command-line raises DistutilsArgError. If no Distutils commands
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
406 were found on the command line, raises DistutilsArgError. Return
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
407 true if command-line was successfully parsed and we should carry
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
408 on with executing commands; false if no errors but we shouldn't
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
409 execute commands (currently, this only happens if user asks for
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
410 help).
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
411 """
15880
3ea10ee91e9c Fix from Jack Jansen for the Mac and the Metrowerks compiler, posted
Andrew M. Kuchling <amk@amk.ca>
parents: 15398
diff changeset
412 #
19139
4a8ab67773a9 Wrap a comment to fit in 80 columns.
Fred Drake <fdrake@acm.org>
parents: 19137
diff changeset
413 # We now have enough information to show the Macintosh dialog
4a8ab67773a9 Wrap a comment to fit in 80 columns.
Fred Drake <fdrake@acm.org>
parents: 19137
diff changeset
414 # that allows the user to interactively specify the "command line".
15880
3ea10ee91e9c Fix from Jack Jansen for the Mac and the Metrowerks compiler, posted
Andrew M. Kuchling <amk@amk.ca>
parents: 15398
diff changeset
415 #
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
416 toplevel_options = self._get_toplevel_options()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
417
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
418 # We have to parse the command line a bit at a time -- global
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
419 # options, then the first command, then its options, and so on --
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
420 # because each command will be handled by a different class, and
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
421 # the options that are valid for a particular class aren't known
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
422 # until we have loaded the command class, which doesn't happen
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
423 # until we know what the command is.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
424
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
425 self.commands = []
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
426 parser = FancyGetopt(toplevel_options + self.display_options)
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
427 parser.set_negative_aliases(self.negative_opt)
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
428 parser.set_aliases({'licence': 'license'})
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
429 args = parser.getopt(args=self.script_args, object=self)
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
430 option_order = parser.get_option_order()
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
431 log.set_verbosity(self.verbose)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
432
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
433 # for display options we return immediately
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
434 if self.handle_display_options(option_order):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
435 return
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
436 while args:
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
437 args = self._parse_command_opts(parser, args)
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
438 if args is None: # user asked for help (and got it)
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
439 return
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
440
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
441 # Handle the cases of --help as a "global" option, ie.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
442 # "setup.py --help" and "setup.py --help command ...". For the
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
443 # former, we show global options (--verbose, --dry-run, etc.)
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
444 # and display-only options (--name, --version, etc.); for the
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
445 # latter, we omit the display-only options and show help for
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
446 # each command listed on the command line.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
447 if self.help:
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
448 self._show_help(parser,
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
449 display_options=len(self.commands) == 0,
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
450 commands=self.commands)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
451 return
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
452
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
453 # Oops, no commands found -- an end-user error
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
454 if not self.commands:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
455 raise DistutilsArgError, "no commands supplied"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
456
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
457 # All is well: return true
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
458 return 1
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
459
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
460 def _get_toplevel_options(self):
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
461 """Return the non-display options recognized at the top level.
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
462
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
463 This includes options that are recognized *only* at the top
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
464 level as well as options recognized for commands.
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
465 """
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
466 return self.global_options + [
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
467 ("command-packages=", None,
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
468 "list of packages that provide distutils commands"),
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
469 ]
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
470
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
471 def _parse_command_opts(self, parser, args):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
472 """Parse the command-line options for a single command.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
473 'parser' must be a FancyGetopt instance; 'args' must be the list
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
474 of arguments, starting with the current command (whose options
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
475 we are about to parse). Returns a new version of 'args' with
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
476 the next command at the front of the list; will be the empty
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
477 list if there are no more commands on the command line. Returns
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
478 None if the user asked for help on this command.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
479 """
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
480 # late import because of mutual dependence between these modules
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
481 from distutils.cmd import Command
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
482
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
483 # Pull the current command from the head of the command line
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
484 command = args[0]
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
485 if not command_re.match(command):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
486 raise SystemExit, "invalid command name '%s'" % command
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
487 self.commands.append(command)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
488
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
489 # Dig up the command class that implements this command, so we
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
490 # 1) know that it's a valid command, and 2) know which options
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
491 # it takes.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
492 try:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
493 cmd_class = self.get_command_class(command)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
494 except DistutilsModuleError, msg:
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
495 raise DistutilsArgError, msg
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
496
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
497 # Require that the command class be derived from Command -- want
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
498 # to be sure that the basic "command" interface is implemented.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
499 if not issubclass(cmd_class, Command):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
500 raise DistutilsClassError, \
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
501 "command class %s must subclass Command" % cmd_class
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
502
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
503 # Also make sure that the command object provides a list of its
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
504 # known options.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
505 if not (hasattr(cmd_class, 'user_options') and
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
506 type(cmd_class.user_options) is ListType):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
507 raise DistutilsClassError, \
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
508 ("command class %s must provide " +
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
509 "'user_options' attribute (a list of tuples)") % \
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
510 cmd_class
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
511
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
512 # If the command class has a list of negative alias options,
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
513 # merge it in with the global negative aliases.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
514 negative_opt = self.negative_opt
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
515 if hasattr(cmd_class, 'negative_opt'):
54101
b4261da4ea50 Fix bootstrapping by removing uses of the copy module in distutils
Antoine Pitrou <solipsis@pitrou.net>
parents: 51799
diff changeset
516 negative_opt = negative_opt.copy()
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
517 negative_opt.update(cmd_class.negative_opt)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
518
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14886
diff changeset
519 # Check for help_options in command class. They have a different
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14886
diff changeset
520 # format (tuple of four) so we need to preprocess them here.
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
521 if (hasattr(cmd_class, 'help_options') and
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
522 type(cmd_class.help_options) is ListType):
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
523 help_options = fix_help_options(cmd_class.help_options)
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
524 else:
12998
86d498946868 More stylistic tweaks to the generic '--help-xxx' code.
Greg Ward <gward@python.net>
parents: 12997
diff changeset
525 help_options = []
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
526
12869
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12868
diff changeset
527
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
528 # All commands support the global options too, just by adding
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
529 # in 'global_options'.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
530 parser.set_option_table(self.global_options +
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
531 cmd_class.user_options +
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
532 help_options)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
533 parser.set_negative_aliases(negative_opt)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
534 (args, opts) = parser.getopt(args[1:])
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
535 if hasattr(opts, 'help') and opts.help:
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
536 self._show_help(parser, display_options=0, commands=[cmd_class])
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
537 return
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
538
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
539 if (hasattr(cmd_class, 'help_options') and
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
540 type(cmd_class.help_options) is ListType):
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
541 help_option_found=0
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
542 for (help_option, short, desc, func) in cmd_class.help_options:
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
543 if hasattr(opts, parser.get_attr_name(help_option)):
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
544 help_option_found=1
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14886
diff changeset
545 #print "showing help for option %s of command %s" % \
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
546 # (help_option[0],cmd_class)
12998
86d498946868 More stylistic tweaks to the generic '--help-xxx' code.
Greg Ward <gward@python.net>
parents: 12997
diff changeset
547
86d498946868 More stylistic tweaks to the generic '--help-xxx' code.
Greg Ward <gward@python.net>
parents: 12997
diff changeset
548 if callable(func):
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
549 func()
12998
86d498946868 More stylistic tweaks to the generic '--help-xxx' code.
Greg Ward <gward@python.net>
parents: 12997
diff changeset
550 else:
19139
4a8ab67773a9 Wrap a comment to fit in 80 columns.
Fred Drake <fdrake@acm.org>
parents: 19137
diff changeset
551 raise DistutilsClassError(
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28155
diff changeset
552 "invalid help function %r for help option '%s': "
19139
4a8ab67773a9 Wrap a comment to fit in 80 columns.
Fred Drake <fdrake@acm.org>
parents: 19137
diff changeset
553 "must be a callable object (function, etc.)"
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 28155
diff changeset
554 % (func, help_option))
12998
86d498946868 More stylistic tweaks to the generic '--help-xxx' code.
Greg Ward <gward@python.net>
parents: 12997
diff changeset
555
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
556 if help_option_found:
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
557 return
12869
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12868
diff changeset
558
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
559 # Put the options from the command-line into their official
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
560 # holding pen, the 'command_options' dictionary.
12762
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
561 opt_dict = self.get_option_dict(command)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
562 for (name, value) in vars(opts).items():
12762
9e1b8050de63 Factored out code for extracting-or-creating one of the option
Greg Ward <gward@python.net>
parents: 12735
diff changeset
563 opt_dict[name] = ("command line", value)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
564
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
565 return args
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
566
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
567 def finalize_options(self):
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
568 """Set final values for all the options on the Distribution
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
569 instance, analogous to the .finalize_options() method of Command
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
570 objects.
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
571 """
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
572 keywords = self.metadata.keywords
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
573 if keywords is not None:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
574 if type(keywords) is StringType:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
575 keywordlist = string.split(keywords, ',')
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
576 self.metadata.keywords = map(string.strip, keywordlist)
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
577
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
578 platforms = self.metadata.platforms
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
579 if platforms is not None:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
580 if type(platforms) is StringType:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
581 platformlist = string.split(platforms, ',')
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
582 self.metadata.platforms = map(string.strip, platformlist)
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
583
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
584 def _show_help(self, parser, global_options=1, display_options=1,
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
585 commands=[]):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
586 """Show help for the setup script command-line in the form of
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
587 several lists of command-line options. 'parser' should be a
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
588 FancyGetopt instance; do not expect it to be returned in the
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
589 same state, as its option table will be reset to make it
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
590 generate the correct help text.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
591
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
592 If 'global_options' is true, lists the global options:
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
593 --verbose, --dry-run, etc. If 'display_options' is true, lists
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
594 the "display-only" options: --name, --version, etc. Finally,
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
595 lists per-command help for every command name or command class
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
596 in 'commands'.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
597 """
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
598 # late import because of mutual dependence between these modules
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
599 from distutils.core import gen_usage
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
600 from distutils.cmd import Command
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
601
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
602 if global_options:
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
603 if display_options:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
604 options = self._get_toplevel_options()
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
605 else:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
606 options = self.global_options
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
607 parser.set_option_table(options)
34648
d48fa0afdcba Patch #1104111: Alter setup.py --help and --help-commands.
Martin v. Löwis <martin@v.loewis.de>
parents: 33965
diff changeset
608 parser.print_help(self.common_usage + "\nGlobal options:")
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
609 print
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
610
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
611 if display_options:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
612 parser.set_option_table(self.display_options)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
613 parser.print_help(
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
614 "Information display options (just display " +
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
615 "information, ignore any commands)")
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
616 print
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
617
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
618 for command in self.commands:
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
619 if type(command) is ClassType and issubclass(command, Command):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
620 klass = command
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
621 else:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
622 klass = self.get_command_class(command)
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
623 if (hasattr(klass, 'help_options') and
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
624 type(klass.help_options) is ListType):
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
625 parser.set_option_table(klass.user_options +
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
626 fix_help_options(klass.help_options))
13413
7fea4a1af090 fix inconsistent use of tabs and spaces
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13044
diff changeset
627 else:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
628 parser.set_option_table(klass.user_options)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
629 parser.print_help("Options for '%s' command:" % klass.__name__)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
630 print
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
631
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
632 print gen_usage(self.script_name)
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
633 return
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
634
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
635 def handle_display_options(self, option_order):
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
636 """If there were any non-global "display-only" options
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
637 (--help-commands or the metadata display options) on the command
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
638 line, display the requested info and return true; else return
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
639 false.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
640 """
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
641 from distutils.core import gen_usage
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
642
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
643 # User just wants a list of commands -- we'll print it out and stop
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
644 # processing now (ie. if they ran "setup --help-commands foo bar",
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
645 # we ignore "foo bar").
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
646 if self.help_commands:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
647 self.print_commands()
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
648 print
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
649 print gen_usage(self.script_name)
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
650 return 1
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
651
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
652 # If user supplied any of the "display metadata" options, then
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
653 # display that metadata in the order in which the user supplied the
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
654 # metadata options.
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
655 any_display_options = 0
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
656 is_display_option = {}
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
657 for option in self.display_options:
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
658 is_display_option[option[0]] = 1
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
659
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
660 for (opt, val) in option_order:
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
661 if val and is_display_option.get(opt):
14832
54adb7b4f8c8 Change to use the new 'translate_longopt()' function from fancy_getopt, rather
Greg Ward <gward@python.net>
parents: 14827
diff changeset
662 opt = translate_longopt(opt)
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
663 value = getattr(self.metadata, "get_"+opt)()
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
664 if opt in ['keywords', 'platforms']:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
665 print string.join(value, ',')
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
666 elif opt in ('classifiers', 'provides', 'requires',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
667 'obsoletes'):
27048
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
668 print string.join(value, '\n')
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
669 else:
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
670 print value
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
671 any_display_options = 1
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
672
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
673 return any_display_options
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
674
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
675 def print_command_list(self, commands, header, max_length):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
676 """Print a subset of the list of all commands -- used by
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
677 'print_commands()'.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
678 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
679 print header + ":"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
680
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
681 for cmd in commands:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
682 klass = self.cmdclass.get(cmd)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
683 if not klass:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
684 klass = self.get_command_class(cmd)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
685 try:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
686 description = klass.description
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
687 except AttributeError:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
688 description = "(no description available)"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
689
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
690 print " %-*s %s" % (max_length, cmd, description)
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
691
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
692 def print_commands(self):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
693 """Print out a help message listing all available commands with a
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
694 description of each. The list is divided into "standard commands"
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
695 (listed in distutils.command.__all__) and "extra commands"
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
696 (mentioned in self.cmdclass, but not a standard command). The
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
697 descriptions come from the command class attribute
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
698 'description'.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
699 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
700 import distutils.command
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
701 std_commands = distutils.command.__all__
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
702 is_std = {}
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
703 for cmd in std_commands:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
704 is_std[cmd] = 1
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
705
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
706 extra_commands = []
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
707 for cmd in self.cmdclass.keys():
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
708 if not is_std.get(cmd):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
709 extra_commands.append(cmd)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
710
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
711 max_length = 0
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
712 for cmd in (std_commands + extra_commands):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
713 if len(cmd) > max_length:
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
714 max_length = len(cmd)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
715
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
716 self.print_command_list(std_commands,
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
717 "Standard commands",
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
718 max_length)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
719 if extra_commands:
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
720 print
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
721 self.print_command_list(extra_commands,
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
722 "Extra commands",
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
723 max_length)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
724
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
725 def get_command_list(self):
15398
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
726 """Get a list of (command, description) tuples.
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
727 The list is divided into "standard commands" (listed in
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
728 distutils.command.__all__) and "extra commands" (mentioned in
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
729 self.cmdclass, but not a standard command). The descriptions come
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
730 from the command class attribute 'description'.
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
731 """
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
732 # Currently this is only used on Mac OS, for the Mac-only GUI
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
733 # Distutils interface (by Jack Jansen)
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
734
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
735 import distutils.command
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
736 std_commands = distutils.command.__all__
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
737 is_std = {}
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
738 for cmd in std_commands:
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
739 is_std[cmd] = 1
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
740
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
741 extra_commands = []
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
742 for cmd in self.cmdclass.keys():
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
743 if not is_std.get(cmd):
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
744 extra_commands.append(cmd)
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
745
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
746 rv = []
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
747 for cmd in (std_commands + extra_commands):
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
748 klass = self.cmdclass.get(cmd)
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
749 if not klass:
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
750 klass = self.get_command_class(cmd)
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
751 try:
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
752 description = klass.description
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
753 except AttributeError:
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
754 description = "(no description available)"
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
755 rv.append((cmd, description))
3ab7faae803a Jack Jansen: added 'get_command_list()' method, and Mac-specific code to
Greg Ward <gward@python.net>
parents: 15216
diff changeset
756 return rv
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
757
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
758 # -- Command class/object methods ----------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
759
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
760 def get_command_packages(self):
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
761 """Return a list of packages from which commands are loaded."""
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
762 pkgs = self.command_packages
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
763 if not isinstance(pkgs, type([])):
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
764 pkgs = string.split(pkgs or "", ",")
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
765 for i in range(len(pkgs)):
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
766 pkgs[i] = string.strip(pkgs[i])
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
767 pkgs = filter(None, pkgs)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
768 if "distutils.command" not in pkgs:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
769 pkgs.insert(0, "distutils.command")
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
770 self.command_packages = pkgs
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
771 return pkgs
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
772
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
773 def get_command_class(self, command):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
774 """Return the class that implements the Distutils command named by
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
775 'command'. First we check the 'cmdclass' dictionary; if the
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
776 command is mentioned there, we fetch the class object from the
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
777 dictionary and return it. Otherwise we load the command module
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
778 ("distutils.command." + command) and fetch the command class from
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
779 the module. The loaded class is also stored in 'cmdclass'
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
780 to speed future calls to 'get_command_class()'.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
781
12673
5646773320be Preliminary support for config files:
Gregory P. Smith <greg@mad-scientist.com>
parents: 12602
diff changeset
782 Raises DistutilsModuleError if the expected module could not be
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
783 found, or if that module does not define the expected class.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
784 """
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
785 klass = self.cmdclass.get(command)
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
786 if klass:
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
787 return klass
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
788
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
789 for pkgname in self.get_command_packages():
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
790 module_name = "%s.%s" % (pkgname, command)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
791 klass_name = command
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
792
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
793 try:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
794 __import__ (module_name)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
795 module = sys.modules[module_name]
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
796 except ImportError:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
797 continue
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
798
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
799 try:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
800 klass = getattr(module, klass_name)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
801 except AttributeError:
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
802 raise DistutilsModuleError, \
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
803 "invalid command '%s' (no class '%s' in module '%s')" \
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
804 % (command, klass_name, module_name)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
805
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
806 self.cmdclass[command] = klass
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
807 return klass
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
808
32938
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
809 raise DistutilsModuleError("invalid command '%s'" % command)
8ce344f6c954 This allows additional commands to be provided for existing setup.py
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
810
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
811
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
812 def get_command_obj(self, command, create=1):
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
813 """Return the command object for 'command'. Normally this object
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 13413
diff changeset
814 is cached on a previous call to 'get_command_obj()'; if no command
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
815 object for 'command' is in the cache, then we either create and
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
816 return it (if 'create' is true) or return None.
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
817 """
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
818 cmd_obj = self.command_obj.get(command)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
819 if not cmd_obj and create:
12826
7d2a0063e26d Only print debugging output if DEBUG true (and deleted some of the more
Greg Ward <gward@python.net>
parents: 12822
diff changeset
820 if DEBUG:
7d2a0063e26d Only print debugging output if DEBUG true (and deleted some of the more
Greg Ward <gward@python.net>
parents: 12822
diff changeset
821 print "Distribution.get_command_obj(): " \
7d2a0063e26d Only print debugging output if DEBUG true (and deleted some of the more
Greg Ward <gward@python.net>
parents: 12822
diff changeset
822 "creating '%s' command object" % command
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
823
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
824 klass = self.get_command_class(command)
12732
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
825 cmd_obj = self.command_obj[command] = klass(self)
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
826 self.have_run[command] = 0
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
827
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
828 # Set any options that were supplied in config files
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
829 # or on the command line. (NB. support for error
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
830 # reporting is lame here: any errors aren't reported
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
831 # until 'finalize_options()' is called, which means
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
832 # we won't report the source of the error.)
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
833 options = self.command_options.get(command)
7954ff93ee3b Fixed so options from config files and command lines actually work:
Greg Ward <gward@python.net>
parents: 12726
diff changeset
834 if options:
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
835 self._set_command_options(cmd_obj, options)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
836
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
837 return cmd_obj
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
838
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
839 def _set_command_options(self, command_obj, option_dict=None):
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
840 """Set the options for 'command_obj' from 'option_dict'. Basically
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
841 this means copying elements of a dictionary ('option_dict') to
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
842 attributes of an instance ('command').
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
843
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
844 'command_obj' must be a Command instance. If 'option_dict' is not
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
845 supplied, uses the standard option dictionary for this command
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
846 (from 'self.command_options').
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
847 """
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
848 command_name = command_obj.get_command_name()
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
849 if option_dict is None:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
850 option_dict = self.get_option_dict(command_name)
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
851
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
852 if DEBUG: print " setting options for '%s' command:" % command_name
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
853 for (option, (source, value)) in option_dict.items():
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
854 if DEBUG: print " %s = %s (from %s)" % (option, value, source)
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
855 try:
14832
54adb7b4f8c8 Change to use the new 'translate_longopt()' function from fancy_getopt, rather
Greg Ward <gward@python.net>
parents: 14827
diff changeset
856 bool_opts = map(translate_longopt, command_obj.boolean_options)
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
857 except AttributeError:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
858 bool_opts = []
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
859 try:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
860 neg_opt = command_obj.negative_opt
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
861 except AttributeError:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
862 neg_opt = {}
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
863
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
864 try:
14886
f657930fd274 Fix '_set_command_options()' so it only calls 'strtobool()' on strings
Greg Ward <gward@python.net>
parents: 14859
diff changeset
865 is_string = type(value) is StringType
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34805
diff changeset
866 if option in neg_opt and is_string:
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
867 setattr(command_obj, neg_opt[option], not strtobool(value))
14886
f657930fd274 Fix '_set_command_options()' so it only calls 'strtobool()' on strings
Greg Ward <gward@python.net>
parents: 14859
diff changeset
868 elif option in bool_opts and is_string:
14827
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
869 setattr(command_obj, option, strtobool(value))
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
870 elif hasattr(command_obj, option):
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
871 setattr(command_obj, option, value)
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
872 else:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
873 raise DistutilsOptionError, \
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
874 ("error in %s: command '%s' has no such option '%s'"
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
875 % (source, command_name, option))
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
876 except ValueError, msg:
b1a0fb554456 Fixed some bugs and mis-features in handling config files:
Greg Ward <gward@python.net>
parents: 14629
diff changeset
877 raise DistutilsOptionError, msg
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
878
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
879 def reinitialize_command(self, command, reinit_subcommands=0):
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
880 """Reinitializes a command to the state it was in when first
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
881 returned by 'get_command_obj()': ie., initialized but not yet
13044
0d309f7f023f Typo fix.
Greg Ward <gward@python.net>
parents: 12998
diff changeset
882 finalized. This provides the opportunity to sneak option
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
883 values in programmatically, overriding or supplementing
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
884 user-supplied values from the config files and command line.
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
885 You'll have to re-finalize the command object (by calling
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
886 'finalize_options()' or 'ensure_finalized()') before using it for
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
887 real.
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
888
14627
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
889 'command' should be a command name (string) or command object. If
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
890 'reinit_subcommands' is true, also reinitializes the command's
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
891 sub-commands, as declared by the 'sub_commands' class attribute (if
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
892 it has one). See the "install" command for an example. Only
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
893 reinitializes the sub-commands that actually matter, ie. those
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
894 whose test predicates return true.
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
895
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
896 Returns the reinitialized command object.
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
897 """
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
898 from distutils.cmd import Command
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
899 if not isinstance(command, Command):
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
900 command_name = command
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
901 command = self.get_command_obj(command_name)
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
902 else:
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
903 command_name = command.get_command_name()
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
904
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
905 if not command.finalized:
12811
b12ada2eb312 Oops, 'reinitialize_command()' forgot to return the command object if didn't
Greg Ward <gward@python.net>
parents: 12788
diff changeset
906 return command
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
907 command.initialize_options()
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
908 command.finalized = 0
12863
c0fd88f2a65a Fix 'reinitialize_command()' so it resets the 'have_run' flag for the
Greg Ward <gward@python.net>
parents: 12826
diff changeset
909 self.have_run[command_name] = 0
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
910 self._set_command_options(command)
14627
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
911
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
912 if reinit_subcommands:
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
913 for sub in command.get_sub_commands():
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
914 self.reinitialize_command(sub, reinit_subcommands)
14627
40595017a992 Generalized 'reinitialize_command()' so it can optionally reinitialize
Greg Ward <gward@python.net>
parents: 14237
diff changeset
915
12788
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
916 return command
8004d29c77b8 Factored '_set_command_options()' out of 'get_command_obj()'.
Greg Ward <gward@python.net>
parents: 12783
diff changeset
917
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
918 # -- Methods that operate on the Distribution ----------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
919
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
920 def announce(self, msg, level=1):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
921 log.debug(msg)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
922
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
923 def run_commands(self):
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
924 """Run each command that was seen on the setup script command line.
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
925 Uses the list of commands found and cache of command objects
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
926 created by 'get_command_obj()'.
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
927 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
928 for cmd in self.commands:
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
929 self.run_command(cmd)
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
930
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
931 # -- Methods that operate on its Commands --------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
932
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
933 def run_command(self, command):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
934 """Do whatever it takes to run a command (including nothing at all,
12726
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
935 if the command has already been run). Specifically: if we have
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
936 already created and run the command named by 'command', return
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
937 silently without doing anything. If the command named by 'command'
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
938 doesn't even have a command object yet, create one. Then invoke
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
939 'run()' on that command object (or an existing one).
5dd3b35bfd52 Marching towards full support of config files: thoroughly overhauled the
Greg Ward <gward@python.net>
parents: 12720
diff changeset
940 """
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
941 # Already been here, done that? then return silently.
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
942 if self.have_run.get(command):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
943 return
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
944
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
945 log.info("running %s", command)
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
946 cmd_obj = self.get_command_obj(command)
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
947 cmd_obj.ensure_finalized()
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
948 cmd_obj.run()
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
949 self.have_run[command] = 1
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
950
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
951
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
952 # -- Distribution query methods ------------------------------------
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
953
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
954 def has_pure_modules(self):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
955 return len(self.packages or self.py_modules or []) > 0
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
956
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
957 def has_ext_modules(self):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
958 return self.ext_modules and len(self.ext_modules) > 0
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
959
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
960 def has_c_libraries(self):
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
961 return self.libraries and len(self.libraries) > 0
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
962
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
963 def has_modules(self):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
964 return self.has_pure_modules() or self.has_ext_modules()
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
965
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
966 def has_headers(self):
12780
9335daa9ddd3 Support for the "install_headers" command: distribution option 'headers'
Greg Ward <gward@python.net>
parents: 12762
diff changeset
967 return self.headers and len(self.headers) > 0
9335daa9ddd3 Support for the "install_headers" command: distribution option 'headers'
Greg Ward <gward@python.net>
parents: 12762
diff changeset
968
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
969 def has_scripts(self):
12720
2ea98d9dc669 Added 'has_scripts()', 'has_data_files()' methods.
Greg Ward <gward@python.net>
parents: 12719
diff changeset
970 return self.scripts and len(self.scripts) > 0
2ea98d9dc669 Added 'has_scripts()', 'has_data_files()' methods.
Greg Ward <gward@python.net>
parents: 12719
diff changeset
971
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
972 def has_data_files(self):
12720
2ea98d9dc669 Added 'has_scripts()', 'has_data_files()' methods.
Greg Ward <gward@python.net>
parents: 12719
diff changeset
973 return self.data_files and len(self.data_files) > 0
2ea98d9dc669 Added 'has_scripts()', 'has_data_files()' methods.
Greg Ward <gward@python.net>
parents: 12719
diff changeset
974
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
975 def is_pure(self):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
976 return (self.has_pure_modules() and
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
977 not self.has_ext_modules() and
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
978 not self.has_c_libraries())
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
979
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
980 # -- Metadata query methods ----------------------------------------
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
981
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
982 # If you're looking for 'get_name()', 'get_version()', and so forth,
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
983 # they are defined in a sneaky way: the constructor binds self.get_XXX
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
984 # to self.metadata.get_XXX. The actual code is in the
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
985 # DistributionMetadata class, below.
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
986
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
987 class DistributionMetadata:
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
988 """Dummy class to hold the distribution meta-data: name, version,
14859
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
989 author, and so forth.
e97660d1f1aa Standardize whitespace in function calls and docstrings.
Greg Ward <gward@python.net>
parents: 14832
diff changeset
990 """
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
991
19669
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
992 _METHOD_BASENAMES = ("name", "version", "author", "author_email",
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
993 "maintainer", "maintainer_email", "url",
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
994 "license", "description", "long_description",
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
995 "keywords", "platforms", "fullname", "contact",
28155
178d19cff163 [Bug #693470] 'licence' as an alias for 'license' doesn't work.
Andrew M. Kuchling <amk@amk.ca>
parents: 27975
diff changeset
996 "contact_email", "license", "classifiers",
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
997 "download_url",
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
998 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
999 "provides", "requires", "obsoletes",
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1000 )
19669
87e8fc0a9862 Don't use dir() to find instance attribute names.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 19139
diff changeset
1001
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1002 def __init__ (self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1003 self.name = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1004 self.version = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1005 self.author = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1006 self.author_email = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1007 self.maintainer = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1008 self.maintainer_email = None
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1009 self.url = None
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
1010 self.license = None
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1011 self.description = None
12496
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
1012 self.long_description = None
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1013 self.keywords = None
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1014 self.platforms = None
27048
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
1015 self.classifiers = None
27975
cc95bb7870dc [Patch #683939] Add download_url field to metadata
Andrew M. Kuchling <amk@amk.ca>
parents: 27048
diff changeset
1016 self.download_url = None
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1017 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1018 self.provides = None
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1019 self.requires = None
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1020 self.obsoletes = None
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
1021
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1022 def write_pkg_info(self, base_dir):
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1023 """Write the PKG-INFO file into the release tree.
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1024 """
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1025 pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w')
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1026 self.write_pkg_file(pkg_info)
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1027 pkg_info.close()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
1028
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1029 def write_pkg_file(self, file):
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1030 """Write the PKG-INFO format data to a file object.
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1031 """
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1032 version = '1.0'
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1033 if self.provides or self.requires or self.obsoletes:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1034 version = '1.1'
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1035
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1036 self._write_field(file, 'Metadata-Version', version)
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1037 self._write_field(file, 'Name', self.get_name())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1038 self._write_field(file, 'Version', self.get_version())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1039 self._write_field(file, 'Summary', self.get_description())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1040 self._write_field(file, 'Home-page', self.get_url())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1041 self._write_field(file, 'Author', self.get_contact())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1042 self._write_field(file, 'Author-email', self.get_contact_email())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1043 self._write_field(file, 'License', self.get_license())
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1044 if self.download_url:
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1045 self._write_field(file, 'Download-URL', self.download_url)
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1046
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1047 long_desc = rfc822_escape( self.get_long_description())
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1048 self._write_field(file, 'Description', long_desc)
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1049
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1050 keywords = string.join( self.get_keywords(), ',')
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1051 if keywords:
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1052 self._write_field(file, 'Keywords', keywords)
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1053
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1054 self._write_list(file, 'Platform', self.get_platforms())
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1055 self._write_list(file, 'Classifier', self.get_classifiers())
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1056
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1057 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1058 self._write_list(file, 'Requires', self.get_requires())
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1059 self._write_list(file, 'Provides', self.get_provides())
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1060 self._write_list(file, 'Obsoletes', self.get_obsoletes())
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1061
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1062 def _write_field(self, file, name, value):
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1063 if isinstance(value, unicode):
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1064 value = value.encode(PKG_INFO_ENCODING)
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1065 else:
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1066 value = str(value)
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1067 file.write('%s: %s\n' % (name, value))
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1068
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1069 def _write_list (self, file, name, values):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1070 for value in values:
48981
4c683ec4415b Issue #2562: Fix distutils PKG-INFO writing logic to allow having
Marc-André Lemburg <mal@egenix.com>
parents: 47252
diff changeset
1071 self._write_field(file, name, value)
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1072
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1073 # -- Metadata query methods ----------------------------------------
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1074
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1075 def get_name(self):
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
1076 return self.name or "UNKNOWN"
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents:
diff changeset
1077
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1078 def get_version(self):
21266
4dae842aa7c5 Use a version number of 0.0.0 instead of ???. The latter leads to
Thomas Heller <theller@ctypes.org>
parents: 21257
diff changeset
1079 return self.version or "0.0.0"
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1080
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1081 def get_fullname(self):
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1082 return "%s-%s" % (self.get_name(), self.get_version())
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1083
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1084 def get_author(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1085 return self.author or "UNKNOWN"
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1086
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1087 def get_author_email(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1088 return self.author_email or "UNKNOWN"
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1089
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1090 def get_maintainer(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1091 return self.maintainer or "UNKNOWN"
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1092
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1093 def get_maintainer_email(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1094 return self.maintainer_email or "UNKNOWN"
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1095
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1096 def get_contact(self):
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1097 return self.maintainer or self.author or "UNKNOWN"
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1098
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1099 def get_contact_email(self):
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1100 return self.maintainer_email or self.author_email or "UNKNOWN"
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1101
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1102 def get_url(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1103 return self.url or "UNKNOWN"
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1104
19137
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
1105 def get_license(self):
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
1106 return self.license or "UNKNOWN"
fb12ea9290b2 [Bug #412271, bug #449009] Use 'license' as the attribute name,
Andrew M. Kuchling <amk@amk.ca>
parents: 17271
diff changeset
1107 get_licence = get_license
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 21266
diff changeset
1108
12427
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1109 def get_description(self):
978c9687beef Patch, originally from Bastian Kleineidam and savagely mutilated by me,
Greg Ward <gward@python.net>
parents: 12407
diff changeset
1110 return self.description or "UNKNOWN"
12496
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
1111
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
1112 def get_long_description(self):
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
1113 return self.long_description or "UNKNOWN"
2a53a3a47962 Harry Henry Gebel: add 'long_description' to DistributionMetadata.
Greg Ward <gward@python.net>
parents: 12448
diff changeset
1114
17127
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1115 def get_keywords(self):
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1116 return self.keywords or []
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1117
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1118 def get_platforms(self):
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1119 return self.platforms or ["UNKNOWN"]
54b6d28a6878 Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
Andrew M. Kuchling <amk@amk.ca>
parents: 17064
diff changeset
1120
27048
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
1121 def get_classifiers(self):
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
1122 return self.classifiers or []
554121fcbb9d [Patch #658094] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
1123
27975
cc95bb7870dc [Patch #683939] Add download_url field to metadata
Andrew M. Kuchling <amk@amk.ca>
parents: 27048
diff changeset
1124 def get_download_url(self):
cc95bb7870dc [Patch #683939] Add download_url field to metadata
Andrew M. Kuchling <amk@amk.ca>
parents: 27048
diff changeset
1125 return self.download_url or "UNKNOWN"
cc95bb7870dc [Patch #683939] Add download_url field to metadata
Andrew M. Kuchling <amk@amk.ca>
parents: 27048
diff changeset
1126
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1127 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1128 def get_requires(self):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1129 return self.requires or []
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1130
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1131 def set_requires(self, value):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1132 import distutils.versionpredicate
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1133 for v in value:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1134 distutils.versionpredicate.VersionPredicate(v)
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1135 self.requires = value
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1136
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1137 def get_provides(self):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1138 return self.provides or []
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1139
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1140 def set_provides(self, value):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1141 value = [v.strip() for v in value]
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1142 for v in value:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1143 import distutils.versionpredicate
34788
b14c8e6310e7 - rename check_provision() to split_revision()
Fred Drake <fdrake@acm.org>
parents: 34785
diff changeset
1144 distutils.versionpredicate.split_provision(v)
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1145 self.provides = value
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1146
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1147 def get_obsoletes(self):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1148 return self.obsoletes or []
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1149
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1150 def set_obsoletes(self, value):
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1151 import distutils.versionpredicate
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1152 for v in value:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1153 distutils.versionpredicate.VersionPredicate(v)
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1154 self.obsoletes = value
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 34648
diff changeset
1155
54114
f1bf538786b7 pep8-fied distutils.dist module
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54101
diff changeset
1156 def fix_help_options(options):
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1157 """Convert a 4-tuple 'help_options' list as found in various command
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1158 classes to the 3-tuple form required by FancyGetopt.
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1159 """
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1160 new_options = []
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1161 for help_tuple in options:
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1162 new_options.append(help_tuple[0:3])
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
1163 return new_options