Skip to content

Commit

Permalink
Apply ruff/pyupgrade rule UP032
Browse files Browse the repository at this point in the history
	UP032 Use f-string instead of `format` call
  • Loading branch information
DimitriPapadopoulos committed Jul 13, 2024
1 parent 568daf5 commit 59be934
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _evaluate_markers(markers: MarkerList, environment: dict[str, str]) -> bool:


def format_full_version(info: sys._version_info) -> str:
version = "{0.major}.{0.minor}.{0.micro}".format(info)
version = f"{info.major}.{info.minor}.{info.micro}"
kind = info.releaselevel
if kind != "final":
version += kind[0] + str(info.serial)
Expand Down
36 changes: 13 additions & 23 deletions src/packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ def cpython_tags(
if use_abi3:
for minor_version in range(python_version[1] - 1, 1, -1):
for platform_ in platforms:
interpreter = "cp{version}".format(
version=_version_nodot((python_version[0], minor_version))
)
version = _version_nodot((python_version[0], minor_version))
interpreter = f"cp{version}"
yield Tag(interpreter, "abi3", platform_)


Expand Down Expand Up @@ -435,24 +434,22 @@ def mac_platforms(
if (10, 0) <= version and version < (11, 0):
# Prior to Mac OS 11, each yearly release of Mac OS bumped the
# "minor" version number. The major version was always 10.
major_version = 10
for minor_version in range(version[1], -1, -1):
compat_version = 10, minor_version
compat_version = major_version, minor_version
binary_formats = _mac_binary_formats(compat_version, arch)
for binary_format in binary_formats:
yield "macosx_{major}_{minor}_{binary_format}".format(
major=10, minor=minor_version, binary_format=binary_format
)
yield f"macosx_{major_version}_{minor_version}_{binary_format}"

if version >= (11, 0):
# Starting with Mac OS 11, each yearly release bumps the major version
# number. The minor versions are now the midyear updates.
minor_version = 0
for major_version in range(version[0], 10, -1):
compat_version = major_version, 0
compat_version = major_version, minor_version
binary_formats = _mac_binary_formats(compat_version, arch)
for binary_format in binary_formats:
yield "macosx_{major}_{minor}_{binary_format}".format(
major=major_version, minor=0, binary_format=binary_format
)
yield f"macosx_{major_version}_{minor_version}_{binary_format}"

if version >= (11, 0):
# Mac OS 11 on x86_64 is compatible with binaries from previous releases.
Expand All @@ -462,25 +459,18 @@ def mac_platforms(
# However, the "universal2" binary format can have a
# macOS version earlier than 11.0 when the x86_64 part of the binary supports
# that version of macOS.
major_version = 10
if arch == "x86_64":
for minor_version in range(16, 3, -1):
compat_version = 10, minor_version
compat_version = major_version, minor_version
binary_formats = _mac_binary_formats(compat_version, arch)
for binary_format in binary_formats:
yield "macosx_{major}_{minor}_{binary_format}".format(
major=compat_version[0],
minor=compat_version[1],
binary_format=binary_format,
)
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
else:
for minor_version in range(16, 3, -1):
compat_version = 10, minor_version
compat_version = major_version, minor_version
binary_format = "universal2"
yield "macosx_{major}_{minor}_{binary_format}".format(
major=compat_version[0],
minor=compat_version[1],
binary_format=binary_format,
)
yield f"macosx_{major_version}_{minor_version}_{binary_format}"


def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ class TestDefaultEnvironment:
def test_matches_expected(self):
environment = default_environment()

iver = "{0.major}.{0.minor}.{0.micro}".format(sys.implementation.version)
iver = (
f"{sys.implementation.version.major}."
f"{sys.implementation.version.minor}."
f"{sys.implementation.version.micro}"
)
if sys.implementation.version.releaselevel != "final":
iver = (
f"{iver}{sys.implementation.version.releaselevel[0]}{sys.implementation.version.serial}"
f"{iver}{sys.implementation.version.releaselevel[0]}"
f"{sys.implementation.version.serial}"
)

assert environment == {
Expand Down
4 changes: 1 addition & 3 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def test_str(self, example_tag):
assert str(example_tag) == "py3-none-any"

def test_repr(self, example_tag):
assert repr(example_tag) == "<py3-none-any @ {tag_id}>".format(
tag_id=id(example_tag)
)
assert repr(example_tag) == f"<py3-none-any @ {id(example_tag)}>"

def test_attribute_access(self, example_tag):
assert example_tag.interpreter == "py3"
Expand Down

0 comments on commit 59be934

Please sign in to comment.