Skip to content

Commit 050eafb

Browse files
Enforce ruff/pyupgrade rule UP031
UP031 Use format specifiers instead of percent format
1 parent fc9f889 commit 050eafb

36 files changed

+191
-194
lines changed

pkg_resources/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def get_supported_platform():
200200
m = macosVersionString.match(plat)
201201
if m is not None and sys.platform == "darwin":
202202
try:
203-
plat = 'macosx-%s-%s' % ('.'.join(_macos_vers()[:2]), m.group(3))
203+
plat = 'macosx-{}-{}'.format('.'.join(_macos_vers()[:2]), m.group(3))
204204
except ValueError:
205205
# not macOS
206206
pass
@@ -492,7 +492,7 @@ def compatible_platforms(provided: str | None, required: str | None) -> bool:
492492
provDarwin = darwinVersionString.match(provided)
493493
if provDarwin:
494494
dversion = int(provDarwin.group(1))
495-
macosversion = "%s.%s" % (reqMac.group(1), reqMac.group(2))
495+
macosversion = "{}.{}".format(reqMac.group(1), reqMac.group(2))
496496
if (
497497
dversion == 7
498498
and macosversion >= "10.3"
@@ -1316,7 +1316,7 @@ def __iadd__(self, other: Distribution | Environment) -> Self:
13161316
for dist in other[project]:
13171317
self.add(dist)
13181318
else:
1319-
raise TypeError("Can't add %r to environment" % (other,))
1319+
raise TypeError("Can't add {!r} to environment".format(other))
13201320
return self
13211321

13221322
def __add__(self, other: Distribution | Environment) -> Self:
@@ -2018,15 +2018,15 @@ def _zipinfo_name(self, fspath):
20182018
return ''
20192019
if fspath.startswith(self.zip_pre):
20202020
return fspath[len(self.zip_pre) :]
2021-
raise AssertionError("%s is not a subpath of %s" % (fspath, self.zip_pre))
2021+
raise AssertionError("{} is not a subpath of {}".format(fspath, self.zip_pre))
20222022

20232023
def _parts(self, zip_path):
20242024
# Convert a zipfile subpath into an egg-relative path part list.
20252025
# pseudo-fs path
20262026
fspath = self.zip_pre + zip_path
20272027
if fspath.startswith(self.egg_root + os.sep):
20282028
return fspath[len(self.egg_root) + 1 :].split(os.sep)
2029-
raise AssertionError("%s is not a subpath of %s" % (fspath, self.egg_root))
2029+
raise AssertionError("{} is not a subpath of {}".format(fspath, self.egg_root))
20302030

20312031
@property
20322032
def zipinfo(self):
@@ -2729,15 +2729,15 @@ def __init__(
27292729
self.dist = dist
27302730

27312731
def __str__(self) -> str:
2732-
s = "%s = %s" % (self.name, self.module_name)
2732+
s = "{} = {}".format(self.name, self.module_name)
27332733
if self.attrs:
27342734
s += ':' + '.'.join(self.attrs)
27352735
if self.extras:
2736-
s += ' [%s]' % ','.join(self.extras)
2736+
s += ' [{}]'.format(','.join(self.extras))
27372737
return s
27382738

27392739
def __repr__(self) -> str:
2740-
return "EntryPoint.parse(%r)" % str(self)
2740+
return "EntryPoint.parse({!r})".format(str(self))
27412741

27422742
@overload
27432743
def load(
@@ -3108,7 +3108,7 @@ def requires(self, extras: Iterable[str] = ()) -> list[Requirement]:
31083108
deps.extend(dm[safe_extra(ext)])
31093109
except KeyError as e:
31103110
raise UnknownExtra(
3111-
"%s has no such extra feature %r" % (self, ext)
3111+
"{} has no such extra feature {!r}".format(self, ext)
31123112
) from e
31133113
return deps
31143114

@@ -3150,7 +3150,7 @@ def activate(self, path: list[str] | None = None, replace: bool = False) -> None
31503150

31513151
def egg_name(self):
31523152
"""Return what this distribution's standard .egg filename should be"""
3153-
filename = "%s-%s-py%s" % (
3153+
filename = "{}-{}-py{}".format(
31543154
to_filename(self.project_name),
31553155
to_filename(self.version),
31563156
self.py_version or PY_MAJOR,
@@ -3162,7 +3162,7 @@ def egg_name(self):
31623162

31633163
def __repr__(self) -> str:
31643164
if self.location:
3165-
return "%s (%s)" % (self, self.location)
3165+
return "{} ({})".format(self, self.location)
31663166
else:
31673167
return str(self)
31683168

@@ -3172,7 +3172,7 @@ def __str__(self) -> str:
31723172
except ValueError:
31733173
version = None
31743174
version = version or "[unknown version]"
3175-
return "%s %s" % (self.project_name, version)
3175+
return "{} {}".format(self.project_name, version)
31763176

31773177
def __getattr__(self, attr: str):
31783178
"""Delegate all unrecognized public attributes to .metadata provider"""
@@ -3200,17 +3200,17 @@ def from_filename(
32003200
def as_requirement(self):
32013201
"""Return a ``Requirement`` that matches this distribution exactly"""
32023202
if isinstance(self.parsed_version, packaging.version.Version):
3203-
spec = "%s==%s" % (self.project_name, self.parsed_version)
3203+
spec = "{}=={}".format(self.project_name, self.parsed_version)
32043204
else:
3205-
spec = "%s===%s" % (self.project_name, self.parsed_version)
3205+
spec = "{}==={}".format(self.project_name, self.parsed_version)
32063206

32073207
return Requirement.parse(spec)
32083208

32093209
def load_entry_point(self, group: str, name: str) -> _ResolvedEntryPoint:
32103210
"""Return the `name` entry point of `group` or raise ImportError"""
32113211
ep = self.get_entry_info(group, name)
32123212
if ep is None:
3213-
raise ImportError("Entry point %r not found" % ((group, name),))
3213+
raise ImportError("Entry point {!r} not found".format((group, name)))
32143214
return ep.load()
32153215

32163216
@overload
@@ -3327,8 +3327,8 @@ def check_version_conflict(self):
33273327
):
33283328
continue
33293329
issue_warning(
3330-
"Module %s was already imported from %s, but %s is being added"
3331-
" to sys.path" % (modname, fn, self.location),
3330+
"Module {} was already imported from {}, but {} is being added"
3331+
" to sys.path".format(modname, fn, self.location),
33323332
)
33333333

33343334
def has_version(self) -> bool:
@@ -3512,7 +3512,7 @@ def __hash__(self) -> int:
35123512
return self.__hash
35133513

35143514
def __repr__(self) -> str:
3515-
return "Requirement.parse(%r)" % str(self)
3515+
return "Requirement.parse({!r})".format(str(self))
35163516

35173517
@staticmethod
35183518
def parse(s: str | Iterable[str]) -> Requirement:

ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ ignore = [
3535
"TRY003", # raise-vanilla-args, avoid multitude of exception classes
3636
"TRY301", # raise-within-try, it's handy
3737
"UP015", # redundant-open-modes, explicit is preferred
38-
"UP031", # temporarily disabled
3938
"UP032", # temporarily disabled
4039
"UP038", # Using `X | Y` in `isinstance` call is slower and more verbose https://github.com/astral-sh/ruff/issues/7871
4140
# Only enforcing return type annotations for public functions

setuptools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _ensure_stringlike(self, option, what, default=None):
182182
return default
183183
elif not isinstance(val, str):
184184
raise DistutilsOptionError(
185-
"'%s' must be a %s (got `%s`)" % (option, what, val)
185+
"'{}' must be a {} (got `{}`)".format(option, what, val)
186186
)
187187
return val
188188

@@ -210,7 +210,7 @@ def ensure_string_list(self, option: str) -> None:
210210
ok = False
211211
if not ok:
212212
raise DistutilsOptionError(
213-
"'%s' must be a list of strings (got %r)" % (option, val)
213+
"'{}' must be a list of strings (got {!r})".format(option, val)
214214
)
215215

216216
@overload

setuptools/_core_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
150150
version = self.get_metadata_version()
151151

152152
def write_field(key, value):
153-
file.write("%s: %s\n" % (key, value))
153+
file.write("{}: {}\n".format(key, value))
154154

155155
write_field('Metadata-Version', str(version))
156156
write_field('Name', self.get_name())
@@ -179,7 +179,7 @@ def write_field(key, value):
179179
write_field('License', rfc822_escape(license))
180180

181181
for project_url in self.project_urls.items():
182-
write_field('Project-URL', '%s, %s' % project_url)
182+
write_field('Project-URL', '{}, {}'.format(*project_url))
183183

184184
keywords = ','.join(self.get_keywords())
185185
if keywords:
@@ -209,7 +209,7 @@ def write_field(key, value):
209209

210210
long_description = self.get_long_description()
211211
if long_description:
212-
file.write("\n%s" % long_description)
212+
file.write("\n{}".format(long_description))
213213
if not long_description.endswith("\n"):
214214
file.write("\n")
215215

setuptools/_imp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def find_module(module, paths=None):
2929
"""Just like 'imp.find_module()', but with package support"""
3030
spec = find_spec(module, paths)
3131
if spec is None:
32-
raise ImportError("Can't find %s" % module)
32+
raise ImportError("Can't find {}".format(module))
3333
if not spec.has_location and hasattr(spec, 'submodule_search_locations'):
3434
spec = importlib.util.spec_from_loader('__init__.py', spec.loader)
3535

@@ -76,12 +76,12 @@ def find_module(module, paths=None):
7676
def get_frozen_object(module, paths=None):
7777
spec = find_spec(module, paths)
7878
if not spec:
79-
raise ImportError("Can't find %s" % module)
79+
raise ImportError("Can't find {}".format(module))
8080
return spec.loader.get_code(module)
8181

8282

8383
def get_module(module, paths, info):
8484
spec = find_spec(module, paths)
8585
if not spec:
86-
raise ImportError("Can't find %s" % module)
86+
raise ImportError("Can't find {}".format(module))
8787
return module_from_spec(spec)

setuptools/archive_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def unpack_archive(
6262
else:
6363
return
6464
else:
65-
raise UnrecognizedFormat("Not a recognized archive type: %s" % filename)
65+
raise UnrecognizedFormat("Not a recognized archive type: {}".format(filename))
6666

6767

6868
def unpack_directory(filename, extract_dir, progress_filter=default_filter) -> None:
@@ -71,7 +71,7 @@ def unpack_directory(filename, extract_dir, progress_filter=default_filter) -> N
7171
Raises ``UnrecognizedFormat`` if `filename` is not a directory
7272
"""
7373
if not os.path.isdir(filename):
74-
raise UnrecognizedFormat("%s is not a directory" % filename)
74+
raise UnrecognizedFormat("{} is not a directory".format(filename))
7575

7676
paths = {
7777
filename: ('', extract_dir),
@@ -101,7 +101,7 @@ def unpack_zipfile(filename, extract_dir, progress_filter=default_filter) -> Non
101101
"""
102102

103103
if not zipfile.is_zipfile(filename):
104-
raise UnrecognizedFormat("%s is not a zip file" % (filename,))
104+
raise UnrecognizedFormat("{} is not a zip file".format(filename))
105105

106106
with zipfile.ZipFile(filename) as z:
107107
_unpack_zipfile_obj(z, extract_dir, progress_filter)
@@ -198,7 +198,7 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter) -> boo
198198
tarobj = tarfile.open(filename)
199199
except tarfile.TarError as e:
200200
raise UnrecognizedFormat(
201-
"%s is not a compressed or uncompressed tar file" % (filename,)
201+
"{} is not a compressed or uncompressed tar file".format(filename)
202202
) from e
203203

204204
for member, final_dst in _iter_open_tar(

setuptools/command/alias.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run(self) -> None:
5555
print("setup.py alias", format_alias(alias, aliases))
5656
return
5757
else:
58-
print("No alias definition found for %r" % alias)
58+
print("No alias definition found for {!r}".format(alias))
5959
return
6060
else:
6161
alias = self.args[0]
@@ -73,5 +73,5 @@ def format_alias(name, aliases):
7373
elif source == config_file('local'):
7474
source = ''
7575
else:
76-
source = '--filename=%r' % source
76+
source = '--filename={!r}'.format(source)
7777
return source + name + ' ' + command

setuptools/command/bdist_egg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def zap_pyfiles(self):
263263
pattern = r'(?P<name>.+)\.(?P<magic>[^.]+)\.pyc'
264264
m = re.match(pattern, name)
265265
path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc')
266-
log.info("Renaming file from [%s] to [%s]" % (path_old, path_new))
266+
log.info("Renaming file from [{}] to [{}]".format(path_old, path_new))
267267
try:
268268
os.remove(path_new)
269269
except OSError:

setuptools/command/build_clib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def build_libraries(self, libraries) -> None:
2929
sources = build_info.get('sources')
3030
if sources is None or not isinstance(sources, (list, tuple)):
3131
raise DistutilsSetupError(
32-
"in 'libraries' option (library '%s'), "
32+
"in 'libraries' option (library '{}'), "
3333
"'sources' must be present and must be "
34-
"a list of source filenames" % lib_name
34+
"a list of source filenames".format(lib_name)
3535
)
3636
sources = sorted(list(sources))
3737

@@ -43,9 +43,9 @@ def build_libraries(self, libraries) -> None:
4343
obj_deps = build_info.get('obj_deps', dict())
4444
if not isinstance(obj_deps, dict):
4545
raise DistutilsSetupError(
46-
"in 'libraries' option (library '%s'), "
46+
"in 'libraries' option (library '{}'), "
4747
"'obj_deps' must be a dictionary of "
48-
"type 'source: list'" % lib_name
48+
"type 'source: list'".format(lib_name)
4949
)
5050
dependencies = []
5151

@@ -54,9 +54,9 @@ def build_libraries(self, libraries) -> None:
5454
global_deps = obj_deps.get('', list())
5555
if not isinstance(global_deps, (list, tuple)):
5656
raise DistutilsSetupError(
57-
"in 'libraries' option (library '%s'), "
57+
"in 'libraries' option (library '{}'), "
5858
"'obj_deps' must be a dictionary of "
59-
"type 'source: list'" % lib_name
59+
"type 'source: list'".format(lib_name)
6060
)
6161

6262
# Build the list to be used by newer_pairwise_group
@@ -67,9 +67,9 @@ def build_libraries(self, libraries) -> None:
6767
extra_deps = obj_deps.get(source, list())
6868
if not isinstance(extra_deps, (list, tuple)):
6969
raise DistutilsSetupError(
70-
"in 'libraries' option (library '%s'), "
70+
"in 'libraries' option (library '{}'), "
7171
"'obj_deps' must be a dictionary of "
72-
"type 'source: list'" % lib_name
72+
"type 'source: list'".format(lib_name)
7373
)
7474
src_deps.extend(extra_deps)
7575
dependencies.append(src_deps)

setuptools/command/build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _write_stub_file(self, stub_file: str, ext: Extension, compile=False):
360360
" global __bootstrap__, __file__, __loader__",
361361
" import sys, os, pkg_resources, importlib.util" + if_dl(", dl"),
362362
" __file__ = pkg_resources.resource_filename"
363-
"(__name__,%r)" % os.path.basename(ext._file_name),
363+
"(__name__,{!r})".format(os.path.basename(ext._file_name)),
364364
" del __bootstrap__",
365365
" if '__loader__' in globals():",
366366
" del __loader__",

0 commit comments

Comments
 (0)