mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 22:24:45 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -3,10 +3,11 @@
|
|||
Provides the Distribution class, which represents the module distribution
|
||||
being built/installed/distributed.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from email import message_from_file
|
||||
|
||||
try:
|
||||
|
|
@ -65,12 +66,14 @@ class Distribution:
|
|||
# have minimal control over.
|
||||
# The fourth entry for verbose means that it can be repeated.
|
||||
global_options = [
|
||||
('verbose', 'v', "run verbosely (default)", 1),
|
||||
('quiet', 'q', "run quietly (turns verbosity off)"),
|
||||
('verbose', 'v', 'run verbosely (default)', 1),
|
||||
('quiet', 'q', 'run quietly (turns verbosity off)'),
|
||||
('dry-run', 'n', "don't actually do anything"),
|
||||
('help', 'h', "show detailed help message"),
|
||||
('no-user-cfg', None,
|
||||
'ignore pydistutils.cfg in your home directory'),
|
||||
('help', 'h', 'show detailed help message'),
|
||||
(
|
||||
'no-user-cfg', None,
|
||||
'ignore pydistutils.cfg in your home directory',
|
||||
),
|
||||
]
|
||||
|
||||
# 'common_usage' is a short (2-3 line) string describing the common
|
||||
|
|
@ -84,49 +87,91 @@ Common commands: (see '--help-commands' for more)
|
|||
|
||||
# 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,
|
||||
"print the maintainer's name if known, else the author's"),
|
||||
('contact-email', None,
|
||||
"print the maintainer's email address if known, else the author's"),
|
||||
('url', None,
|
||||
"print the URL for this package"),
|
||||
('license', None,
|
||||
"print the license of the package"),
|
||||
('licence', None,
|
||||
"alias for --license"),
|
||||
('description', None,
|
||||
"print the package description"),
|
||||
('long-description', None,
|
||||
"print the long package description"),
|
||||
('platforms', None,
|
||||
"print the list of platforms"),
|
||||
('classifiers', None,
|
||||
"print the list of classifiers"),
|
||||
('keywords', None,
|
||||
"print the list of keywords"),
|
||||
('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")
|
||||
]
|
||||
(
|
||||
'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,
|
||||
"print the maintainer's name if known, else the author's",
|
||||
),
|
||||
(
|
||||
'contact-email', None,
|
||||
"print the maintainer's email address if known, else the author's",
|
||||
),
|
||||
(
|
||||
'url', None,
|
||||
'print the URL for this package',
|
||||
),
|
||||
(
|
||||
'license', None,
|
||||
'print the license of the package',
|
||||
),
|
||||
(
|
||||
'licence', None,
|
||||
'alias for --license',
|
||||
),
|
||||
(
|
||||
'description', None,
|
||||
'print the package description',
|
||||
),
|
||||
(
|
||||
'long-description', None,
|
||||
'print the long package description',
|
||||
),
|
||||
(
|
||||
'platforms', None,
|
||||
'print the list of platforms',
|
||||
),
|
||||
(
|
||||
'classifiers', None,
|
||||
'print the list of classifiers',
|
||||
),
|
||||
(
|
||||
'keywords', None,
|
||||
'print the list of keywords',
|
||||
),
|
||||
(
|
||||
'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',
|
||||
),
|
||||
]
|
||||
display_option_names = [translate_longopt(x[0]) for x in display_options]
|
||||
|
||||
# negative options are options that exclude other options
|
||||
|
|
@ -159,7 +204,7 @@ Common commands: (see '--help-commands' for more)
|
|||
# object in a sneaky and underhanded (but efficient!) way.
|
||||
self.metadata = DistributionMetadata()
|
||||
for basename in self.metadata._METHOD_BASENAMES:
|
||||
method_name = "get_" + basename
|
||||
method_name = 'get_' + basename
|
||||
setattr(self, method_name, getattr(self.metadata, method_name))
|
||||
|
||||
# 'cmdclass' maps command names to class objects, so we
|
||||
|
|
@ -250,7 +295,7 @@ Common commands: (see '--help-commands' for more)
|
|||
for (command, cmd_options) in options.items():
|
||||
opt_dict = self.get_option_dict(command)
|
||||
for (opt, val) in cmd_options.items():
|
||||
opt_dict[opt] = ("setup script", val)
|
||||
opt_dict[opt] = ('setup script', val)
|
||||
|
||||
if 'licence' in attrs:
|
||||
attrs['license'] = attrs['licence']
|
||||
|
|
@ -259,19 +304,19 @@ Common commands: (see '--help-commands' for more)
|
|||
if warnings is not None:
|
||||
warnings.warn(msg)
|
||||
else:
|
||||
sys.stderr.write(msg + "\n")
|
||||
sys.stderr.write(msg + '\n')
|
||||
|
||||
# Now work on the rest of the attributes. Any attribute that's
|
||||
# not already defined is invalid!
|
||||
for (key, val) in attrs.items():
|
||||
if hasattr(self.metadata, "set_" + key):
|
||||
getattr(self.metadata, "set_" + key)(val)
|
||||
if hasattr(self.metadata, 'set_' + key):
|
||||
getattr(self.metadata, 'set_' + key)(val)
|
||||
elif hasattr(self.metadata, key):
|
||||
setattr(self.metadata, key, val)
|
||||
elif hasattr(self, key):
|
||||
setattr(self, key, val)
|
||||
else:
|
||||
msg = "Unknown distribution option: %s" % repr(key)
|
||||
msg = 'Unknown distribution option: %s' % repr(key)
|
||||
warnings.warn(msg)
|
||||
|
||||
# no-user-cfg is handled before other command line args
|
||||
|
|
@ -303,7 +348,7 @@ Common commands: (see '--help-commands' for more)
|
|||
dict = self.command_options[command] = {}
|
||||
return dict
|
||||
|
||||
def dump_option_dicts(self, header=None, commands=None, indent=""):
|
||||
def dump_option_dicts(self, header=None, commands=None, indent=''):
|
||||
from pprint import pformat
|
||||
|
||||
if commands is None: # dump all command option dicts
|
||||
|
|
@ -311,23 +356,27 @@ Common commands: (see '--help-commands' for more)
|
|||
|
||||
if header is not None:
|
||||
self.announce(indent + header)
|
||||
indent = indent + " "
|
||||
indent = indent + ' '
|
||||
|
||||
if not commands:
|
||||
self.announce(indent + "no commands known yet")
|
||||
self.announce(indent + 'no commands known yet')
|
||||
return
|
||||
|
||||
for cmd_name in commands:
|
||||
opt_dict = self.command_options.get(cmd_name)
|
||||
if opt_dict is None:
|
||||
self.announce(indent +
|
||||
"no option dict for '%s' command" % cmd_name)
|
||||
self.announce(
|
||||
indent +
|
||||
"no option dict for '%s' command" % cmd_name,
|
||||
)
|
||||
else:
|
||||
self.announce(indent +
|
||||
"option dict for '%s' command:" % cmd_name)
|
||||
self.announce(
|
||||
indent +
|
||||
"option dict for '%s' command:" % cmd_name,
|
||||
)
|
||||
out = pformat(opt_dict)
|
||||
for line in out.split('\n'):
|
||||
self.announce(indent + " " + line)
|
||||
self.announce(indent + ' ' + line)
|
||||
|
||||
# -- Config file finding/parsing methods ---------------------------
|
||||
|
||||
|
|
@ -353,15 +402,15 @@ Common commands: (see '--help-commands' for more)
|
|||
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
|
||||
|
||||
# Look for the system config file
|
||||
sys_file = os.path.join(sys_dir, "distutils.cfg")
|
||||
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':
|
||||
user_filename = ".pydistutils.cfg"
|
||||
user_filename = '.pydistutils.cfg'
|
||||
else:
|
||||
user_filename = "pydistutils.cfg"
|
||||
user_filename = 'pydistutils.cfg'
|
||||
|
||||
# And look for the user config file
|
||||
if self.want_user_cfg:
|
||||
|
|
@ -370,12 +419,12 @@ Common commands: (see '--help-commands' for more)
|
|||
files.append(user_file)
|
||||
|
||||
# All platforms support local setup.cfg
|
||||
local_file = "setup.cfg"
|
||||
local_file = 'setup.cfg'
|
||||
if os.path.isfile(local_file):
|
||||
files.append(local_file)
|
||||
|
||||
if DEBUG:
|
||||
self.announce("using config files: %s" % ', '.join(files))
|
||||
self.announce('using config files: %s' % ', '.join(files))
|
||||
|
||||
return files
|
||||
|
||||
|
|
@ -388,7 +437,8 @@ Common commands: (see '--help-commands' for more)
|
|||
'install-base', 'install-platbase', 'install-lib',
|
||||
'install-platlib', 'install-purelib', 'install-headers',
|
||||
'install-scripts', 'install-data', 'prefix', 'exec-prefix',
|
||||
'home', 'user', 'root']
|
||||
'home', 'user', 'root',
|
||||
]
|
||||
else:
|
||||
ignore_options = []
|
||||
|
||||
|
|
@ -398,12 +448,12 @@ Common commands: (see '--help-commands' for more)
|
|||
filenames = self.find_config_files()
|
||||
|
||||
if DEBUG:
|
||||
self.announce("Distribution.parse_config_files():")
|
||||
self.announce('Distribution.parse_config_files():')
|
||||
|
||||
parser = ConfigParser()
|
||||
for filename in filenames:
|
||||
if DEBUG:
|
||||
self.announce(" reading %s" % filename)
|
||||
self.announce(' reading %s' % filename)
|
||||
parser.read(filename)
|
||||
for section in parser.sections():
|
||||
options = parser.options(section)
|
||||
|
|
@ -411,7 +461,7 @@ Common commands: (see '--help-commands' for more)
|
|||
|
||||
for opt in options:
|
||||
if opt != '__name__' and opt not in ignore_options:
|
||||
val = parser.get(section,opt)
|
||||
val = parser.get(section, opt)
|
||||
opt = opt.replace('-', '_')
|
||||
opt_dict[opt] = (filename, val)
|
||||
|
||||
|
|
@ -428,7 +478,7 @@ Common commands: (see '--help-commands' for more)
|
|||
try:
|
||||
if alias:
|
||||
setattr(self, alias, not strtobool(val))
|
||||
elif opt in ('verbose', 'dry_run'): # ugh!
|
||||
elif opt in ('verbose', 'dry_run'): # ugh!
|
||||
setattr(self, opt, strtobool(val))
|
||||
else:
|
||||
setattr(self, opt, val)
|
||||
|
|
@ -492,14 +542,16 @@ Common commands: (see '--help-commands' for more)
|
|||
# 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)
|
||||
self._show_help(
|
||||
parser,
|
||||
display_options=len(self.commands) == 0,
|
||||
commands=self.commands,
|
||||
)
|
||||
return
|
||||
|
||||
# Oops, no commands found -- an end-user error
|
||||
if not self.commands:
|
||||
raise DistutilsArgError("no commands supplied")
|
||||
raise DistutilsArgError('no commands supplied')
|
||||
|
||||
# All is well: return true
|
||||
return True
|
||||
|
|
@ -511,9 +563,11 @@ Common commands: (see '--help-commands' for more)
|
|||
level as well as options recognized for commands.
|
||||
"""
|
||||
return self.global_options + [
|
||||
("command-packages=", None,
|
||||
"list of packages that provide distutils commands"),
|
||||
]
|
||||
(
|
||||
'command-packages=', None,
|
||||
'list of packages that provide distutils commands',
|
||||
),
|
||||
]
|
||||
|
||||
def _parse_command_opts(self, parser, args):
|
||||
"""Parse the command-line options for a single command.
|
||||
|
|
@ -545,14 +599,19 @@ Common commands: (see '--help-commands' for more)
|
|||
# to be sure that the basic "command" interface is implemented.
|
||||
if not issubclass(cmd_class, Command):
|
||||
raise DistutilsClassError(
|
||||
"command class %s must subclass Command" % cmd_class)
|
||||
'command class %s must subclass Command' % cmd_class,
|
||||
)
|
||||
|
||||
# Also make sure that the command object provides a list of its
|
||||
# known options.
|
||||
if not (hasattr(cmd_class, 'user_options') and
|
||||
isinstance(cmd_class.user_options, list)):
|
||||
msg = ("command class %s must provide "
|
||||
"'user_options' attribute (a list of tuples)")
|
||||
if not (
|
||||
hasattr(cmd_class, 'user_options') and
|
||||
isinstance(cmd_class.user_options, list)
|
||||
):
|
||||
msg = (
|
||||
'command class %s must provide '
|
||||
"'user_options' attribute (a list of tuples)"
|
||||
)
|
||||
raise DistutilsClassError(msg % cmd_class)
|
||||
|
||||
# If the command class has a list of negative alias options,
|
||||
|
|
@ -564,36 +623,43 @@ Common commands: (see '--help-commands' for more)
|
|||
|
||||
# Check for help_options in command class. They have a different
|
||||
# format (tuple of four) so we need to preprocess them here.
|
||||
if (hasattr(cmd_class, 'help_options') and
|
||||
isinstance(cmd_class.help_options, list)):
|
||||
if (
|
||||
hasattr(cmd_class, 'help_options') and
|
||||
isinstance(cmd_class.help_options, list)
|
||||
):
|
||||
help_options = fix_help_options(cmd_class.help_options)
|
||||
else:
|
||||
help_options = []
|
||||
|
||||
# All commands support the global options too, just by adding
|
||||
# in 'global_options'.
|
||||
parser.set_option_table(self.global_options +
|
||||
cmd_class.user_options +
|
||||
help_options)
|
||||
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:])
|
||||
if hasattr(opts, 'help') and opts.help:
|
||||
self._show_help(parser, display_options=0, commands=[cmd_class])
|
||||
return
|
||||
|
||||
if (hasattr(cmd_class, 'help_options') and
|
||||
isinstance(cmd_class.help_options, list)):
|
||||
help_option_found=0
|
||||
if (
|
||||
hasattr(cmd_class, 'help_options') and
|
||||
isinstance(cmd_class.help_options, list)
|
||||
):
|
||||
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
|
||||
help_option_found = 1
|
||||
if callable(func):
|
||||
func()
|
||||
else:
|
||||
raise DistutilsClassError(
|
||||
"invalid help function %r for help option '%s': "
|
||||
"must be a callable object (function, etc.)"
|
||||
% (func, help_option))
|
||||
'must be a callable object (function, etc.)'
|
||||
% (func, help_option),
|
||||
)
|
||||
|
||||
if help_option_found:
|
||||
return
|
||||
|
|
@ -602,7 +668,7 @@ Common commands: (see '--help-commands' for more)
|
|||
# holding pen, the 'command_options' dictionary.
|
||||
opt_dict = self.get_option_dict(command)
|
||||
for (name, value) in vars(opts).items():
|
||||
opt_dict[name] = ("command line", value)
|
||||
opt_dict[name] = ('command line', value)
|
||||
|
||||
return args
|
||||
|
||||
|
|
@ -619,8 +685,10 @@ Common commands: (see '--help-commands' for more)
|
|||
value = [elm.strip() for elm in value.split(',')]
|
||||
setattr(self.metadata, attr, value)
|
||||
|
||||
def _show_help(self, parser, global_options=1, display_options=1,
|
||||
commands=[]):
|
||||
def _show_help(
|
||||
self, parser, global_options=1, display_options=1,
|
||||
commands=[],
|
||||
):
|
||||
"""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
|
||||
|
|
@ -643,14 +711,15 @@ Common commands: (see '--help-commands' for more)
|
|||
else:
|
||||
options = self.global_options
|
||||
parser.set_option_table(options)
|
||||
parser.print_help(self.common_usage + "\nGlobal options:")
|
||||
parser.print_help(self.common_usage + '\nGlobal options:')
|
||||
print('')
|
||||
|
||||
if display_options:
|
||||
parser.set_option_table(self.display_options)
|
||||
parser.print_help(
|
||||
"Information display options (just display " +
|
||||
"information, ignore any commands)")
|
||||
'Information display options (just display ' +
|
||||
'information, ignore any commands)',
|
||||
)
|
||||
print('')
|
||||
|
||||
for command in self.commands:
|
||||
|
|
@ -658,10 +727,14 @@ Common commands: (see '--help-commands' for more)
|
|||
klass = command
|
||||
else:
|
||||
klass = self.get_command_class(command)
|
||||
if (hasattr(klass, 'help_options') and
|
||||
isinstance(klass.help_options, list)):
|
||||
parser.set_option_table(klass.user_options +
|
||||
fix_help_options(klass.help_options))
|
||||
if (
|
||||
hasattr(klass, 'help_options') and
|
||||
isinstance(klass.help_options, list)
|
||||
):
|
||||
parser.set_option_table(
|
||||
klass.user_options +
|
||||
fix_help_options(klass.help_options),
|
||||
)
|
||||
else:
|
||||
parser.set_option_table(klass.user_options)
|
||||
parser.print_help("Options for '%s' command:" % klass.__name__)
|
||||
|
|
@ -697,11 +770,13 @@ Common commands: (see '--help-commands' for more)
|
|||
for (opt, val) in option_order:
|
||||
if val and is_display_option.get(opt):
|
||||
opt = translate_longopt(opt)
|
||||
value = getattr(self.metadata, "get_"+opt)()
|
||||
value = getattr(self.metadata, 'get_' + opt)()
|
||||
if opt in ['keywords', 'platforms']:
|
||||
print(','.join(value))
|
||||
elif opt in ('classifiers', 'provides', 'requires',
|
||||
'obsoletes'):
|
||||
elif opt in (
|
||||
'classifiers', 'provides', 'requires',
|
||||
'obsoletes',
|
||||
):
|
||||
print('\n'.join(value))
|
||||
else:
|
||||
print(value)
|
||||
|
|
@ -713,7 +788,7 @@ Common commands: (see '--help-commands' for more)
|
|||
"""Print a subset of the list of all commands -- used by
|
||||
'print_commands()'.
|
||||
"""
|
||||
print(header + ":")
|
||||
print(header + ':')
|
||||
|
||||
for cmd in commands:
|
||||
klass = self.cmdclass.get(cmd)
|
||||
|
|
@ -722,9 +797,9 @@ Common commands: (see '--help-commands' for more)
|
|||
try:
|
||||
description = klass.description
|
||||
except AttributeError:
|
||||
description = "(no description available)"
|
||||
description = '(no description available)'
|
||||
|
||||
print(" %-*s %s" % (max_length, cmd, description))
|
||||
print(' %-*s %s' % (max_length, cmd, description))
|
||||
|
||||
def print_commands(self):
|
||||
"""Print out a help message listing all available commands with a
|
||||
|
|
@ -750,14 +825,18 @@ Common commands: (see '--help-commands' for more)
|
|||
if len(cmd) > max_length:
|
||||
max_length = len(cmd)
|
||||
|
||||
self.print_command_list(std_commands,
|
||||
"Standard commands",
|
||||
max_length)
|
||||
self.print_command_list(
|
||||
std_commands,
|
||||
'Standard commands',
|
||||
max_length,
|
||||
)
|
||||
if extra_commands:
|
||||
print()
|
||||
self.print_command_list(extra_commands,
|
||||
"Extra commands",
|
||||
max_length)
|
||||
self.print_command_list(
|
||||
extra_commands,
|
||||
'Extra commands',
|
||||
max_length,
|
||||
)
|
||||
|
||||
def get_command_list(self):
|
||||
"""Get a list of (command, description) tuples.
|
||||
|
|
@ -787,7 +866,7 @@ Common commands: (see '--help-commands' for more)
|
|||
try:
|
||||
description = klass.description
|
||||
except AttributeError:
|
||||
description = "(no description available)"
|
||||
description = '(no description available)'
|
||||
rv.append((cmd, description))
|
||||
return rv
|
||||
|
||||
|
|
@ -800,8 +879,8 @@ Common commands: (see '--help-commands' for more)
|
|||
if pkgs is None:
|
||||
pkgs = ''
|
||||
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
|
||||
if "distutils.command" not in pkgs:
|
||||
pkgs.insert(0, "distutils.command")
|
||||
if 'distutils.command' not in pkgs:
|
||||
pkgs.insert(0, 'distutils.command')
|
||||
self.command_packages = pkgs
|
||||
return pkgs
|
||||
|
||||
|
|
@ -822,7 +901,7 @@ Common commands: (see '--help-commands' for more)
|
|||
return klass
|
||||
|
||||
for pkgname in self.get_command_packages():
|
||||
module_name = "%s.%s" % (pkgname, command)
|
||||
module_name = '{}.{}'.format(pkgname, command)
|
||||
klass_name = command
|
||||
|
||||
try:
|
||||
|
|
@ -836,7 +915,8 @@ Common commands: (see '--help-commands' for more)
|
|||
except AttributeError:
|
||||
raise DistutilsModuleError(
|
||||
"invalid command '%s' (no class '%s' in module '%s')"
|
||||
% (command, klass_name, module_name))
|
||||
% (command, klass_name, module_name),
|
||||
)
|
||||
|
||||
self.cmdclass[command] = klass
|
||||
return klass
|
||||
|
|
@ -852,8 +932,10 @@ Common commands: (see '--help-commands' for more)
|
|||
cmd_obj = self.command_obj.get(command)
|
||||
if not cmd_obj and create:
|
||||
if DEBUG:
|
||||
self.announce("Distribution.get_command_obj(): "
|
||||
"creating '%s' command object" % command)
|
||||
self.announce(
|
||||
'Distribution.get_command_obj(): '
|
||||
"creating '%s' command object" % command,
|
||||
)
|
||||
|
||||
klass = self.get_command_class(command)
|
||||
cmd_obj = self.command_obj[command] = klass(self)
|
||||
|
|
@ -887,11 +969,17 @@ Common commands: (see '--help-commands' for more)
|
|||
self.announce(" setting options for '%s' command:" % command_name)
|
||||
for (option, (source, value)) in option_dict.items():
|
||||
if DEBUG:
|
||||
self.announce(" %s = %s (from %s)" % (option, value,
|
||||
source))
|
||||
self.announce(
|
||||
' {} = {} (from {})'.format(
|
||||
option, value,
|
||||
source,
|
||||
),
|
||||
)
|
||||
try:
|
||||
bool_opts = [translate_longopt(o)
|
||||
for o in command_obj.boolean_options]
|
||||
bool_opts = [
|
||||
translate_longopt(o)
|
||||
for o in command_obj.boolean_options
|
||||
]
|
||||
except AttributeError:
|
||||
bool_opts = []
|
||||
try:
|
||||
|
|
@ -910,7 +998,8 @@ Common commands: (see '--help-commands' for more)
|
|||
else:
|
||||
raise DistutilsOptionError(
|
||||
"error in %s: command '%s' has no such option '%s'"
|
||||
% (source, command_name, option))
|
||||
% (source, command_name, option),
|
||||
)
|
||||
except ValueError as msg:
|
||||
raise DistutilsOptionError(msg)
|
||||
|
||||
|
|
@ -980,7 +1069,7 @@ Common commands: (see '--help-commands' for more)
|
|||
if self.have_run.get(command):
|
||||
return
|
||||
|
||||
log.info("running %s", command)
|
||||
log.info('running %s', command)
|
||||
cmd_obj = self.get_command_obj(command)
|
||||
cmd_obj.ensure_finalized()
|
||||
cmd_obj.run()
|
||||
|
|
@ -1010,9 +1099,11 @@ Common commands: (see '--help-commands' for more)
|
|||
return self.data_files and len(self.data_files) > 0
|
||||
|
||||
def is_pure(self):
|
||||
return (self.has_pure_modules() and
|
||||
not self.has_ext_modules() and
|
||||
not self.has_c_libraries())
|
||||
return (
|
||||
self.has_pure_modules() and
|
||||
not self.has_ext_modules() and
|
||||
not self.has_c_libraries()
|
||||
)
|
||||
|
||||
# -- Metadata query methods ----------------------------------------
|
||||
|
||||
|
|
@ -1021,19 +1112,21 @@ Common commands: (see '--help-commands' for more)
|
|||
# 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,
|
||||
author, and so forth.
|
||||
"""
|
||||
|
||||
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
|
||||
"maintainer", "maintainer_email", "url",
|
||||
"license", "description", "long_description",
|
||||
"keywords", "platforms", "fullname", "contact",
|
||||
"contact_email", "classifiers", "download_url",
|
||||
# PEP 314
|
||||
"provides", "requires", "obsoletes",
|
||||
)
|
||||
_METHOD_BASENAMES = (
|
||||
'name', 'version', 'author', 'author_email',
|
||||
'maintainer', 'maintainer_email', 'url',
|
||||
'license', 'description', 'long_description',
|
||||
'keywords', 'platforms', 'fullname', 'contact',
|
||||
'contact_email', 'classifiers', 'download_url',
|
||||
# PEP 314
|
||||
'provides', 'requires', 'obsoletes',
|
||||
)
|
||||
|
||||
def __init__(self, path=None):
|
||||
if path is not None:
|
||||
|
|
@ -1113,16 +1206,20 @@ class DistributionMetadata:
|
|||
def write_pkg_info(self, base_dir):
|
||||
"""Write the PKG-INFO file into the release tree.
|
||||
"""
|
||||
with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
|
||||
encoding='UTF-8') as pkg_info:
|
||||
with open(
|
||||
os.path.join(base_dir, 'PKG-INFO'), 'w',
|
||||
encoding='UTF-8',
|
||||
) as pkg_info:
|
||||
self.write_pkg_file(pkg_info)
|
||||
|
||||
def write_pkg_file(self, file):
|
||||
"""Write the PKG-INFO format data to a file object.
|
||||
"""
|
||||
version = '1.0'
|
||||
if (self.provides or self.requires or self.obsoletes or
|
||||
self.classifiers or self.download_url):
|
||||
if (
|
||||
self.provides or self.requires or self.obsoletes or
|
||||
self.classifiers or self.download_url
|
||||
):
|
||||
version = '1.1'
|
||||
|
||||
file.write('Metadata-Version: %s\n' % version)
|
||||
|
|
@ -1153,49 +1250,49 @@ class DistributionMetadata:
|
|||
|
||||
def _write_list(self, file, name, values):
|
||||
for value in values:
|
||||
file.write('%s: %s\n' % (name, value))
|
||||
file.write('{}: {}\n'.format(name, value))
|
||||
|
||||
# -- Metadata query methods ----------------------------------------
|
||||
|
||||
def get_name(self):
|
||||
return self.name or "UNKNOWN"
|
||||
return self.name or 'UNKNOWN'
|
||||
|
||||
def get_version(self):
|
||||
return self.version or "0.0.0"
|
||||
return self.version or '0.0.0'
|
||||
|
||||
def get_fullname(self):
|
||||
return "%s-%s" % (self.get_name(), self.get_version())
|
||||
return '{}-{}'.format(self.get_name(), self.get_version())
|
||||
|
||||
def get_author(self):
|
||||
return self.author or "UNKNOWN"
|
||||
return self.author or 'UNKNOWN'
|
||||
|
||||
def get_author_email(self):
|
||||
return self.author_email or "UNKNOWN"
|
||||
return self.author_email or 'UNKNOWN'
|
||||
|
||||
def get_maintainer(self):
|
||||
return self.maintainer or "UNKNOWN"
|
||||
return self.maintainer or 'UNKNOWN'
|
||||
|
||||
def get_maintainer_email(self):
|
||||
return self.maintainer_email or "UNKNOWN"
|
||||
return self.maintainer_email or 'UNKNOWN'
|
||||
|
||||
def get_contact(self):
|
||||
return self.maintainer or self.author or "UNKNOWN"
|
||||
return self.maintainer or self.author or 'UNKNOWN'
|
||||
|
||||
def get_contact_email(self):
|
||||
return self.maintainer_email or self.author_email or "UNKNOWN"
|
||||
return self.maintainer_email or self.author_email or 'UNKNOWN'
|
||||
|
||||
def get_url(self):
|
||||
return self.url or "UNKNOWN"
|
||||
return self.url or 'UNKNOWN'
|
||||
|
||||
def get_license(self):
|
||||
return self.license or "UNKNOWN"
|
||||
return self.license or 'UNKNOWN'
|
||||
get_licence = get_license
|
||||
|
||||
def get_description(self):
|
||||
return self.description or "UNKNOWN"
|
||||
return self.description or 'UNKNOWN'
|
||||
|
||||
def get_long_description(self):
|
||||
return self.long_description or "UNKNOWN"
|
||||
return self.long_description or 'UNKNOWN'
|
||||
|
||||
def get_keywords(self):
|
||||
return self.keywords or []
|
||||
|
|
@ -1204,7 +1301,7 @@ class DistributionMetadata:
|
|||
self.keywords = _ensure_list(value, 'keywords')
|
||||
|
||||
def get_platforms(self):
|
||||
return self.platforms or ["UNKNOWN"]
|
||||
return self.platforms or ['UNKNOWN']
|
||||
|
||||
def set_platforms(self, value):
|
||||
self.platforms = _ensure_list(value, 'platforms')
|
||||
|
|
@ -1216,7 +1313,7 @@ class DistributionMetadata:
|
|||
self.classifiers = _ensure_list(value, 'classifiers')
|
||||
|
||||
def get_download_url(self):
|
||||
return self.download_url or "UNKNOWN"
|
||||
return self.download_url or 'UNKNOWN'
|
||||
|
||||
# PEP 314
|
||||
def get_requires(self):
|
||||
|
|
@ -1247,6 +1344,7 @@ class DistributionMetadata:
|
|||
distutils.versionpredicate.VersionPredicate(v)
|
||||
self.obsoletes = list(value)
|
||||
|
||||
|
||||
def fix_help_options(options):
|
||||
"""Convert a 4-tuple 'help_options' list as found in various command
|
||||
classes to the 3-tuple form required by FancyGetopt.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue