From a88eace7acc39b76aeb8d967777d285dbeb0341f Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 24 Nov 2024 17:08:38 -0500 Subject: [PATCH] UP031 manual fixes for Ruff 0.8.0 --- distutils/command/build.py | 3 ++- distutils/command/install.py | 4 ++-- distutils/command/install_egg_info.py | 8 +++----- distutils/command/sdist.py | 3 +-- distutils/dist.py | 2 +- distutils/fancy_getopt.py | 10 +++++----- distutils/sysconfig.py | 2 +- distutils/tests/test_build.py | 4 +++- distutils/tests/test_build_ext.py | 7 ++++--- distutils/text_file.py | 4 ++-- distutils/util.py | 2 +- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/distutils/command/build.py b/distutils/command/build.py index caf55073..ccd2c706 100644 --- a/distutils/command/build.py +++ b/distutils/command/build.py @@ -113,7 +113,8 @@ def finalize_options(self): # noqa: C901 self.build_temp = os.path.join(self.build_base, 'temp' + plat_specifier) if self.build_scripts is None: self.build_scripts = os.path.join( - self.build_base, 'scripts-%d.%d' % sys.version_info[:2] + self.build_base, + f'scripts-{sys.version_info.major}.{sys.version_info.minor}', ) if self.executable is None and sys.executable: diff --git a/distutils/command/install.py b/distutils/command/install.py index ceb453e0..94009950 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -407,8 +407,8 @@ def finalize_options(self): # noqa: C901 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), 'py_version': py_version, - 'py_version_short': '%d.%d' % sys.version_info[:2], - 'py_version_nodot': '%d%d' % sys.version_info[:2], + 'py_version_short': f'{sys.version_info.major}.{sys.version_info.minor}', + 'py_version_nodot': f'{sys.version_info.major}{sys.version_info.minor}', 'sys_prefix': prefix, 'prefix': prefix, 'sys_exec_prefix': exec_prefix, diff --git a/distutils/command/install_egg_info.py b/distutils/command/install_egg_info.py index 4fbb3440..0baeee7b 100644 --- a/distutils/command/install_egg_info.py +++ b/distutils/command/install_egg_info.py @@ -31,11 +31,9 @@ def basename(self): Allow basename to be overridden by child class. Ref pypa/distutils#2. """ - return "%s-%s-py%d.%d.egg-info" % ( - to_filename(safe_name(self.distribution.get_name())), - to_filename(safe_version(self.distribution.get_version())), - *sys.version_info[:2], - ) + name = to_filename(safe_name(self.distribution.get_name())) + version = to_filename(safe_version(self.distribution.get_version())) + return f"{name}-{version}-py{sys.version_info.major}.{sys.version_info.minor}.egg-info" def finalize_options(self): self.set_undefined_options('install_lib', ('install_dir', 'install_dir')) diff --git a/distutils/command/sdist.py b/distutils/command/sdist.py index d723a1c9..003e0bf8 100644 --- a/distutils/command/sdist.py +++ b/distutils/command/sdist.py @@ -362,8 +362,7 @@ def read_template(self): # convert_path function except (DistutilsTemplateError, ValueError) as msg: self.warn( - "%s, line %d: %s" - % (template.filename, template.current_line, msg) + f"{template.filename}, line {int(template.current_line)}: {msg}" ) finally: template.close() diff --git a/distutils/dist.py b/distutils/dist.py index 8e1e6d0b..f58159ad 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -722,7 +722,7 @@ def print_command_list(self, commands, header, max_length): except AttributeError: description = "(no description available)" - print(" %-*s %s" % (max_length, cmd, description)) + print(f" {cmd:<{max_length}} {description}") def print_commands(self): """Print out a help message listing all available commands with a diff --git a/distutils/fancy_getopt.py b/distutils/fancy_getopt.py index 4ea89603..6f507ad9 100644 --- a/distutils/fancy_getopt.py +++ b/distutils/fancy_getopt.py @@ -351,18 +351,18 @@ def generate_help(self, header=None): # noqa: C901 # Case 1: no short option at all (makes life easy) if short is None: if text: - lines.append(" --%-*s %s" % (max_opt, long, text[0])) + lines.append(f" --{long:<{max_opt}} {text[0]}") else: - lines.append(" --%-*s " % (max_opt, long)) + lines.append(f" --{long:<{max_opt}}") # Case 2: we have a short option, so we have to include it # just after the long option else: opt_names = f"{long} (-{short})" if text: - lines.append(" --%-*s %s" % (max_opt, opt_names, text[0])) + lines.append(f" --{opt_names:<{max_opt}} {text[0]}") else: - lines.append(" --%-*s" % opt_names) + lines.append(f" --{opt_names:<{max_opt}}") for ell in text[1:]: lines.append(big_indent + ell) @@ -464,6 +464,6 @@ def __init__(self, options: Sequence[Any] = []): say, "How should I know?"].)""" for w in (10, 20, 30, 40): - print("width: %d" % w) + print(f"width: {w}") print("\n".join(wrap_text(text, w))) print() diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index da1eecbe..fc0ea787 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -107,7 +107,7 @@ def get_python_version(): leaving off the patchlevel. Sample return values could be '1.5' or '2.2'. """ - return '%d.%d' % sys.version_info[:2] + return f'{sys.version_info.major}.{sys.version_info.minor}' def get_python_inc(plat_specific=False, prefix=None): diff --git a/distutils/tests/test_build.py b/distutils/tests/test_build.py index d379aca0..f7fe69ac 100644 --- a/distutils/tests/test_build.py +++ b/distutils/tests/test_build.py @@ -40,7 +40,9 @@ def test_finalize_options(self): assert cmd.build_temp == wanted # build_scripts is build/scripts-x.x - wanted = os.path.join(cmd.build_base, 'scripts-%d.%d' % sys.version_info[:2]) + wanted = os.path.join( + cmd.build_base, f'scripts-{sys.version_info.major}.{sys.version_info.minor}' + ) assert cmd.build_scripts == wanted # executable is os.path.normpath(sys.executable) diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index 8bd3cef8..3e73d5bf 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -522,14 +522,15 @@ def _try_compile_deployment_target(self, operator, target): # pragma: no cover # at least one value we test with will not exist yet. if target[:2] < (10, 10): # for 10.1 through 10.9.x -> "10n0" - target = '%02d%01d0' % target + tmpl = '{:02}{:01}0' else: # for 10.10 and beyond -> "10nn00" if len(target) >= 2: - target = '%02d%02d00' % target + tmpl = '{:02}{:02}00' else: # 11 and later can have no minor version (11 instead of 11.0) - target = '%02d0000' % target + tmpl = '{:02}0000' + target = tmpl.format(*target) deptarget_ext = Extension( 'deptarget', [self.tmp_path / 'deptargetmodule.c'], diff --git a/distutils/text_file.py b/distutils/text_file.py index fec29c73..89d9048d 100644 --- a/distutils/text_file.py +++ b/distutils/text_file.py @@ -133,9 +133,9 @@ def gen_error(self, msg, line=None): line = self.current_line outmsg.append(self.filename + ", ") if isinstance(line, (list, tuple)): - outmsg.append("lines %d-%d: " % tuple(line)) + outmsg.append("lines {}-{}: ".format(*line)) else: - outmsg.append("line %d: " % line) + outmsg.append(f"line {int(line)}: ") outmsg.append(str(msg)) return "".join(outmsg) diff --git a/distutils/util.py b/distutils/util.py index 8d8260bc..fdc7ba98 100644 --- a/distutils/util.py +++ b/distutils/util.py @@ -288,7 +288,7 @@ def split_quoted(s): elif s[end] == '"': # slurp doubly-quoted string m = _dquote_re.match(s, end) else: - raise RuntimeError("this can't happen (bad char '%c')" % s[end]) + raise RuntimeError(f"this can't happen (bad char '{s[end]}')") if m is None: raise ValueError(f"bad string (mismatched {s[end]} quotes?)")