2000-04-03 22:40:52 -03:00
|
|
|
"""distutils.dist
|
|
|
|
|
|
|
|
Provides the Distribution class, which represents the module distribution
|
2000-06-01 21:44:53 -03:00
|
|
|
being built/installed/distributed.
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2007-04-17 05:48:32 -03:00
|
|
|
import sys, os, re
|
2002-10-31 09:22:41 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
import warnings
|
2002-10-31 09:39:33 -04:00
|
|
|
except ImportError:
|
2002-10-31 09:22:41 -04:00
|
|
|
warnings = None
|
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
from distutils.errors import *
|
2000-09-24 22:58:07 -03:00
|
|
|
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
2001-03-21 23:06:52 -04:00
|
|
|
from distutils.util import check_environ, strtobool, rfc822_escape
|
2002-06-04 17:14:43 -03:00
|
|
|
from distutils import log
|
2002-09-11 13:31:53 -03:00
|
|
|
from distutils.debug import DEBUG
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# Regex to define acceptable Distutils command names. This is not *quite*
|
|
|
|
# the same as a Python NAME -- I don't allow leading underscores. The fact
|
|
|
|
# that they're very similar is no coincidence; the default naming scheme is
|
|
|
|
# to look for a Python module named after the command.
|
|
|
|
command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
|
|
|
|
|
|
|
|
|
|
|
|
class Distribution:
|
2000-06-01 21:44:53 -03:00
|
|
|
"""The core of the Distutils. Most of the work hiding behind 'setup'
|
|
|
|
is really done within a Distribution instance, which farms the work out
|
|
|
|
to the Distutils commands specified on the command line.
|
|
|
|
|
|
|
|
Setup scripts will almost never instantiate Distribution directly,
|
|
|
|
unless the 'setup()' function is totally inadequate to their needs.
|
|
|
|
However, it is conceivable that a setup script might wish to subclass
|
|
|
|
Distribution for some specialized purpose, and then pass the subclass
|
|
|
|
to 'setup()' as the 'distclass' keyword argument. If so, it is
|
|
|
|
necessary to respect the expectations that 'setup' has of Distribution.
|
|
|
|
See the code for 'setup()', in core.py, for details.
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
|
|
|
|
# 'global_options' describes the command-line options that may be
|
2000-04-20 23:28:14 -03:00
|
|
|
# supplied to the setup script prior to any actual commands.
|
|
|
|
# Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
|
2000-04-03 22:40:52 -03:00
|
|
|
# these global options. This list should be kept to a bare minimum,
|
|
|
|
# since every global option is also valid as a command option -- and we
|
|
|
|
# don't want to pollute the commands with too many options that they
|
|
|
|
# have minimal control over.
|
2002-06-04 17:14:43 -03:00
|
|
|
# The fourth entry for verbose means that it can be repeated.
|
|
|
|
global_options = [('verbose', 'v', "run verbosely (default)", 1),
|
2000-05-22 22:42:17 -03:00
|
|
|
('quiet', 'q', "run quietly (turns verbosity off)"),
|
|
|
|
('dry-run', 'n', "don't actually do anything"),
|
|
|
|
('help', 'h', "show detailed help message"),
|
2000-04-03 22:40:52 -03:00
|
|
|
]
|
2000-04-20 23:28:14 -03:00
|
|
|
|
2005-03-03 04:12:27 -04:00
|
|
|
# 'common_usage' is a short (2-3 line) string describing the common
|
|
|
|
# usage of the setup script.
|
|
|
|
common_usage = """\
|
|
|
|
Common commands: (see '--help-commands' for more)
|
|
|
|
|
|
|
|
setup.py build will build the package underneath 'build/'
|
|
|
|
setup.py install will install the package
|
|
|
|
"""
|
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
# options that are not propagated to the commands
|
|
|
|
display_options = [
|
|
|
|
('help-commands', None,
|
|
|
|
"list all available commands"),
|
|
|
|
('name', None,
|
|
|
|
"print package name"),
|
|
|
|
('version', 'V',
|
|
|
|
"print package version"),
|
|
|
|
('fullname', None,
|
|
|
|
"print <package name>-<version>"),
|
|
|
|
('author', None,
|
|
|
|
"print the author's name"),
|
|
|
|
('author-email', None,
|
|
|
|
"print the author's email address"),
|
|
|
|
('maintainer', None,
|
|
|
|
"print the maintainer's name"),
|
|
|
|
('maintainer-email', None,
|
|
|
|
"print the maintainer's email address"),
|
|
|
|
('contact', None,
|
2000-05-22 22:42:17 -03:00
|
|
|
"print the maintainer's name if known, else the author's"),
|
2000-04-20 23:28:14 -03:00
|
|
|
('contact-email', None,
|
2000-05-22 22:42:17 -03:00
|
|
|
"print the maintainer's email address if known, else the author's"),
|
2000-04-20 23:28:14 -03:00
|
|
|
('url', None,
|
|
|
|
"print the URL for this package"),
|
|
|
|
('license', None,
|
2001-08-10 15:49:23 -03:00
|
|
|
"print the license of the package"),
|
|
|
|
('licence', None,
|
|
|
|
"alias for --license"),
|
2000-04-20 23:28:14 -03:00
|
|
|
('description', None,
|
|
|
|
"print the package description"),
|
2000-04-25 23:26:55 -03:00
|
|
|
('long-description', None,
|
|
|
|
"print the long package description"),
|
2001-03-21 23:06:52 -04:00
|
|
|
('platforms', None,
|
|
|
|
"print the list of platforms"),
|
2003-01-03 11:24:36 -04:00
|
|
|
('classifiers', None,
|
|
|
|
"print the list of classifiers"),
|
2001-03-21 23:06:52 -04:00
|
|
|
('keywords', None,
|
|
|
|
"print the list of keywords"),
|
2005-03-20 18:19:47 -04:00
|
|
|
('provides', None,
|
|
|
|
"print the list of packages/modules provided"),
|
|
|
|
('requires', None,
|
|
|
|
"print the list of packages/modules required"),
|
|
|
|
('obsoletes', None,
|
|
|
|
"print the list of packages/modules made obsolete")
|
2000-04-20 23:28:14 -03:00
|
|
|
]
|
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
Fix a place where floor division would be in order.
........
r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
Make map() and filter() identical to itertools.imap() and .ifilter(),
respectively.
I fixed two bootstrap issues, due to the dynamic import of itertools:
1. Starting python requires that map() and filter() are not used until
site.py has added build/lib.<arch> to sys.path.
2. Building python requires that setup.py and distutils and everything
they use is free of map() and filter() calls.
Beyond this, I only fixed the tests in test_builtin.py.
Others, please help fixing the remaining tests that are now broken!
The fixes are usually simple:
a. map(None, X) -> list(X)
b. map(F, X) -> list(map(F, X))
c. map(lambda x: F(x), X) -> [F(x) for x in X]
d. filter(F, X) -> list(filter(F, X))
e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
Someone, please also contribute a fixer for 2to3 to do this.
It can leave map()/filter() calls alone that are already
inside a list() or sorted() call or for-loop.
Only in rare cases have I seen code that depends on map() of lists
of different lengths going to the end of the longest, or on filter()
of a string or tuple returning an object of the same type; these
will need more thought to fix.
........
r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
Make it so that test_decimal fails instead of hangs, to help automated
test runners.
........
r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
Fix a few test cases after the map->imap change.
........
r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
Get a bunch more tests passing after converting map/filter to return iterators.
........
r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
Fix the remaining failing unit tests (at least on OSX).
Also tweaked urllib2 so it doesn't raise socket.gaierror when
all network interfaces are turned off.
........
2007-07-03 05:25:58 -03:00
|
|
|
display_option_names = [translate_longopt(x[0]) for x in display_options]
|
2000-04-20 23:28:14 -03:00
|
|
|
|
|
|
|
# negative options are options that exclude other options
|
2000-04-03 22:40:52 -03:00
|
|
|
negative_opt = {'quiet': 'verbose'}
|
|
|
|
|
|
|
|
|
|
|
|
# -- Creation/initialization methods -------------------------------
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
def __init__ (self, attrs=None):
|
|
|
|
"""Construct a new Distribution instance: initialize all the
|
2000-06-01 21:44:53 -03:00
|
|
|
attributes of a Distribution, and then use 'attrs' (a dictionary
|
|
|
|
mapping attribute names to values) to assign some of those
|
|
|
|
attributes their "real" values. (Any attributes not mentioned in
|
|
|
|
'attrs' will be assigned to some null value: 0, None, an empty list
|
|
|
|
or dictionary, etc.) Most importantly, initialize the
|
|
|
|
'command_obj' attribute to the empty dictionary; this will be
|
|
|
|
filled in with real command objects by 'parse_command_line()'.
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# Default values for our command-line options
|
|
|
|
self.verbose = 1
|
|
|
|
self.dry_run = 0
|
|
|
|
self.help = 0
|
2000-04-20 23:28:14 -03:00
|
|
|
for attr in self.display_option_names:
|
|
|
|
setattr(self, attr, 0)
|
|
|
|
|
|
|
|
# Store the distribution meta-data (name, version, author, and so
|
|
|
|
# forth) in a separate object -- we're getting to have enough
|
|
|
|
# information here (and enough command-line options) that it's
|
|
|
|
# worth it. Also delegate 'get_XXX()' methods to the 'metadata'
|
|
|
|
# object in a sneaky and underhanded (but efficient!) way.
|
2000-09-25 22:52:25 -03:00
|
|
|
self.metadata = DistributionMetadata()
|
2001-09-03 12:47:21 -03:00
|
|
|
for basename in self.metadata._METHOD_BASENAMES:
|
2000-04-21 23:52:44 -03:00
|
|
|
method_name = "get_" + basename
|
|
|
|
setattr(self, method_name, getattr(self.metadata, method_name))
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# 'cmdclass' maps command names to class objects, so we
|
|
|
|
# can 1) quickly figure out which class to instantiate when
|
|
|
|
# we need to create a new command object, and 2) have a way
|
2000-04-20 23:28:14 -03:00
|
|
|
# for the setup script to override command classes
|
2000-04-03 22:40:52 -03:00
|
|
|
self.cmdclass = {}
|
|
|
|
|
2004-08-03 13:37:40 -03:00
|
|
|
# 'command_packages' is a list of packages in which commands
|
|
|
|
# are searched for. The factory for command 'foo' is expected
|
|
|
|
# to be named 'foo' in the module 'foo' in one of the packages
|
|
|
|
# named here. This list is searched from the left; an error
|
|
|
|
# is raised if no named package provides the command being
|
|
|
|
# searched for. (Always access using get_command_packages().)
|
|
|
|
self.command_packages = None
|
|
|
|
|
2000-08-28 22:15:18 -03:00
|
|
|
# 'script_name' and 'script_args' are usually set to sys.argv[0]
|
|
|
|
# and sys.argv[1:], but they can be overridden when the caller is
|
|
|
|
# not necessarily a setup script run from the command-line.
|
|
|
|
self.script_name = None
|
|
|
|
self.script_args = None
|
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# 'command_options' is where we store command options between
|
|
|
|
# parsing them (from config files, the command-line, etc.) and when
|
|
|
|
# they are actually needed -- ie. when the command in question is
|
|
|
|
# instantiated. It is a dictionary of dictionaries of 2-tuples:
|
|
|
|
# command_options = { command_name : { option : (source, value) } }
|
2000-05-11 21:41:33 -03:00
|
|
|
self.command_options = {}
|
|
|
|
|
2005-03-23 14:54:36 -04:00
|
|
|
# 'dist_files' is the list of (command, pyversion, file) that
|
|
|
|
# have been created by any dist commands run so far. This is
|
|
|
|
# filled regardless of whether the run is dry or not. pyversion
|
|
|
|
# gives sysconfig.get_python_version() if the dist file is
|
|
|
|
# specific to a Python version, 'any' if it is good for all
|
|
|
|
# Python versions on the target platform, and '' for a source
|
|
|
|
# file. pyversion should not be used to specify minimum or
|
|
|
|
# maximum required Python versions; use the metainfo for that
|
|
|
|
# instead.
|
2005-03-21 16:56:35 -04:00
|
|
|
self.dist_files = []
|
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
# These options are really the business of various commands, rather
|
|
|
|
# than of the Distribution itself. We provide aliases for them in
|
|
|
|
# Distribution as a convenience to the developer.
|
|
|
|
self.packages = None
|
2004-06-11 18:50:33 -03:00
|
|
|
self.package_data = {}
|
2000-04-03 22:40:52 -03:00
|
|
|
self.package_dir = None
|
|
|
|
self.py_modules = None
|
|
|
|
self.libraries = None
|
2000-05-26 22:36:14 -03:00
|
|
|
self.headers = None
|
2000-04-03 22:40:52 -03:00
|
|
|
self.ext_modules = None
|
|
|
|
self.ext_package = None
|
|
|
|
self.include_dirs = None
|
|
|
|
self.extra_path = None
|
2000-05-11 21:52:23 -03:00
|
|
|
self.scripts = None
|
2000-05-13 00:09:50 -03:00
|
|
|
self.data_files = None
|
2009-01-08 20:15:45 -04:00
|
|
|
self.password = ''
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# And now initialize bookkeeping stuff that can't be supplied by
|
|
|
|
# the caller at all. 'command_obj' maps command names to
|
|
|
|
# Command instances -- that's how we enforce that every command
|
|
|
|
# class is a singleton.
|
|
|
|
self.command_obj = {}
|
|
|
|
|
|
|
|
# 'have_run' maps command names to boolean values; it keeps track
|
|
|
|
# of whether we have actually run a particular command, to make it
|
|
|
|
# cheap to "run" a command whenever we think we might need to -- if
|
|
|
|
# it's already been done, no need for expensive filesystem
|
|
|
|
# operations, we just check the 'have_run' dictionary and carry on.
|
|
|
|
# It's only safe to query 'have_run' for a command class that has
|
|
|
|
# been instantiated -- a false value will be inserted when the
|
|
|
|
# command object is created, and replaced with a true value when
|
2000-07-26 23:13:20 -03:00
|
|
|
# the command is successfully run. Thus it's probably best to use
|
2000-04-03 22:40:52 -03:00
|
|
|
# '.get()' rather than a straight lookup.
|
|
|
|
self.have_run = {}
|
|
|
|
|
|
|
|
# Now we'll use the attrs dictionary (ultimately, keyword args from
|
2000-04-20 23:28:14 -03:00
|
|
|
# the setup script) to possibly override any or all of these
|
|
|
|
# distribution options.
|
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
if attrs:
|
|
|
|
# Pull out the set of command options and work on them
|
|
|
|
# specifically. Note that this order guarantees that aliased
|
|
|
|
# command options will override any supplied redundantly
|
|
|
|
# through the general options dictionary.
|
2000-09-25 22:52:25 -03:00
|
|
|
options = attrs.get('options')
|
2008-12-29 18:38:38 -04:00
|
|
|
if options is not None:
|
2000-04-03 22:40:52 -03:00
|
|
|
del attrs['options']
|
|
|
|
for (command, cmd_options) in options.items():
|
2000-05-25 22:00:15 -03:00
|
|
|
opt_dict = self.get_option_dict(command)
|
|
|
|
for (opt, val) in cmd_options.items():
|
|
|
|
opt_dict[opt] = ("setup script", val)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2006-08-18 19:13:04 -03:00
|
|
|
if 'licence' in attrs:
|
2003-03-03 16:07:27 -04:00
|
|
|
attrs['license'] = attrs['licence']
|
|
|
|
del attrs['licence']
|
|
|
|
msg = "'licence' distribution option is deprecated; use 'license'"
|
|
|
|
if warnings is not None:
|
|
|
|
warnings.warn(msg)
|
|
|
|
else:
|
|
|
|
sys.stderr.write(msg + "\n")
|
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
# Now work on the rest of the attributes. Any attribute that's
|
|
|
|
# not already defined is invalid!
|
2009-06-01 19:36:26 -03:00
|
|
|
for (key, val) in attrs.items():
|
2005-03-20 18:19:47 -04:00
|
|
|
if hasattr(self.metadata, "set_" + key):
|
|
|
|
getattr(self.metadata, "set_" + key)(val)
|
|
|
|
elif hasattr(self.metadata, key):
|
2000-09-25 22:52:25 -03:00
|
|
|
setattr(self.metadata, key, val)
|
|
|
|
elif hasattr(self, key):
|
|
|
|
setattr(self, key, val)
|
2004-10-13 10:22:34 -03:00
|
|
|
else:
|
2002-10-31 09:22:41 -04:00
|
|
|
msg = "Unknown distribution option: %s" % repr(key)
|
|
|
|
if warnings is not None:
|
|
|
|
warnings.warn(msg)
|
|
|
|
else:
|
|
|
|
sys.stderr.write(msg + "\n")
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2001-03-21 23:06:52 -04:00
|
|
|
self.finalize_options()
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_option_dict(self, command):
|
2000-05-25 22:00:15 -03:00
|
|
|
"""Get the option dictionary for a given command. If that
|
|
|
|
command's option dictionary hasn't been created yet, then create it
|
|
|
|
and return the new dictionary; otherwise, return the existing
|
|
|
|
option dictionary.
|
|
|
|
"""
|
|
|
|
dict = self.command_options.get(command)
|
|
|
|
if dict is None:
|
|
|
|
dict = self.command_options[command] = {}
|
|
|
|
return dict
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def dump_option_dicts(self, header=None, commands=None, indent=""):
|
2000-05-28 20:53:06 -03:00
|
|
|
from pprint import pformat
|
|
|
|
|
|
|
|
if commands is None: # dump all command option dicts
|
2007-10-14 22:27:53 -03:00
|
|
|
commands = sorted(self.command_options.keys())
|
2000-05-28 20:53:06 -03:00
|
|
|
|
|
|
|
if header is not None:
|
2009-06-01 19:36:26 -03:00
|
|
|
self.announce(indent + header)
|
2000-05-28 20:53:06 -03:00
|
|
|
indent = indent + " "
|
|
|
|
|
|
|
|
if not commands:
|
2009-06-01 19:36:26 -03:00
|
|
|
self.announce(indent + "no commands known yet")
|
2000-05-28 20:53:06 -03:00
|
|
|
return
|
|
|
|
|
|
|
|
for cmd_name in commands:
|
|
|
|
opt_dict = self.command_options.get(cmd_name)
|
|
|
|
if opt_dict is None:
|
2009-06-01 19:36:26 -03:00
|
|
|
self.announce(indent +
|
|
|
|
"no option dict for '%s' command" % cmd_name)
|
2000-05-28 20:53:06 -03:00
|
|
|
else:
|
2009-06-01 19:36:26 -03:00
|
|
|
self.announce(indent +
|
|
|
|
"option dict for '%s' command:" % cmd_name)
|
2000-05-28 20:53:06 -03:00
|
|
|
out = pformat(opt_dict)
|
2009-06-01 19:36:26 -03:00
|
|
|
for line in out.split('\n'):
|
|
|
|
self.announce(indent + " " + line)
|
2000-05-28 20:53:06 -03:00
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# -- Config file finding/parsing methods ---------------------------
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def find_config_files(self):
|
2000-05-11 21:41:33 -03:00
|
|
|
"""Find as many configuration files as should be processed for this
|
|
|
|
platform, and return a list of filenames in the order in which they
|
|
|
|
should be parsed. The filenames returned are guaranteed to exist
|
|
|
|
(modulo nasty race conditions).
|
|
|
|
|
2001-12-06 12:32:05 -04:00
|
|
|
There are three possible config files: distutils.cfg in the
|
|
|
|
Distutils installation directory (ie. where the top-level
|
|
|
|
Distutils __inst__.py file lives), a file in the user's home
|
|
|
|
directory named .pydistutils.cfg on Unix and pydistutils.cfg
|
|
|
|
on Windows/Mac, and setup.cfg in the current directory.
|
2000-05-22 22:42:17 -03:00
|
|
|
"""
|
2000-05-11 21:41:33 -03:00
|
|
|
files = []
|
2000-06-06 23:26:19 -03:00
|
|
|
check_environ()
|
|
|
|
|
2000-06-06 23:29:03 -03:00
|
|
|
# Where to look for the system-wide Distutils config file
|
|
|
|
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
|
|
|
|
|
|
|
|
# Look for the system config file
|
|
|
|
sys_file = os.path.join(sys_dir, "distutils.cfg")
|
|
|
|
if os.path.isfile(sys_file):
|
|
|
|
files.append(sys_file)
|
|
|
|
|
|
|
|
# What to call the per-user config file
|
|
|
|
if os.name == 'posix':
|
2000-07-07 17:45:21 -03:00
|
|
|
user_filename = ".pydistutils.cfg"
|
|
|
|
else:
|
|
|
|
user_filename = "pydistutils.cfg"
|
2000-10-14 01:06:40 -03:00
|
|
|
|
2000-06-06 23:29:03 -03:00
|
|
|
# And look for the user config file
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
user_file = os.path.join(os.path.expanduser('~'), user_filename)
|
|
|
|
if os.path.isfile(user_file):
|
|
|
|
files.append(user_file)
|
2000-05-11 21:41:33 -03:00
|
|
|
|
|
|
|
# All platforms support local setup.cfg
|
|
|
|
local_file = "setup.cfg"
|
|
|
|
if os.path.isfile(local_file):
|
|
|
|
files.append(local_file)
|
|
|
|
|
|
|
|
return files
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def parse_config_files(self, filenames=None):
|
2008-05-14 19:59:42 -03:00
|
|
|
from configparser import ConfigParser
|
2000-05-11 21:41:33 -03:00
|
|
|
|
|
|
|
if filenames is None:
|
|
|
|
filenames = self.find_config_files()
|
|
|
|
|
2009-06-01 19:36:26 -03:00
|
|
|
if DEBUG:
|
|
|
|
self.announce("Distribution.parse_config_files():")
|
2000-05-23 00:47:35 -03:00
|
|
|
|
2000-05-11 21:41:33 -03:00
|
|
|
parser = ConfigParser()
|
2000-05-22 22:42:17 -03:00
|
|
|
for filename in filenames:
|
2009-06-01 19:36:26 -03:00
|
|
|
if DEBUG:
|
|
|
|
self.announce(" reading", filename)
|
2000-05-22 22:42:17 -03:00
|
|
|
parser.read(filename)
|
|
|
|
for section in parser.sections():
|
|
|
|
options = parser.options(section)
|
2000-05-25 22:00:15 -03:00
|
|
|
opt_dict = self.get_option_dict(section)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
for opt in options:
|
|
|
|
if opt != '__name__':
|
2000-09-24 22:23:52 -03:00
|
|
|
val = parser.get(section,opt)
|
2007-04-17 05:48:32 -03:00
|
|
|
opt = opt.replace('-', '_')
|
2000-09-24 22:23:52 -03:00
|
|
|
opt_dict[opt] = (filename, val)
|
2000-05-11 21:41:33 -03:00
|
|
|
|
2000-05-23 00:47:35 -03:00
|
|
|
# Make the ConfigParser forget everything (so we retain
|
2004-02-17 18:35:19 -04:00
|
|
|
# the original filenames that options come from)
|
2000-05-23 00:47:35 -03:00
|
|
|
parser.__init__()
|
2000-05-11 21:41:33 -03:00
|
|
|
|
2000-09-24 22:23:52 -03:00
|
|
|
# If there was a "global" section in the config file, use it
|
|
|
|
# to set Distribution options.
|
|
|
|
|
2006-08-18 19:13:04 -03:00
|
|
|
if 'global' in self.command_options:
|
2000-09-24 22:23:52 -03:00
|
|
|
for (opt, (src, val)) in self.command_options['global'].items():
|
|
|
|
alias = self.negative_opt.get(opt)
|
|
|
|
try:
|
|
|
|
if alias:
|
|
|
|
setattr(self, alias, not strtobool(val))
|
|
|
|
elif opt in ('verbose', 'dry_run'): # ugh!
|
|
|
|
setattr(self, opt, strtobool(val))
|
2004-08-03 13:37:40 -03:00
|
|
|
else:
|
|
|
|
setattr(self, opt, val)
|
2007-01-10 12:19:56 -04:00
|
|
|
except ValueError as msg:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsOptionError(msg)
|
2000-09-24 22:23:52 -03:00
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# -- Command-line parsing methods ----------------------------------
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def parse_command_line(self):
|
2000-08-28 22:15:18 -03:00
|
|
|
"""Parse the setup script's command line, taken from the
|
|
|
|
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
|
|
|
|
-- see 'setup()' in core.py). This list is first processed for
|
|
|
|
"global options" -- options that set attributes of the Distribution
|
|
|
|
instance. Then, it is alternately scanned for Distutils commands
|
|
|
|
and options for that command. Each new command terminates the
|
|
|
|
options for the previous command. The allowed options for a
|
|
|
|
command are determined by the 'user_options' attribute of the
|
|
|
|
command class -- thus, we have to be able to load command classes
|
|
|
|
in order to parse the command line. Any error in that 'options'
|
|
|
|
attribute raises DistutilsGetoptError; any error on the
|
|
|
|
command-line raises DistutilsArgError. If no Distutils commands
|
|
|
|
were found on the command line, raises DistutilsArgError. Return
|
2000-09-24 22:23:52 -03:00
|
|
|
true if command-line was successfully parsed and we should carry
|
2000-08-28 22:15:18 -03:00
|
|
|
on with executing commands; false if no errors but we shouldn't
|
|
|
|
execute commands (currently, this only happens if user asks for
|
|
|
|
help).
|
2000-05-22 22:42:17 -03:00
|
|
|
"""
|
2001-01-15 12:09:35 -04:00
|
|
|
#
|
2001-08-10 15:59:30 -03:00
|
|
|
# We now have enough information to show the Macintosh dialog
|
|
|
|
# that allows the user to interactively specify the "command line".
|
2001-01-15 12:09:35 -04:00
|
|
|
#
|
2004-08-03 13:37:40 -03:00
|
|
|
toplevel_options = self._get_toplevel_options()
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
# We have to parse the command line a bit at a time -- global
|
|
|
|
# options, then the first command, then its options, and so on --
|
|
|
|
# because each command will be handled by a different class, and
|
2000-05-22 22:42:17 -03:00
|
|
|
# the options that are valid for a particular class aren't known
|
|
|
|
# until we have loaded the command class, which doesn't happen
|
|
|
|
# until we know what the command is.
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
self.commands = []
|
2004-08-03 13:37:40 -03:00
|
|
|
parser = FancyGetopt(toplevel_options + self.display_options)
|
2000-09-25 22:52:25 -03:00
|
|
|
parser.set_negative_aliases(self.negative_opt)
|
2001-08-10 15:49:23 -03:00
|
|
|
parser.set_aliases({'licence': 'license'})
|
2000-09-25 22:52:25 -03:00
|
|
|
args = parser.getopt(args=self.script_args, object=self)
|
2000-04-20 23:28:14 -03:00
|
|
|
option_order = parser.get_option_order()
|
2002-06-04 17:14:43 -03:00
|
|
|
log.set_verbosity(self.verbose)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
# for display options we return immediately
|
|
|
|
if self.handle_display_options(option_order):
|
2000-04-03 22:40:52 -03:00
|
|
|
return
|
|
|
|
while args:
|
2000-05-22 22:42:17 -03:00
|
|
|
args = self._parse_command_opts(parser, args)
|
|
|
|
if args is None: # user asked for help (and got it)
|
2000-04-03 22:40:52 -03:00
|
|
|
return
|
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# Handle the cases of --help as a "global" option, ie.
|
|
|
|
# "setup.py --help" and "setup.py --help command ...". For the
|
|
|
|
# former, we show global options (--verbose, --dry-run, etc.)
|
|
|
|
# and display-only options (--name, --version, etc.); for the
|
|
|
|
# latter, we omit the display-only options and show help for
|
|
|
|
# each command listed on the command line.
|
|
|
|
if self.help:
|
|
|
|
self._show_help(parser,
|
|
|
|
display_options=len(self.commands) == 0,
|
|
|
|
commands=self.commands)
|
2000-04-03 22:40:52 -03:00
|
|
|
return
|
|
|
|
|
|
|
|
# Oops, no commands found -- an end-user error
|
|
|
|
if not self.commands:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsArgError("no commands supplied")
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# All is well: return true
|
2007-08-30 00:52:21 -03:00
|
|
|
return True
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def _get_toplevel_options(self):
|
2004-08-03 13:37:40 -03:00
|
|
|
"""Return the non-display options recognized at the top level.
|
|
|
|
|
|
|
|
This includes options that are recognized *only* at the top
|
|
|
|
level as well as options recognized for commands.
|
|
|
|
"""
|
|
|
|
return self.global_options + [
|
|
|
|
("command-packages=", None,
|
|
|
|
"list of packages that provide distutils commands"),
|
|
|
|
]
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def _parse_command_opts(self, parser, args):
|
2000-05-22 22:42:17 -03:00
|
|
|
"""Parse the command-line options for a single command.
|
|
|
|
'parser' must be a FancyGetopt instance; 'args' must be the list
|
|
|
|
of arguments, starting with the current command (whose options
|
|
|
|
we are about to parse). Returns a new version of 'args' with
|
|
|
|
the next command at the front of the list; will be the empty
|
|
|
|
list if there are no more commands on the command line. Returns
|
|
|
|
None if the user asked for help on this command.
|
|
|
|
"""
|
|
|
|
# late import because of mutual dependence between these modules
|
|
|
|
from distutils.cmd import Command
|
|
|
|
|
|
|
|
# Pull the current command from the head of the command line
|
|
|
|
command = args[0]
|
2000-09-25 22:52:25 -03:00
|
|
|
if not command_re.match(command):
|
2007-08-30 00:52:21 -03:00
|
|
|
raise SystemExit("invalid command name '%s'" % command)
|
2000-09-25 22:52:25 -03:00
|
|
|
self.commands.append(command)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
# Dig up the command class that implements this command, so we
|
|
|
|
# 1) know that it's a valid command, and 2) know which options
|
|
|
|
# it takes.
|
|
|
|
try:
|
2000-09-25 22:52:25 -03:00
|
|
|
cmd_class = self.get_command_class(command)
|
2007-01-10 12:19:56 -04:00
|
|
|
except DistutilsModuleError as msg:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsArgError(msg)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
# Require that the command class be derived from Command -- want
|
|
|
|
# to be sure that the basic "command" interface is implemented.
|
2000-09-25 22:52:25 -03:00
|
|
|
if not issubclass(cmd_class, Command):
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsClassError(
|
|
|
|
"command class %s must subclass Command" % cmd_class)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
# Also make sure that the command object provides a list of its
|
|
|
|
# known options.
|
2000-09-25 22:52:25 -03:00
|
|
|
if not (hasattr(cmd_class, 'user_options') and
|
2007-06-07 20:15:56 -03:00
|
|
|
isinstance(cmd_class.user_options, list)):
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsClassError(("command class %s must provide " +
|
2000-05-22 22:42:17 -03:00
|
|
|
"'user_options' attribute (a list of tuples)") % \
|
2007-08-30 00:52:21 -03:00
|
|
|
cmd_class)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
# If the command class has a list of negative alias options,
|
|
|
|
# merge it in with the global negative aliases.
|
|
|
|
negative_opt = self.negative_opt
|
2000-09-25 22:52:25 -03:00
|
|
|
if hasattr(cmd_class, 'negative_opt'):
|
2009-05-15 14:34:21 -03:00
|
|
|
negative_opt = negative_opt.copy()
|
2000-09-25 22:52:25 -03:00
|
|
|
negative_opt.update(cmd_class.negative_opt)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
2000-10-14 01:06:40 -03:00
|
|
|
# Check for help_options in command class. They have a different
|
|
|
|
# format (tuple of four) so we need to preprocess them here.
|
2000-07-07 17:45:21 -03:00
|
|
|
if (hasattr(cmd_class, 'help_options') and
|
2007-06-07 20:15:56 -03:00
|
|
|
isinstance(cmd_class.help_options, list)):
|
2000-06-23 21:23:20 -03:00
|
|
|
help_options = fix_help_options(cmd_class.help_options)
|
|
|
|
else:
|
2000-06-23 22:22:41 -03:00
|
|
|
help_options = []
|
2000-06-23 21:23:20 -03:00
|
|
|
|
2000-06-07 00:00:06 -03:00
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# All commands support the global options too, just by adding
|
|
|
|
# in 'global_options'.
|
2000-09-25 22:52:25 -03:00
|
|
|
parser.set_option_table(self.global_options +
|
|
|
|
cmd_class.user_options +
|
|
|
|
help_options)
|
|
|
|
parser.set_negative_aliases(negative_opt)
|
|
|
|
(args, opts) = parser.getopt(args[1:])
|
2000-05-23 00:47:35 -03:00
|
|
|
if hasattr(opts, 'help') and opts.help:
|
2000-05-22 22:42:17 -03:00
|
|
|
self._show_help(parser, display_options=0, commands=[cmd_class])
|
|
|
|
return
|
|
|
|
|
2000-07-07 17:45:21 -03:00
|
|
|
if (hasattr(cmd_class, 'help_options') and
|
2007-06-07 20:15:56 -03:00
|
|
|
isinstance(cmd_class.help_options, list)):
|
2000-07-07 17:45:21 -03:00
|
|
|
help_option_found=0
|
|
|
|
for (help_option, short, desc, func) in cmd_class.help_options:
|
|
|
|
if hasattr(opts, parser.get_attr_name(help_option)):
|
|
|
|
help_option_found=1
|
Merged revisions 55407-55513 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r55413 | fred.drake | 2007-05-17 12:30:10 -0700 (Thu, 17 May 2007) | 1 line
fix argument name in documentation; match the implementation
................
r55430 | jack.diederich | 2007-05-18 06:39:59 -0700 (Fri, 18 May 2007) | 1 line
Implements class decorators, PEP 3129.
................
r55432 | guido.van.rossum | 2007-05-18 08:09:41 -0700 (Fri, 18 May 2007) | 2 lines
obsubmit.
................
r55434 | guido.van.rossum | 2007-05-18 09:39:10 -0700 (Fri, 18 May 2007) | 3 lines
Fix bug in test_inspect. (I presume this is how it should be fixed;
Jack Diedrich, please verify.)
................
r55460 | brett.cannon | 2007-05-20 00:31:57 -0700 (Sun, 20 May 2007) | 4 lines
Remove the imageop module. With imgfile already removed in Python 3.0 and
rgbimg gone in Python 2.6 the unit tests themselves were made worthless. Plus
third-party libraries perform the same function much better.
................
r55469 | neal.norwitz | 2007-05-20 11:28:20 -0700 (Sun, 20 May 2007) | 118 lines
Merged revisions 55324-55467 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55348 | georg.brandl | 2007-05-15 13:19:34 -0700 (Tue, 15 May 2007) | 4 lines
HTML-escape the plain traceback in cgitb's HTML output, to prevent
the traceback inadvertently or maliciously closing the comment and
injecting HTML into the error page.
........
r55372 | neal.norwitz | 2007-05-15 21:33:50 -0700 (Tue, 15 May 2007) | 6 lines
Port rev 55353 from Guido:
Add what looks like a necessary call to PyErr_NoMemory() when PyMem_MALLOC()
fails.
Will backport.
........
r55377 | neal.norwitz | 2007-05-15 22:06:33 -0700 (Tue, 15 May 2007) | 1 line
Mention removal of some directories for obsolete platforms
........
r55380 | brett.cannon | 2007-05-15 22:50:03 -0700 (Tue, 15 May 2007) | 2 lines
Change the maintainer of the BeOS port.
........
r55383 | georg.brandl | 2007-05-16 06:44:18 -0700 (Wed, 16 May 2007) | 2 lines
Bug #1719995: don't use deprecated method in sets example.
........
r55386 | neal.norwitz | 2007-05-16 13:05:11 -0700 (Wed, 16 May 2007) | 5 lines
Fix bug in marshal where bad data would cause a segfault due to
lack of an infinite recursion check.
Contributed by Damien Miller at Google.
........
r55389 | brett.cannon | 2007-05-16 15:42:29 -0700 (Wed, 16 May 2007) | 6 lines
Remove the gopherlib module. It has been raising a DeprecationWarning since
Python 2.5.
Also remove gopher support from urllib/urllib2. As both imported gopherlib the
usage of the support would have raised a DeprecationWarning.
........
r55394 | raymond.hettinger | 2007-05-16 18:08:04 -0700 (Wed, 16 May 2007) | 1 line
calendar.py gets no benefit from xrange() instead of range()
........
r55395 | brett.cannon | 2007-05-16 19:02:56 -0700 (Wed, 16 May 2007) | 3 lines
Complete deprecation of BaseException.message. Some subclasses were directly
accessing the message attribute instead of using the descriptor.
........
r55396 | neal.norwitz | 2007-05-16 23:11:36 -0700 (Wed, 16 May 2007) | 4 lines
Reduce the max stack depth to see if this fixes the segfaults on
Windows and some other boxes. If this is successful, this rev should
be backported. I'm not sure how close to the limit we should push this.
........
r55397 | neal.norwitz | 2007-05-16 23:23:50 -0700 (Wed, 16 May 2007) | 4 lines
Set the depth to something very small to try to determine if the
crashes on Windows are really due to the stack size or possibly
some other problem.
........
r55398 | neal.norwitz | 2007-05-17 00:04:46 -0700 (Thu, 17 May 2007) | 4 lines
Last try for tweaking the max stack depth. 5000 was the original value,
4000 didn't work either. 1000 does work on Windows. If 2000 works,
that will hopefully be a reasonable balance.
........
r55412 | fred.drake | 2007-05-17 12:29:58 -0700 (Thu, 17 May 2007) | 1 line
fix argument name in documentation; match the implementation
........
r55427 | neal.norwitz | 2007-05-17 22:47:16 -0700 (Thu, 17 May 2007) | 1 line
Verify neither dumps or loads overflow the stack and segfault.
........
r55446 | collin.winter | 2007-05-18 16:11:24 -0700 (Fri, 18 May 2007) | 1 line
Backport PEP 3110's new 'except' syntax to 2.6.
........
r55448 | raymond.hettinger | 2007-05-18 18:11:16 -0700 (Fri, 18 May 2007) | 1 line
Improvements to NamedTuple's implementation, tests, and documentation
........
r55449 | raymond.hettinger | 2007-05-18 18:50:11 -0700 (Fri, 18 May 2007) | 1 line
Fix beginner mistake -- don't mix spaces and tabs.
........
r55450 | neal.norwitz | 2007-05-18 20:48:47 -0700 (Fri, 18 May 2007) | 1 line
Clear data so random memory does not get freed. Will backport.
........
r55452 | neal.norwitz | 2007-05-18 21:34:55 -0700 (Fri, 18 May 2007) | 3 lines
Whoops, need to pay attention to those test failures.
Move the clear to *before* the first use, not after.
........
r55453 | neal.norwitz | 2007-05-18 21:35:52 -0700 (Fri, 18 May 2007) | 1 line
Give some clue as to what happened if the test fails.
........
r55455 | georg.brandl | 2007-05-19 11:09:26 -0700 (Sat, 19 May 2007) | 2 lines
Fix docstring for add_package in site.py.
........
r55458 | brett.cannon | 2007-05-20 00:09:50 -0700 (Sun, 20 May 2007) | 2 lines
Remove the rgbimg module. It has been deprecated since Python 2.5.
........
r55465 | nick.coghlan | 2007-05-20 04:12:49 -0700 (Sun, 20 May 2007) | 1 line
Fix typo in example (should be backported, but my maintenance branch is woefully out of date)
........
................
r55472 | brett.cannon | 2007-05-20 12:06:18 -0700 (Sun, 20 May 2007) | 2 lines
Remove imageop from the Windows build process.
................
r55486 | neal.norwitz | 2007-05-20 23:59:52 -0700 (Sun, 20 May 2007) | 1 line
Remove callable() builtin
................
r55506 | neal.norwitz | 2007-05-22 00:43:29 -0700 (Tue, 22 May 2007) | 78 lines
Merged revisions 55468-55505 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r55468 | neal.norwitz | 2007-05-20 11:06:27 -0700 (Sun, 20 May 2007) | 1 line
rotor is long gone.
........
r55470 | neal.norwitz | 2007-05-20 11:43:00 -0700 (Sun, 20 May 2007) | 1 line
Update directories/files at the top-level.
........
r55471 | brett.cannon | 2007-05-20 12:05:06 -0700 (Sun, 20 May 2007) | 2 lines
Try to remove rgbimg from Windows builds.
........
r55474 | brett.cannon | 2007-05-20 16:17:38 -0700 (Sun, 20 May 2007) | 4 lines
Remove the macfs module. This led to the deprecation of macostools.touched();
it completely relied on macfs and is a no-op on OS X according to code
comments.
........
r55476 | brett.cannon | 2007-05-20 16:56:18 -0700 (Sun, 20 May 2007) | 3 lines
Move imgfile import to the global namespace to trigger an import error ASAP to
prevent creation of a test file.
........
r55477 | brett.cannon | 2007-05-20 16:57:38 -0700 (Sun, 20 May 2007) | 3 lines
Cause posixfile to raise a DeprecationWarning. Documented as deprecated since
Ptyhon 1.5.
........
r55479 | andrew.kuchling | 2007-05-20 17:03:15 -0700 (Sun, 20 May 2007) | 1 line
Note removed modules
........
r55481 | martin.v.loewis | 2007-05-20 21:35:47 -0700 (Sun, 20 May 2007) | 2 lines
Add Alexandre Vassalotti.
........
r55482 | george.yoshida | 2007-05-20 21:41:21 -0700 (Sun, 20 May 2007) | 4 lines
fix against r55474 [Remove the macfs module]
Remove "libmacfs.tex" from Makefile.deps and mac/mac.tex.
........
r55487 | raymond.hettinger | 2007-05-21 01:13:35 -0700 (Mon, 21 May 2007) | 1 line
Replace assertion with straight error-checking.
........
r55489 | raymond.hettinger | 2007-05-21 09:40:10 -0700 (Mon, 21 May 2007) | 1 line
Allow all alphanumeric and underscores in type and field names.
........
r55490 | facundo.batista | 2007-05-21 10:32:32 -0700 (Mon, 21 May 2007) | 5 lines
Added timeout support to HTTPSConnection, through the
socket.create_connection function. Also added a small
test for this, and updated NEWS file.
........
r55495 | georg.brandl | 2007-05-21 13:34:16 -0700 (Mon, 21 May 2007) | 2 lines
Patch #1686487: you can now pass any mapping after '**' in function calls.
........
r55502 | neal.norwitz | 2007-05-21 23:03:36 -0700 (Mon, 21 May 2007) | 1 line
Document new params to HTTPSConnection
........
r55504 | neal.norwitz | 2007-05-22 00:16:10 -0700 (Tue, 22 May 2007) | 1 line
Stop using METH_OLDARGS
........
r55505 | neal.norwitz | 2007-05-22 00:16:44 -0700 (Tue, 22 May 2007) | 1 line
Stop using METH_OLDARGS implicitly
........
................
2007-05-22 15:11:13 -03:00
|
|
|
if hasattr(func, '__call__'):
|
2000-07-07 17:45:21 -03:00
|
|
|
func()
|
2000-06-23 22:22:41 -03:00
|
|
|
else:
|
2001-08-10 15:59:30 -03:00
|
|
|
raise DistutilsClassError(
|
2004-02-12 13:35:32 -04:00
|
|
|
"invalid help function %r for help option '%s': "
|
2001-08-10 15:59:30 -03:00
|
|
|
"must be a callable object (function, etc.)"
|
2004-02-12 13:35:32 -04:00
|
|
|
% (func, help_option))
|
2000-06-23 22:22:41 -03:00
|
|
|
|
2001-12-06 16:51:35 -04:00
|
|
|
if help_option_found:
|
2000-07-07 17:45:21 -03:00
|
|
|
return
|
2000-06-07 00:00:06 -03:00
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
# Put the options from the command-line into their official
|
|
|
|
# holding pen, the 'command_options' dictionary.
|
2000-05-25 22:00:15 -03:00
|
|
|
opt_dict = self.get_option_dict(command)
|
2000-05-22 22:42:17 -03:00
|
|
|
for (name, value) in vars(opts).items():
|
2000-05-25 22:00:15 -03:00
|
|
|
opt_dict[name] = ("command line", value)
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
return args
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def finalize_options(self):
|
2001-03-21 23:06:52 -04:00
|
|
|
"""Set final values for all the options on the Distribution
|
|
|
|
instance, analogous to the .finalize_options() method of Command
|
|
|
|
objects.
|
|
|
|
"""
|
2009-06-01 19:36:26 -03:00
|
|
|
for attr in ('keywords', 'platforms'):
|
|
|
|
value = getattr(self.metadata, attr)
|
|
|
|
if value is None:
|
|
|
|
continue
|
|
|
|
if isinstance(value, str):
|
|
|
|
value = [elm.strip() for elm in value.split(',')]
|
|
|
|
setattr(self.metadata, attr, value)
|
2001-03-21 23:06:52 -04:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def _show_help(self, parser, global_options=1, display_options=1,
|
|
|
|
commands=[]):
|
2000-05-22 22:42:17 -03:00
|
|
|
"""Show help for the setup script command-line in the form of
|
|
|
|
several lists of command-line options. 'parser' should be a
|
|
|
|
FancyGetopt instance; do not expect it to be returned in the
|
|
|
|
same state, as its option table will be reset to make it
|
|
|
|
generate the correct help text.
|
|
|
|
|
|
|
|
If 'global_options' is true, lists the global options:
|
|
|
|
--verbose, --dry-run, etc. If 'display_options' is true, lists
|
|
|
|
the "display-only" options: --name, --version, etc. Finally,
|
|
|
|
lists per-command help for every command name or command class
|
|
|
|
in 'commands'.
|
|
|
|
"""
|
|
|
|
# late import because of mutual dependence between these modules
|
2000-08-28 22:15:18 -03:00
|
|
|
from distutils.core import gen_usage
|
2000-05-22 22:42:17 -03:00
|
|
|
from distutils.cmd import Command
|
|
|
|
|
|
|
|
if global_options:
|
2004-08-03 13:37:40 -03:00
|
|
|
if display_options:
|
|
|
|
options = self._get_toplevel_options()
|
|
|
|
else:
|
|
|
|
options = self.global_options
|
|
|
|
parser.set_option_table(options)
|
2005-03-03 04:12:27 -04:00
|
|
|
parser.print_help(self.common_usage + "\nGlobal options:")
|
2009-07-04 00:00:50 -03:00
|
|
|
print('')
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
if display_options:
|
2000-09-25 22:52:25 -03:00
|
|
|
parser.set_option_table(self.display_options)
|
|
|
|
parser.print_help(
|
2000-05-22 22:42:17 -03:00
|
|
|
"Information display options (just display " +
|
|
|
|
"information, ignore any commands)")
|
2009-07-04 00:00:50 -03:00
|
|
|
print('')
|
2000-05-22 22:42:17 -03:00
|
|
|
|
|
|
|
for command in self.commands:
|
2007-06-07 20:15:56 -03:00
|
|
|
if isinstance(command, type) and issubclass(command, Command):
|
2000-05-22 22:42:17 -03:00
|
|
|
klass = command
|
|
|
|
else:
|
2000-09-25 22:52:25 -03:00
|
|
|
klass = self.get_command_class(command)
|
2000-07-07 17:45:21 -03:00
|
|
|
if (hasattr(klass, 'help_options') and
|
2007-06-07 20:15:56 -03:00
|
|
|
isinstance(klass.help_options, list)):
|
2000-09-25 22:52:25 -03:00
|
|
|
parser.set_option_table(klass.user_options +
|
|
|
|
fix_help_options(klass.help_options))
|
2000-07-07 17:45:21 -03:00
|
|
|
else:
|
2000-09-25 22:52:25 -03:00
|
|
|
parser.set_option_table(klass.user_options)
|
|
|
|
parser.print_help("Options for '%s' command:" % klass.__name__)
|
2009-07-04 00:00:50 -03:00
|
|
|
print('')
|
2000-05-22 22:42:17 -03:00
|
|
|
|
2009-07-04 00:00:50 -03:00
|
|
|
print(gen_usage(self.script_name))
|
2000-05-22 22:42:17 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def handle_display_options(self, option_order):
|
2000-04-20 23:28:14 -03:00
|
|
|
"""If there were any non-global "display-only" options
|
2000-05-22 22:42:17 -03:00
|
|
|
(--help-commands or the metadata display options) on the command
|
|
|
|
line, display the requested info and return true; else return
|
|
|
|
false.
|
|
|
|
"""
|
2000-08-28 22:15:18 -03:00
|
|
|
from distutils.core import gen_usage
|
2000-04-20 23:28:14 -03:00
|
|
|
|
|
|
|
# User just wants a list of commands -- we'll print it out and stop
|
|
|
|
# processing now (ie. if they ran "setup --help-commands foo bar",
|
|
|
|
# we ignore "foo bar").
|
|
|
|
if self.help_commands:
|
2000-09-25 22:52:25 -03:00
|
|
|
self.print_commands()
|
2009-07-04 00:00:50 -03:00
|
|
|
print('')
|
|
|
|
print(gen_usage(self.script_name))
|
2000-04-20 23:28:14 -03:00
|
|
|
return 1
|
|
|
|
|
|
|
|
# If user supplied any of the "display metadata" options, then
|
|
|
|
# display that metadata in the order in which the user supplied the
|
|
|
|
# metadata options.
|
|
|
|
any_display_options = 0
|
|
|
|
is_display_option = {}
|
|
|
|
for option in self.display_options:
|
|
|
|
is_display_option[option[0]] = 1
|
|
|
|
|
|
|
|
for (opt, val) in option_order:
|
|
|
|
if val and is_display_option.get(opt):
|
2000-09-24 22:58:07 -03:00
|
|
|
opt = translate_longopt(opt)
|
2001-03-21 23:06:52 -04:00
|
|
|
value = getattr(self.metadata, "get_"+opt)()
|
|
|
|
if opt in ['keywords', 'platforms']:
|
2009-07-04 00:00:50 -03:00
|
|
|
print(','.join(value))
|
2005-03-20 18:19:47 -04:00
|
|
|
elif opt in ('classifiers', 'provides', 'requires',
|
|
|
|
'obsoletes'):
|
2009-07-04 00:00:50 -03:00
|
|
|
print('\n'.join(value))
|
2001-03-21 23:06:52 -04:00
|
|
|
else:
|
2009-07-04 00:00:50 -03:00
|
|
|
print(value)
|
2000-04-20 23:28:14 -03:00
|
|
|
any_display_options = 1
|
|
|
|
|
|
|
|
return any_display_options
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def print_command_list(self, commands, header, max_length):
|
2000-04-03 22:40:52 -03:00
|
|
|
"""Print a subset of the list of all commands -- used by
|
2000-05-22 22:42:17 -03:00
|
|
|
'print_commands()'.
|
|
|
|
"""
|
2009-07-04 00:00:50 -03:00
|
|
|
print(header + ":")
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
for cmd in commands:
|
2000-09-25 22:52:25 -03:00
|
|
|
klass = self.cmdclass.get(cmd)
|
2000-04-03 22:40:52 -03:00
|
|
|
if not klass:
|
2000-09-25 22:52:25 -03:00
|
|
|
klass = self.get_command_class(cmd)
|
2000-04-03 22:40:52 -03:00
|
|
|
try:
|
|
|
|
description = klass.description
|
|
|
|
except AttributeError:
|
|
|
|
description = "(no description available)"
|
|
|
|
|
2009-07-04 00:00:50 -03:00
|
|
|
print(" %-*s %s" % (max_length, cmd, description))
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def print_commands(self):
|
2000-05-22 22:42:17 -03:00
|
|
|
"""Print out a help message listing all available commands with a
|
|
|
|
description of each. The list is divided into "standard commands"
|
|
|
|
(listed in distutils.command.__all__) and "extra commands"
|
|
|
|
(mentioned in self.cmdclass, but not a standard command). The
|
|
|
|
descriptions come from the command class attribute
|
|
|
|
'description'.
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
import distutils.command
|
|
|
|
std_commands = distutils.command.__all__
|
|
|
|
is_std = {}
|
|
|
|
for cmd in std_commands:
|
|
|
|
is_std[cmd] = 1
|
|
|
|
|
|
|
|
extra_commands = []
|
|
|
|
for cmd in self.cmdclass.keys():
|
|
|
|
if not is_std.get(cmd):
|
2000-09-25 22:52:25 -03:00
|
|
|
extra_commands.append(cmd)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
max_length = 0
|
|
|
|
for cmd in (std_commands + extra_commands):
|
2000-09-25 22:52:25 -03:00
|
|
|
if len(cmd) > max_length:
|
|
|
|
max_length = len(cmd)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2000-09-25 22:52:25 -03:00
|
|
|
self.print_command_list(std_commands,
|
|
|
|
"Standard commands",
|
|
|
|
max_length)
|
2000-04-03 22:40:52 -03:00
|
|
|
if extra_commands:
|
2007-02-09 01:37:30 -04:00
|
|
|
print()
|
2000-09-25 22:52:25 -03:00
|
|
|
self.print_command_list(extra_commands,
|
|
|
|
"Extra commands",
|
|
|
|
max_length)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_command_list(self):
|
2000-11-10 22:47:11 -04:00
|
|
|
"""Get a list of (command, description) tuples.
|
|
|
|
The list is divided into "standard commands" (listed in
|
|
|
|
distutils.command.__all__) and "extra commands" (mentioned in
|
|
|
|
self.cmdclass, but not a standard command). The descriptions come
|
|
|
|
from the command class attribute 'description'.
|
|
|
|
"""
|
|
|
|
# Currently this is only used on Mac OS, for the Mac-only GUI
|
|
|
|
# Distutils interface (by Jack Jansen)
|
|
|
|
import distutils.command
|
|
|
|
std_commands = distutils.command.__all__
|
|
|
|
is_std = {}
|
|
|
|
for cmd in std_commands:
|
|
|
|
is_std[cmd] = 1
|
|
|
|
|
|
|
|
extra_commands = []
|
|
|
|
for cmd in self.cmdclass.keys():
|
|
|
|
if not is_std.get(cmd):
|
|
|
|
extra_commands.append(cmd)
|
|
|
|
|
|
|
|
rv = []
|
|
|
|
for cmd in (std_commands + extra_commands):
|
|
|
|
klass = self.cmdclass.get(cmd)
|
|
|
|
if not klass:
|
|
|
|
klass = self.get_command_class(cmd)
|
|
|
|
try:
|
|
|
|
description = klass.description
|
|
|
|
except AttributeError:
|
|
|
|
description = "(no description available)"
|
|
|
|
rv.append((cmd, description))
|
|
|
|
return rv
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# -- Command class/object methods ----------------------------------
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_command_packages(self):
|
2004-08-03 13:37:40 -03:00
|
|
|
"""Return a list of packages from which commands are loaded."""
|
|
|
|
pkgs = self.command_packages
|
2009-06-01 19:36:26 -03:00
|
|
|
if not isinstance(pkgs, list):
|
|
|
|
if pkgs is None:
|
|
|
|
pkgs = ''
|
|
|
|
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
|
2004-08-03 13:37:40 -03:00
|
|
|
if "distutils.command" not in pkgs:
|
|
|
|
pkgs.insert(0, "distutils.command")
|
|
|
|
self.command_packages = pkgs
|
|
|
|
return pkgs
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_command_class(self, command):
|
2000-05-22 22:42:17 -03:00
|
|
|
"""Return the class that implements the Distutils command named by
|
|
|
|
'command'. First we check the 'cmdclass' dictionary; if the
|
|
|
|
command is mentioned there, we fetch the class object from the
|
|
|
|
dictionary and return it. Otherwise we load the command module
|
|
|
|
("distutils.command." + command) and fetch the command class from
|
|
|
|
the module. The loaded class is also stored in 'cmdclass'
|
|
|
|
to speed future calls to 'get_command_class()'.
|
2000-05-11 21:41:33 -03:00
|
|
|
|
|
|
|
Raises DistutilsModuleError if the expected module could not be
|
2000-05-22 22:42:17 -03:00
|
|
|
found, or if that module does not define the expected class.
|
|
|
|
"""
|
|
|
|
klass = self.cmdclass.get(command)
|
|
|
|
if klass:
|
|
|
|
return klass
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2004-08-03 13:37:40 -03:00
|
|
|
for pkgname in self.get_command_packages():
|
|
|
|
module_name = "%s.%s" % (pkgname, command)
|
|
|
|
klass_name = command
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2004-08-03 13:37:40 -03:00
|
|
|
try:
|
|
|
|
__import__ (module_name)
|
|
|
|
module = sys.modules[module_name]
|
|
|
|
except ImportError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
klass = getattr(module, klass_name)
|
|
|
|
except AttributeError:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsModuleError(
|
|
|
|
"invalid command '%s' (no class '%s' in module '%s')"
|
|
|
|
% (command, klass_name, module_name))
|
2004-08-03 13:37:40 -03:00
|
|
|
|
|
|
|
self.cmdclass[command] = klass
|
|
|
|
return klass
|
|
|
|
|
|
|
|
raise DistutilsModuleError("invalid command '%s'" % command)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_command_obj(self, command, create=1):
|
2000-05-22 22:42:17 -03:00
|
|
|
"""Return the command object for 'command'. Normally this object
|
2000-07-26 23:13:20 -03:00
|
|
|
is cached on a previous call to 'get_command_obj()'; if no command
|
2000-05-22 22:42:17 -03:00
|
|
|
object for 'command' is in the cache, then we either create and
|
|
|
|
return it (if 'create' is true) or return None.
|
|
|
|
"""
|
|
|
|
cmd_obj = self.command_obj.get(command)
|
2000-04-03 22:40:52 -03:00
|
|
|
if not cmd_obj and create:
|
2000-06-01 22:59:33 -03:00
|
|
|
if DEBUG:
|
2009-06-01 19:36:26 -03:00
|
|
|
self.announce("Distribution.get_command_obj(): " \
|
|
|
|
"creating '%s' command object" % command)
|
2000-05-23 00:47:35 -03:00
|
|
|
|
2000-05-22 22:42:17 -03:00
|
|
|
klass = self.get_command_class(command)
|
2000-05-23 00:47:35 -03:00
|
|
|
cmd_obj = self.command_obj[command] = klass(self)
|
|
|
|
self.have_run[command] = 0
|
|
|
|
|
|
|
|
# Set any options that were supplied in config files
|
|
|
|
# or on the command line. (NB. support for error
|
|
|
|
# reporting is lame here: any errors aren't reported
|
|
|
|
# until 'finalize_options()' is called, which means
|
|
|
|
# we won't report the source of the error.)
|
|
|
|
options = self.command_options.get(command)
|
|
|
|
if options:
|
2000-05-28 20:53:06 -03:00
|
|
|
self._set_command_options(cmd_obj, options)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
return cmd_obj
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def _set_command_options(self, command_obj, option_dict=None):
|
2000-05-28 20:53:06 -03:00
|
|
|
"""Set the options for 'command_obj' from 'option_dict'. Basically
|
|
|
|
this means copying elements of a dictionary ('option_dict') to
|
|
|
|
attributes of an instance ('command').
|
|
|
|
|
2000-09-24 22:23:52 -03:00
|
|
|
'command_obj' must be a Command instance. If 'option_dict' is not
|
2000-05-28 20:53:06 -03:00
|
|
|
supplied, uses the standard option dictionary for this command
|
|
|
|
(from 'self.command_options').
|
|
|
|
"""
|
|
|
|
command_name = command_obj.get_command_name()
|
|
|
|
if option_dict is None:
|
|
|
|
option_dict = self.get_option_dict(command_name)
|
|
|
|
|
2009-06-01 19:36:26 -03:00
|
|
|
if DEBUG:
|
|
|
|
self.announce(" setting options for '%s' command:" % command_name)
|
2000-05-28 20:53:06 -03:00
|
|
|
for (option, (source, value)) in option_dict.items():
|
2009-06-01 19:36:26 -03:00
|
|
|
if DEBUG:
|
|
|
|
self.announce(" %s = %s (from %s)" % (option, value,
|
|
|
|
source))
|
2000-09-24 22:23:52 -03:00
|
|
|
try:
|
2008-07-26 17:09:45 -03:00
|
|
|
bool_opts = [translate_longopt(o)
|
|
|
|
for o in command_obj.boolean_options]
|
2000-09-24 22:23:52 -03:00
|
|
|
except AttributeError:
|
|
|
|
bool_opts = []
|
|
|
|
try:
|
|
|
|
neg_opt = command_obj.negative_opt
|
|
|
|
except AttributeError:
|
|
|
|
neg_opt = {}
|
|
|
|
|
|
|
|
try:
|
2007-10-16 15:12:55 -03:00
|
|
|
is_string = isinstance(value, str)
|
2006-08-18 19:13:04 -03:00
|
|
|
if option in neg_opt and is_string:
|
2000-09-24 22:23:52 -03:00
|
|
|
setattr(command_obj, neg_opt[option], not strtobool(value))
|
2000-09-26 21:15:37 -03:00
|
|
|
elif option in bool_opts and is_string:
|
2000-09-24 22:23:52 -03:00
|
|
|
setattr(command_obj, option, strtobool(value))
|
|
|
|
elif hasattr(command_obj, option):
|
|
|
|
setattr(command_obj, option, value)
|
|
|
|
else:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsOptionError(
|
|
|
|
"error in %s: command '%s' has no such option '%s'"
|
|
|
|
% (source, command_name, option))
|
2007-01-10 12:19:56 -04:00
|
|
|
except ValueError as msg:
|
2007-08-30 00:52:21 -03:00
|
|
|
raise DistutilsOptionError(msg)
|
2000-05-28 20:53:06 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def reinitialize_command(self, command, reinit_subcommands=0):
|
2000-05-28 20:53:06 -03:00
|
|
|
"""Reinitializes a command to the state it was in when first
|
|
|
|
returned by 'get_command_obj()': ie., initialized but not yet
|
2000-06-27 22:25:27 -03:00
|
|
|
finalized. This provides the opportunity to sneak option
|
2000-05-28 20:53:06 -03:00
|
|
|
values in programmatically, overriding or supplementing
|
|
|
|
user-supplied values from the config files and command line.
|
|
|
|
You'll have to re-finalize the command object (by calling
|
|
|
|
'finalize_options()' or 'ensure_finalized()') before using it for
|
2001-12-06 16:51:35 -04:00
|
|
|
real.
|
2000-05-28 20:53:06 -03:00
|
|
|
|
2000-09-16 12:23:28 -03:00
|
|
|
'command' should be a command name (string) or command object. If
|
|
|
|
'reinit_subcommands' is true, also reinitializes the command's
|
|
|
|
sub-commands, as declared by the 'sub_commands' class attribute (if
|
|
|
|
it has one). See the "install" command for an example. Only
|
|
|
|
reinitializes the sub-commands that actually matter, ie. those
|
|
|
|
whose test predicates return true.
|
|
|
|
|
2000-05-28 20:53:06 -03:00
|
|
|
Returns the reinitialized command object.
|
|
|
|
"""
|
|
|
|
from distutils.cmd import Command
|
|
|
|
if not isinstance(command, Command):
|
|
|
|
command_name = command
|
|
|
|
command = self.get_command_obj(command_name)
|
|
|
|
else:
|
|
|
|
command_name = command.get_command_name()
|
|
|
|
|
|
|
|
if not command.finalized:
|
2000-05-31 22:09:47 -03:00
|
|
|
return command
|
2000-05-28 20:53:06 -03:00
|
|
|
command.initialize_options()
|
|
|
|
command.finalized = 0
|
2000-06-05 23:52:36 -03:00
|
|
|
self.have_run[command_name] = 0
|
2000-05-28 20:53:06 -03:00
|
|
|
self._set_command_options(command)
|
2000-09-16 12:23:28 -03:00
|
|
|
|
|
|
|
if reinit_subcommands:
|
|
|
|
for sub in command.get_sub_commands():
|
2001-12-06 16:51:35 -04:00
|
|
|
self.reinitialize_command(sub, reinit_subcommands)
|
2000-09-16 12:23:28 -03:00
|
|
|
|
2000-05-28 20:53:06 -03:00
|
|
|
return command
|
|
|
|
|
2000-04-03 22:40:52 -03:00
|
|
|
# -- Methods that operate on the Distribution ----------------------
|
|
|
|
|
2009-07-03 23:04:21 -03:00
|
|
|
def announce(self, msg, level=log.INFO):
|
|
|
|
log.log(level, msg)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def run_commands(self):
|
2000-04-20 23:28:14 -03:00
|
|
|
"""Run each command that was seen on the setup script command line.
|
2000-05-22 22:42:17 -03:00
|
|
|
Uses the list of commands found and cache of command objects
|
2000-09-25 22:52:25 -03:00
|
|
|
created by 'get_command_obj()'.
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
for cmd in self.commands:
|
2000-09-25 22:52:25 -03:00
|
|
|
self.run_command(cmd)
|
2000-04-03 22:40:52 -03:00
|
|
|
|
|
|
|
# -- Methods that operate on its Commands --------------------------
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def run_command(self, command):
|
2000-04-03 22:40:52 -03:00
|
|
|
"""Do whatever it takes to run a command (including nothing at all,
|
2000-05-22 22:42:17 -03:00
|
|
|
if the command has already been run). Specifically: if we have
|
|
|
|
already created and run the command named by 'command', return
|
|
|
|
silently without doing anything. If the command named by 'command'
|
|
|
|
doesn't even have a command object yet, create one. Then invoke
|
|
|
|
'run()' on that command object (or an existing one).
|
|
|
|
"""
|
2000-04-03 22:40:52 -03:00
|
|
|
# Already been here, done that? then return silently.
|
2000-09-25 22:52:25 -03:00
|
|
|
if self.have_run.get(command):
|
2000-04-03 22:40:52 -03:00
|
|
|
return
|
|
|
|
|
2002-06-04 17:14:43 -03:00
|
|
|
log.info("running %s", command)
|
2000-09-25 22:52:25 -03:00
|
|
|
cmd_obj = self.get_command_obj(command)
|
|
|
|
cmd_obj.ensure_finalized()
|
|
|
|
cmd_obj.run()
|
2000-04-03 22:40:52 -03:00
|
|
|
self.have_run[command] = 1
|
|
|
|
|
|
|
|
|
|
|
|
# -- Distribution query methods ------------------------------------
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_pure_modules(self):
|
2000-09-25 22:52:25 -03:00
|
|
|
return len(self.packages or self.py_modules or []) > 0
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_ext_modules(self):
|
2000-09-25 22:52:25 -03:00
|
|
|
return self.ext_modules and len(self.ext_modules) > 0
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_c_libraries(self):
|
2000-09-25 22:52:25 -03:00
|
|
|
return self.libraries and len(self.libraries) > 0
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_modules(self):
|
2000-04-03 22:40:52 -03:00
|
|
|
return self.has_pure_modules() or self.has_ext_modules()
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_headers(self):
|
2000-05-26 22:36:14 -03:00
|
|
|
return self.headers and len(self.headers) > 0
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_scripts(self):
|
2000-05-20 12:06:48 -03:00
|
|
|
return self.scripts and len(self.scripts) > 0
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def has_data_files(self):
|
2000-05-20 12:06:48 -03:00
|
|
|
return self.data_files and len(self.data_files) > 0
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def is_pure(self):
|
2000-04-03 22:40:52 -03:00
|
|
|
return (self.has_pure_modules() and
|
|
|
|
not self.has_ext_modules() and
|
|
|
|
not self.has_c_libraries())
|
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
# -- Metadata query methods ----------------------------------------
|
|
|
|
|
|
|
|
# If you're looking for 'get_name()', 'get_version()', and so forth,
|
|
|
|
# they are defined in a sneaky way: the constructor binds self.get_XXX
|
|
|
|
# to self.metadata.get_XXX. The actual code is in the
|
|
|
|
# DistributionMetadata class, below.
|
|
|
|
|
|
|
|
class DistributionMetadata:
|
|
|
|
"""Dummy class to hold the distribution meta-data: name, version,
|
2000-09-25 22:52:25 -03:00
|
|
|
author, and so forth.
|
|
|
|
"""
|
2000-04-20 23:28:14 -03:00
|
|
|
|
2001-09-03 12:47:21 -03:00
|
|
|
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
|
|
|
|
"maintainer", "maintainer_email", "url",
|
|
|
|
"license", "description", "long_description",
|
|
|
|
"keywords", "platforms", "fullname", "contact",
|
2003-03-03 16:07:27 -04:00
|
|
|
"contact_email", "license", "classifiers",
|
2005-03-20 18:19:47 -04:00
|
|
|
"download_url",
|
|
|
|
# PEP 314
|
|
|
|
"provides", "requires", "obsoletes",
|
|
|
|
)
|
2001-09-03 12:47:21 -03:00
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
def __init__ (self):
|
|
|
|
self.name = None
|
|
|
|
self.version = None
|
|
|
|
self.author = None
|
|
|
|
self.author_email = None
|
|
|
|
self.maintainer = None
|
|
|
|
self.maintainer_email = None
|
|
|
|
self.url = None
|
2001-08-10 15:49:23 -03:00
|
|
|
self.license = None
|
2000-04-20 23:28:14 -03:00
|
|
|
self.description = None
|
2000-04-25 23:26:55 -03:00
|
|
|
self.long_description = None
|
2001-03-21 23:06:52 -04:00
|
|
|
self.keywords = None
|
|
|
|
self.platforms = None
|
2003-01-03 11:24:36 -04:00
|
|
|
self.classifiers = None
|
2003-02-19 10:16:01 -04:00
|
|
|
self.download_url = None
|
2005-03-20 18:19:47 -04:00
|
|
|
# PEP 314
|
|
|
|
self.provides = None
|
|
|
|
self.requires = None
|
|
|
|
self.obsoletes = None
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def write_pkg_info(self, base_dir):
|
2001-03-21 23:06:52 -04:00
|
|
|
"""Write the PKG-INFO file into the release tree.
|
|
|
|
"""
|
|
|
|
pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w')
|
2005-03-20 18:19:47 -04:00
|
|
|
self.write_pkg_file(pkg_info)
|
|
|
|
pkg_info.close()
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def write_pkg_file(self, file):
|
2005-03-20 18:19:47 -04:00
|
|
|
"""Write the PKG-INFO format data to a file object.
|
|
|
|
"""
|
|
|
|
version = '1.0'
|
|
|
|
if self.provides or self.requires or self.obsoletes:
|
|
|
|
version = '1.1'
|
|
|
|
|
|
|
|
file.write('Metadata-Version: %s\n' % version)
|
|
|
|
file.write('Name: %s\n' % self.get_name() )
|
|
|
|
file.write('Version: %s\n' % self.get_version() )
|
|
|
|
file.write('Summary: %s\n' % self.get_description() )
|
|
|
|
file.write('Home-page: %s\n' % self.get_url() )
|
|
|
|
file.write('Author: %s\n' % self.get_contact() )
|
|
|
|
file.write('Author-email: %s\n' % self.get_contact_email() )
|
|
|
|
file.write('License: %s\n' % self.get_license() )
|
2003-02-19 10:16:01 -04:00
|
|
|
if self.download_url:
|
2005-03-20 18:19:47 -04:00
|
|
|
file.write('Download-URL: %s\n' % self.download_url)
|
2001-03-21 23:06:52 -04:00
|
|
|
|
2009-06-01 19:36:26 -03:00
|
|
|
long_desc = rfc822_escape(self.get_long_description())
|
2005-03-20 18:19:47 -04:00
|
|
|
file.write('Description: %s\n' % long_desc)
|
2001-03-21 23:06:52 -04:00
|
|
|
|
2007-04-17 05:48:32 -03:00
|
|
|
keywords = ','.join(self.get_keywords())
|
2001-03-21 23:06:52 -04:00
|
|
|
if keywords:
|
2005-03-20 18:19:47 -04:00
|
|
|
file.write('Keywords: %s\n' % keywords )
|
2001-03-21 23:06:52 -04:00
|
|
|
|
2005-03-20 18:19:47 -04:00
|
|
|
self._write_list(file, 'Platform', self.get_platforms())
|
|
|
|
self._write_list(file, 'Classifier', self.get_classifiers())
|
2003-01-03 11:24:36 -04:00
|
|
|
|
2005-03-20 18:19:47 -04:00
|
|
|
# PEP 314
|
|
|
|
self._write_list(file, 'Requires', self.get_requires())
|
|
|
|
self._write_list(file, 'Provides', self.get_provides())
|
|
|
|
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def _write_list(self, file, name, values):
|
2005-03-20 18:19:47 -04:00
|
|
|
for value in values:
|
|
|
|
file.write('%s: %s\n' % (name, value))
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
# -- Metadata query methods ----------------------------------------
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_name(self):
|
2000-04-03 22:40:52 -03:00
|
|
|
return self.name or "UNKNOWN"
|
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
def get_version(self):
|
2001-12-06 16:44:19 -04:00
|
|
|
return self.version or "0.0.0"
|
2000-04-20 23:28:14 -03:00
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def get_fullname(self):
|
2000-04-20 23:28:14 -03:00
|
|
|
return "%s-%s" % (self.get_name(), self.get_version())
|
|
|
|
|
|
|
|
def get_author(self):
|
|
|
|
return self.author or "UNKNOWN"
|
2000-04-03 22:40:52 -03:00
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
def get_author_email(self):
|
|
|
|
return self.author_email or "UNKNOWN"
|
|
|
|
|
|
|
|
def get_maintainer(self):
|
|
|
|
return self.maintainer or "UNKNOWN"
|
|
|
|
|
|
|
|
def get_maintainer_email(self):
|
|
|
|
return self.maintainer_email or "UNKNOWN"
|
|
|
|
|
|
|
|
def get_contact(self):
|
2009-05-16 15:37:32 -03:00
|
|
|
return self.maintainer or self.author or "UNKNOWN"
|
2000-04-20 23:28:14 -03:00
|
|
|
|
|
|
|
def get_contact_email(self):
|
2009-05-16 15:37:32 -03:00
|
|
|
return self.maintainer_email or self.author_email or "UNKNOWN"
|
2000-04-20 23:28:14 -03:00
|
|
|
|
|
|
|
def get_url(self):
|
|
|
|
return self.url or "UNKNOWN"
|
|
|
|
|
2001-08-10 15:49:23 -03:00
|
|
|
def get_license(self):
|
|
|
|
return self.license or "UNKNOWN"
|
|
|
|
get_licence = get_license
|
2001-12-06 16:51:35 -04:00
|
|
|
|
2000-04-20 23:28:14 -03:00
|
|
|
def get_description(self):
|
|
|
|
return self.description or "UNKNOWN"
|
2000-04-25 23:26:55 -03:00
|
|
|
|
|
|
|
def get_long_description(self):
|
|
|
|
return self.long_description or "UNKNOWN"
|
|
|
|
|
2001-03-21 23:06:52 -04:00
|
|
|
def get_keywords(self):
|
|
|
|
return self.keywords or []
|
|
|
|
|
|
|
|
def get_platforms(self):
|
|
|
|
return self.platforms or ["UNKNOWN"]
|
|
|
|
|
2003-01-03 11:24:36 -04:00
|
|
|
def get_classifiers(self):
|
|
|
|
return self.classifiers or []
|
|
|
|
|
2003-02-19 10:16:01 -04:00
|
|
|
def get_download_url(self):
|
|
|
|
return self.download_url or "UNKNOWN"
|
|
|
|
|
2005-03-20 18:19:47 -04:00
|
|
|
# PEP 314
|
|
|
|
def get_requires(self):
|
|
|
|
return self.requires or []
|
|
|
|
|
|
|
|
def set_requires(self, value):
|
|
|
|
import distutils.versionpredicate
|
|
|
|
for v in value:
|
|
|
|
distutils.versionpredicate.VersionPredicate(v)
|
|
|
|
self.requires = value
|
|
|
|
|
|
|
|
def get_provides(self):
|
|
|
|
return self.provides or []
|
|
|
|
|
|
|
|
def set_provides(self, value):
|
|
|
|
value = [v.strip() for v in value]
|
|
|
|
for v in value:
|
|
|
|
import distutils.versionpredicate
|
2005-03-21 02:36:32 -04:00
|
|
|
distutils.versionpredicate.split_provision(v)
|
2005-03-20 18:19:47 -04:00
|
|
|
self.provides = value
|
|
|
|
|
|
|
|
def get_obsoletes(self):
|
|
|
|
return self.obsoletes or []
|
|
|
|
|
|
|
|
def set_obsoletes(self, value):
|
|
|
|
import distutils.versionpredicate
|
|
|
|
for v in value:
|
|
|
|
distutils.versionpredicate.VersionPredicate(v)
|
|
|
|
self.obsoletes = value
|
|
|
|
|
2009-05-16 15:37:32 -03:00
|
|
|
def fix_help_options(options):
|
2000-06-23 21:23:20 -03:00
|
|
|
"""Convert a 4-tuple 'help_options' list as found in various command
|
|
|
|
classes to the 3-tuple form required by FancyGetopt.
|
|
|
|
"""
|
|
|
|
new_options = []
|
|
|
|
for help_tuple in options:
|
|
|
|
new_options.append(help_tuple[0:3])
|
|
|
|
return new_options
|