[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -3,11 +3,20 @@
Provides the Command class, the base class for the command classes
in the distutils.command package.
"""
from __future__ import annotations
import sys, os, re
from distutils.errors import DistutilsOptionError
from distutils import util, dir_util, file_util, archive_util, dep_util
import os
import re
import sys
from distutils import archive_util
from distutils import dep_util
from distutils import dir_util
from distutils import file_util
from distutils import log
from distutils import util
from distutils.errors import DistutilsOptionError
class Command:
"""Abstract base class for defining command classes, the "worker bees"
@ -41,7 +50,6 @@ class Command:
# defined. The canonical example is the "install" command.
sub_commands = []
# -- Creation/initialization methods -------------------------------
def __init__(self, dist):
@ -54,9 +62,9 @@ class Command:
from distutils.dist import Distribution
if not isinstance(dist, Distribution):
raise TypeError("dist must be a Distribution instance")
raise TypeError('dist must be a Distribution instance')
if self.__class__ is Command:
raise RuntimeError("Command is an abstract class")
raise RuntimeError('Command is an abstract class')
self.distribution = dist
self.initialize_options()
@ -94,7 +102,7 @@ class Command:
# XXX A more explicit way to customize dry_run would be better.
def __getattr__(self, attr):
if attr == 'dry_run':
myval = getattr(self, "_" + attr)
myval = getattr(self, '_' + attr)
if myval is None:
return getattr(self.distribution, attr)
else:
@ -130,8 +138,10 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError("abstract method -- subclass %s must override"
% self.__class__)
raise RuntimeError(
'abstract method -- subclass %s must override'
% self.__class__,
)
def finalize_options(self):
"""Set final values for all the options that this command supports.
@ -144,23 +154,26 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError("abstract method -- subclass %s must override"
% self.__class__)
raise RuntimeError(
'abstract method -- subclass %s must override'
% self.__class__,
)
def dump_options(self, header=None, indent=""):
def dump_options(self, header=None, indent=''):
from distutils.fancy_getopt import longopt_xlate
if header is None:
header = "command options for '%s':" % self.get_command_name()
self.announce(indent + header, level=log.INFO)
indent = indent + " "
indent = indent + ' '
for (option, _, _) in self.user_options:
option = option.translate(longopt_xlate)
if option[-1] == "=":
if option[-1] == '=':
option = option[:-1]
value = getattr(self, option)
self.announce(indent + "%s = %s" % (option, value),
level=log.INFO)
self.announce(
indent + '{} = {}'.format(option, value),
level=log.INFO,
)
def run(self):
"""A command's raison d'etre: carry out the action it exists to
@ -172,8 +185,10 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError("abstract method -- subclass %s must override"
% self.__class__)
raise RuntimeError(
'abstract method -- subclass %s must override'
% self.__class__,
)
def announce(self, msg, level=1):
"""If the current verbosity level is of greater than or equal to
@ -190,7 +205,6 @@ class Command:
print(msg)
sys.stdout.flush()
# -- Option validation methods -------------------------------------
# (these are very handy in writing the 'finalize_options()' method)
#
@ -210,15 +224,17 @@ class Command:
setattr(self, option, default)
return default
elif not isinstance(val, str):
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
% (option, what, val))
raise DistutilsOptionError(
"'%s' must be a %s (got `%s`)"
% (option, what, val),
)
return val
def ensure_string(self, option, default=None):
"""Ensure that 'option' is a string; if not defined, set it to
'default'.
"""
self._ensure_stringlike(option, "string", default)
self._ensure_stringlike(option, 'string', default)
def ensure_string_list(self, option):
r"""Ensure that 'option' is a list of strings. If 'option' is
@ -238,11 +254,14 @@ class Command:
ok = False
if not ok:
raise DistutilsOptionError(
"'%s' must be a list of strings (got %r)"
% (option, val))
"'%s' must be a list of strings (got %r)"
% (option, val),
)
def _ensure_tested_string(self, option, tester, what, error_fmt,
default=None):
def _ensure_tested_string(
self, option, tester, what, error_fmt,
default=None,
):
val = self._ensure_stringlike(option, what, default)
if val is not None and not tester(val):
raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
@ -250,15 +269,18 @@ class Command:
def ensure_filename(self, option):
"""Ensure that 'option' is the name of an existing file."""
self._ensure_tested_string(option, os.path.isfile,
"filename",
"'%s' does not exist or is not a file")
self._ensure_tested_string(
option, os.path.isfile,
'filename',
"'%s' does not exist or is not a file",
)
def ensure_dirname(self, option):
self._ensure_tested_string(option, os.path.isdir,
"directory name",
"'%s' does not exist or is not a directory")
self._ensure_tested_string(
option, os.path.isdir,
'directory name',
"'%s' does not exist or is not a directory",
)
# -- Convenience methods for commands ------------------------------
@ -302,8 +324,10 @@ class Command:
# XXX rename to 'get_reinitialized_command()'? (should do the
# same in dist.py, if so)
def reinitialize_command(self, command, reinit_subcommands=0):
return self.distribution.reinitialize_command(command,
reinit_subcommands)
return self.distribution.reinitialize_command(
command,
reinit_subcommands,
)
def run_command(self, command):
"""Run some other command: uses the 'run_command()' method of
@ -325,11 +349,10 @@ class Command:
commands.append(cmd_name)
return commands
# -- External world manipulation -----------------------------------
def warn(self, msg):
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
log.warn('warning: %s: %s\n', self.get_command_name(), msg)
def execute(self, func, args, msg=None, level=1):
util.execute(func, args, msg, dry_run=self.dry_run)
@ -337,25 +360,33 @@ class Command:
def mkpath(self, name, mode=0o777):
dir_util.mkpath(name, mode, dry_run=self.dry_run)
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
link=None, level=1):
def copy_file(
self, infile, outfile, preserve_mode=1, preserve_times=1,
link=None, level=1,
):
"""Copy a file respecting verbose, dry-run and force flags. (The
former two default to whatever is in the Distribution object, and
the latter defaults to false for commands that don't define it.)"""
return file_util.copy_file(infile, outfile, preserve_mode,
preserve_times, not self.force, link,
dry_run=self.dry_run)
return file_util.copy_file(
infile, outfile, preserve_mode,
preserve_times, not self.force, link,
dry_run=self.dry_run,
)
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1,
preserve_symlinks=0, level=1):
def copy_tree(
self, infile, outfile, preserve_mode=1, preserve_times=1,
preserve_symlinks=0, level=1,
):
"""Copy an entire directory tree respecting verbose, dry-run,
and force flags.
"""
return dir_util.copy_tree(infile, outfile, preserve_mode,
preserve_times, preserve_symlinks,
not self.force, dry_run=self.dry_run)
return dir_util.copy_tree(
infile, outfile, preserve_mode,
preserve_times, preserve_symlinks,
not self.force, dry_run=self.dry_run,
)
def move_file (self, src, dst, level=1):
def move_file(self, src, dst, level=1):
"""Move a file respecting dry-run flag."""
return file_util.move_file(src, dst, dry_run=self.dry_run)
@ -364,14 +395,20 @@ class Command:
from distutils.spawn import spawn
spawn(cmd, search_path, dry_run=self.dry_run)
def make_archive(self, base_name, format, root_dir=None, base_dir=None,
owner=None, group=None):
return archive_util.make_archive(base_name, format, root_dir, base_dir,
dry_run=self.dry_run,
owner=owner, group=group)
def make_archive(
self, base_name, format, root_dir=None, base_dir=None,
owner=None, group=None,
):
return archive_util.make_archive(
base_name, format, root_dir, base_dir,
dry_run=self.dry_run,
owner=owner, group=group,
)
def make_file(self, infiles, outfile, func, args,
exec_msg=None, skip_msg=None, level=1):
def make_file(
self, infiles, outfile, func, args,
exec_msg=None, skip_msg=None, level=1,
):
"""Special case of 'execute()' for operations that process one or
more input files and generate one output file. Works just like
'execute()', except the operation is skipped and a different
@ -381,17 +418,18 @@ class Command:
timestamp checks.
"""
if skip_msg is None:
skip_msg = "skipping %s (inputs unchanged)" % outfile
skip_msg = 'skipping %s (inputs unchanged)' % outfile
# Allow 'infiles' to be a single string
if isinstance(infiles, str):
infiles = (infiles,)
elif not isinstance(infiles, (list, tuple)):
raise TypeError(
"'infiles' must be a string, or a list or tuple of strings")
"'infiles' must be a string, or a list or tuple of strings",
)
if exec_msg is None:
exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
exec_msg = 'generating {} from {}'.format(outfile, ', '.join(infiles))
# If 'outfile' must be regenerated (either because it doesn't
# exist, is out-of-date, or the 'force' flag is true) then