Skip to content

Commit

Permalink
fix: evaluate free threaded wheel tags (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Sep 11, 2024
1 parent d9ae6c9 commit d2ccd88
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/dep_logic/tags/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse(cls, platform: str) -> Self:
Available operating systems:
- `linux`: an alias for `manylinux_2_17_x86_64`
- `windows`: an alias for `win_amd64`
- `macos`: an alias for `macos_12_0_arm64`
- `macos`: an alias for `macos_14_0_arm64`
- `alpine`: an alias for `musllinux_1_2_x86_64`
- `windows_amd64`
- `windows_x86`
Expand All @@ -54,7 +54,7 @@ def parse(cls, platform: str) -> Self:
elif platform == "windows":
return cls(os.Windows(), Arch.X86_64)
elif platform == "macos":
return cls(os.Macos(12, 0), Arch.Aarch64)
return cls(os.Macos(14, 0), Arch.Aarch64)
elif platform == "alpine":
return cls(os.Musllinux(1, 2), Arch.X86_64)
elif platform.startswith("windows_"):
Expand Down
20 changes: 17 additions & 3 deletions src/dep_logic/tags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ def _evaluate_python(
.replace("pyston", "pt")
.lower()
)
allow_abi3 = impl == "cp" and (
self.implementation is None or not self.implementation.gil_disabled
)
free_threaded: bool | None = None
if self.implementation is not None:
free_threaded = self.implementation.gil_disabled
try:
if impl == "cp" and abi_impl == "abi3":
if abi_impl == "abi3":
if not allow_abi3:
return None
if (
parse_version_specifier(f">={major}.{minor or 0}")
& self.requires_python
Expand All @@ -178,8 +186,14 @@ def _evaluate_python(
# cp36-cp36m-*
# cp312-cp312m-*
# pp310-pypy310_pp75-*
if abi_impl != "none" and not abi_impl.startswith(python_tag.lower()):
return None
if abi_impl != "none":
if not abi_impl.startswith(python_tag.lower()):
return None
if (
free_threaded is not None
and abi_impl.endswith("t") is not free_threaded
):
return None
if major and minor:
wheel_range = parse_version_specifier(f"=={major}.{minor}.*")
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/tags/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_platform_tags_musl():
"text,expected,normalized",
[
("linux", Platform(os.Manylinux(2, 17), Arch.X86_64), "manylinux_2_17_x86_64"),
("macos", Platform(os.Macos(12, 0), Arch.Aarch64), "macos_12_0_arm64"),
("macos", Platform(os.Macos(14, 0), Arch.Aarch64), "macos_14_0_arm64"),
("windows", Platform(os.Windows(), Arch.X86_64), "windows_amd64"),
("alpine", Platform(os.Musllinux(1, 2), Arch.X86_64), "musllinux_1_2_x86_64"),
(
Expand Down
19 changes: 19 additions & 0 deletions tests/tags/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

def test_check_wheel_tags():
wheels = [
"protobuf-5.27.2-cp313-cp313t-macosx_14_0_arm64.whl",
"protobuf-5.27.2-cp313-cp313-macosx_14_0_arm64.whl",
"protobuf-5.27.2-cp310-abi3-win32.whl",
"protobuf-5.27.2-cp310-abi3-win_amd64.whl",
"protobuf-5.27.2-cp310-cp310-macosx_12_0_arm64.whl",
Expand Down Expand Up @@ -52,11 +54,26 @@ def test_check_wheel_tags():
}
filtered_wheels = sorted(wheel_compats, key=wheel_compats.__getitem__, reverse=True)
assert filtered_wheels == [
"protobuf-5.27.2-cp313-cp313-macosx_14_0_arm64.whl",
"protobuf-5.27.2-cp310-cp310-macosx_12_0_arm64.whl",
"protobuf-5.27.2-cp38-abi3-macosx_10_9_universal2.whl",
"protobuf-5.27.2-py3-none-any.whl",
]

macos_free_threaded_env = EnvSpec.from_spec(">=3.9", "macos", "cpython", True)
wheel_compats = {
f: c
for f, c in {
f: macos_free_threaded_env.wheel_compatibility(f) for f in wheels
}.items()
if c is not None
}
filtered_wheels = sorted(wheel_compats, key=wheel_compats.__getitem__, reverse=True)
assert filtered_wheels == [
"protobuf-5.27.2-cp313-cp313t-macosx_14_0_arm64.whl",
"protobuf-5.27.2-py3-none-any.whl",
]

python_env = EnvSpec.from_spec(">=3.9")
wheel_compats = {
f: c
Expand All @@ -65,6 +82,8 @@ def test_check_wheel_tags():
}
filtered_wheels = sorted(wheel_compats, key=wheel_compats.__getitem__, reverse=True)
assert filtered_wheels == [
"protobuf-5.27.2-cp313-cp313t-macosx_14_0_arm64.whl",
"protobuf-5.27.2-cp313-cp313-macosx_14_0_arm64.whl",
"protobuf-5.27.2-cp310-cp310-macosx_12_0_arm64.whl",
"protobuf-5.27.2-cp310-abi3-win32.whl",
"protobuf-5.27.2-cp310-abi3-win_amd64.whl",
Expand Down

0 comments on commit d2ccd88

Please sign in to comment.