This commit is contained in:
ton
2024-10-07 10:13:40 +07:00
parent aa1631742f
commit 3a7d696db6
9729 changed files with 1832837 additions and 161742 deletions

View File

@@ -4,14 +4,14 @@ Provides the Command class, the base class for the command classes
in the distutils.command package.
"""
import sys
import logging
import os
import re
import logging
import sys
from .errors import DistutilsOptionError
from . import util, dir_util, file_util, archive_util, dep_util
from . import _modified, archive_util, dir_util, file_util, util
from ._log import log
from .errors import DistutilsOptionError
class Command:
@@ -87,13 +87,13 @@ class Command:
# The 'help' flag is just used for command-line parsing, so
# none of that complicated bureaucracy is needed.
self.help = 0
self.help = False
# 'finalized' records whether or not 'finalize_options()' has been
# called. 'finalize_options()' itself should not pay attention to
# this flag: it is the business of 'ensure_finalized()', which
# always calls 'finalize_options()', to respect/update it.
self.finalized = 0
self.finalized = False
# XXX A more explicit way to customize dry_run would be better.
def __getattr__(self, attr):
@@ -109,7 +109,7 @@ class Command:
def ensure_finalized(self):
if not self.finalized:
self.finalize_options()
self.finalized = 1
self.finalized = True
# Subclasses must define:
# initialize_options()
@@ -135,7 +135,7 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError(
"abstract method -- subclass %s must override" % self.__class__
f"abstract method -- subclass {self.__class__} must override"
)
def finalize_options(self):
@@ -150,14 +150,14 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError(
"abstract method -- subclass %s must override" % self.__class__
f"abstract method -- subclass {self.__class__} must override"
)
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()
header = f"command options for '{self.get_command_name()}':"
self.announce(indent + header, level=logging.INFO)
indent = indent + " "
for option, _, _ in self.user_options:
@@ -165,7 +165,7 @@ class Command:
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
self.announce(indent + "{} = {}".format(option, value), level=logging.INFO)
self.announce(indent + f"{option} = {value}", level=logging.INFO)
def run(self):
"""A command's raison d'etre: carry out the action it exists to
@@ -178,7 +178,7 @@ class Command:
This method must be implemented by all command classes.
"""
raise RuntimeError(
"abstract method -- subclass %s must override" % self.__class__
f"abstract method -- subclass {self.__class__} must override"
)
def announce(self, msg, level=logging.DEBUG):
@@ -213,9 +213,7 @@ class Command:
setattr(self, option, default)
return default
elif not isinstance(val, str):
raise DistutilsOptionError(
"'{}' must be a {} (got `{}`)".format(option, what, val)
)
raise DistutilsOptionError(f"'{option}' must be a {what} (got `{val}`)")
return val
def ensure_string(self, option, default=None):
@@ -242,7 +240,7 @@ class Command:
ok = False
if not ok:
raise DistutilsOptionError(
"'{}' must be a list of strings (got {!r})".format(option, val)
f"'{option}' must be a list of strings (got {val!r})"
)
def _ensure_tested_string(self, option, tester, what, error_fmt, default=None):
@@ -295,7 +293,7 @@ class Command:
if getattr(self, dst_option) is None:
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
def get_finalized_command(self, command, create=1):
def get_finalized_command(self, command, create=True):
"""Wrapper around Distribution's 'get_command_obj()' method: find
(create if necessary and 'create' is true) the command object for
'command', call its 'ensure_finalized()' method, and return the
@@ -307,7 +305,7 @@ 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):
def reinitialize_command(self, command, reinit_subcommands=False):
return self.distribution.reinitialize_command(command, reinit_subcommands)
def run_command(self, command):
@@ -342,7 +340,13 @@ class Command:
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
self,
infile,
outfile,
preserve_mode=True,
preserve_times=True,
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
@@ -361,9 +365,9 @@ class Command:
self,
infile,
outfile,
preserve_mode=1,
preserve_times=1,
preserve_symlinks=0,
preserve_mode=True,
preserve_times=True,
preserve_symlinks=False,
level=1,
):
"""Copy an entire directory tree respecting verbose, dry-run,
@@ -383,7 +387,7 @@ class Command:
"""Move a file respecting dry-run flag."""
return file_util.move_file(src, dst, dry_run=self.dry_run)
def spawn(self, cmd, search_path=1, level=1):
def spawn(self, cmd, search_path=True, level=1):
"""Spawn an external command respecting dry-run flag."""
from distutils.spawn import spawn
@@ -414,7 +418,7 @@ class Command:
timestamp checks.
"""
if skip_msg is None:
skip_msg = "skipping %s (inputs unchanged)" % outfile
skip_msg = f"skipping {outfile} (inputs unchanged)"
# Allow 'infiles' to be a single string
if isinstance(infiles, str):
@@ -428,7 +432,7 @@ class Command:
# If 'outfile' must be regenerated (either because it doesn't
# exist, is out-of-date, or the 'force' flag is true) then
# perform the action that presumably regenerates it
if self.force or dep_util.newer_group(infiles, outfile):
if self.force or _modified.newer_group(infiles, outfile):
self.execute(func, args, exec_msg, level)
# Otherwise, print the "skip" message
else: