Skip to content

Commit a88eace

Browse files
committed
UP031 manual fixes for Ruff 0.8.0
1 parent a9f832b commit a88eace

11 files changed

+25
-24
lines changed

distutils/command/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def finalize_options(self): # noqa: C901
113113
self.build_temp = os.path.join(self.build_base, 'temp' + plat_specifier)
114114
if self.build_scripts is None:
115115
self.build_scripts = os.path.join(
116-
self.build_base, 'scripts-%d.%d' % sys.version_info[:2]
116+
self.build_base,
117+
f'scripts-{sys.version_info.major}.{sys.version_info.minor}',
117118
)
118119

119120
if self.executable is None and sys.executable:

distutils/command/install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def finalize_options(self): # noqa: C901
407407
'dist_version': self.distribution.get_version(),
408408
'dist_fullname': self.distribution.get_fullname(),
409409
'py_version': py_version,
410-
'py_version_short': '%d.%d' % sys.version_info[:2],
411-
'py_version_nodot': '%d%d' % sys.version_info[:2],
410+
'py_version_short': f'{sys.version_info.major}.{sys.version_info.minor}',
411+
'py_version_nodot': f'{sys.version_info.major}{sys.version_info.minor}',
412412
'sys_prefix': prefix,
413413
'prefix': prefix,
414414
'sys_exec_prefix': exec_prefix,

distutils/command/install_egg_info.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ def basename(self):
3131
Allow basename to be overridden by child class.
3232
Ref pypa/distutils#2.
3333
"""
34-
return "%s-%s-py%d.%d.egg-info" % (
35-
to_filename(safe_name(self.distribution.get_name())),
36-
to_filename(safe_version(self.distribution.get_version())),
37-
*sys.version_info[:2],
38-
)
34+
name = to_filename(safe_name(self.distribution.get_name()))
35+
version = to_filename(safe_version(self.distribution.get_version()))
36+
return f"{name}-{version}-py{sys.version_info.major}.{sys.version_info.minor}.egg-info"
3937

4038
def finalize_options(self):
4139
self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))

distutils/command/sdist.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ def read_template(self):
362362
# convert_path function
363363
except (DistutilsTemplateError, ValueError) as msg:
364364
self.warn(
365-
"%s, line %d: %s"
366-
% (template.filename, template.current_line, msg)
365+
f"{template.filename}, line {int(template.current_line)}: {msg}"
367366
)
368367
finally:
369368
template.close()

distutils/dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def print_command_list(self, commands, header, max_length):
722722
except AttributeError:
723723
description = "(no description available)"
724724

725-
print(" %-*s %s" % (max_length, cmd, description))
725+
print(f" {cmd:<{max_length}} {description}")
726726

727727
def print_commands(self):
728728
"""Print out a help message listing all available commands with a

distutils/fancy_getopt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,18 @@ def generate_help(self, header=None): # noqa: C901
351351
# Case 1: no short option at all (makes life easy)
352352
if short is None:
353353
if text:
354-
lines.append(" --%-*s %s" % (max_opt, long, text[0]))
354+
lines.append(f" --{long:<{max_opt}} {text[0]}")
355355
else:
356-
lines.append(" --%-*s " % (max_opt, long))
356+
lines.append(f" --{long:<{max_opt}}")
357357

358358
# Case 2: we have a short option, so we have to include it
359359
# just after the long option
360360
else:
361361
opt_names = f"{long} (-{short})"
362362
if text:
363-
lines.append(" --%-*s %s" % (max_opt, opt_names, text[0]))
363+
lines.append(f" --{opt_names:<{max_opt}} {text[0]}")
364364
else:
365-
lines.append(" --%-*s" % opt_names)
365+
lines.append(f" --{opt_names:<{max_opt}}")
366366

367367
for ell in text[1:]:
368368
lines.append(big_indent + ell)
@@ -464,6 +464,6 @@ def __init__(self, options: Sequence[Any] = []):
464464
say, "How should I know?"].)"""
465465

466466
for w in (10, 20, 30, 40):
467-
print("width: %d" % w)
467+
print(f"width: {w}")
468468
print("\n".join(wrap_text(text, w)))
469469
print()

distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def get_python_version():
107107
leaving off the patchlevel. Sample return values could be '1.5'
108108
or '2.2'.
109109
"""
110-
return '%d.%d' % sys.version_info[:2]
110+
return f'{sys.version_info.major}.{sys.version_info.minor}'
111111

112112

113113
def get_python_inc(plat_specific=False, prefix=None):

distutils/tests/test_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def test_finalize_options(self):
4040
assert cmd.build_temp == wanted
4141

4242
# build_scripts is build/scripts-x.x
43-
wanted = os.path.join(cmd.build_base, 'scripts-%d.%d' % sys.version_info[:2])
43+
wanted = os.path.join(
44+
cmd.build_base, f'scripts-{sys.version_info.major}.{sys.version_info.minor}'
45+
)
4446
assert cmd.build_scripts == wanted
4547

4648
# executable is os.path.normpath(sys.executable)

distutils/tests/test_build_ext.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,15 @@ def _try_compile_deployment_target(self, operator, target): # pragma: no cover
522522
# at least one value we test with will not exist yet.
523523
if target[:2] < (10, 10):
524524
# for 10.1 through 10.9.x -> "10n0"
525-
target = '%02d%01d0' % target
525+
tmpl = '{:02}{:01}0'
526526
else:
527527
# for 10.10 and beyond -> "10nn00"
528528
if len(target) >= 2:
529-
target = '%02d%02d00' % target
529+
tmpl = '{:02}{:02}00'
530530
else:
531531
# 11 and later can have no minor version (11 instead of 11.0)
532-
target = '%02d0000' % target
532+
tmpl = '{:02}0000'
533+
target = tmpl.format(*target)
533534
deptarget_ext = Extension(
534535
'deptarget',
535536
[self.tmp_path / 'deptargetmodule.c'],

distutils/text_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ def gen_error(self, msg, line=None):
133133
line = self.current_line
134134
outmsg.append(self.filename + ", ")
135135
if isinstance(line, (list, tuple)):
136-
outmsg.append("lines %d-%d: " % tuple(line))
136+
outmsg.append("lines {}-{}: ".format(*line))
137137
else:
138-
outmsg.append("line %d: " % line)
138+
outmsg.append(f"line {int(line)}: ")
139139
outmsg.append(str(msg))
140140
return "".join(outmsg)
141141

distutils/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def split_quoted(s):
288288
elif s[end] == '"': # slurp doubly-quoted string
289289
m = _dquote_re.match(s, end)
290290
else:
291-
raise RuntimeError("this can't happen (bad char '%c')" % s[end])
291+
raise RuntimeError(f"this can't happen (bad char '{s[end]}')")
292292

293293
if m is None:
294294
raise ValueError(f"bad string (mismatched {s[end]} quotes?)")

0 commit comments

Comments
 (0)