Skip to content

Commit

Permalink
UP031 manual fixes for Ruff 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Dec 26, 2024
1 parent a9f832b commit a88eace
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 24 deletions.
3 changes: 2 additions & 1 deletion distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions distutils/command/install_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
3 changes: 1 addition & 2 deletions distutils/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions distutils/text_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?)")
Expand Down

0 comments on commit a88eace

Please sign in to comment.