Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PyPy SOABI parsing #484

Merged
merged 4 commits into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/news.rst
Expand Up @@ -13,6 +13,8 @@ Release Notes
- Fixed ``ValueError: ZIP does not support timestamps before 1980`` when using
``SOURCE_DATE_EPOCH=0`` or when on-disk timestamps are earlier than 1980-01-01. Such
timestamps are now changed to the minimum value before packaging.
- The future-proof fix in 0.36.0 for converting PyPy's SOABI into a abi tag was
agronholm marked this conversation as resolved.
Show resolved Hide resolved
faulty. Fixed so that future changes in the SOABI will not change the tag.

**0.37.1 (2021-12-22)**

Expand Down
11 changes: 5 additions & 6 deletions src/wheel/bdist_wheel.py
Expand Up @@ -17,7 +17,6 @@
from email.generator import BytesGenerator, Generator
from io import BytesIO
from shutil import rmtree
from sysconfig import get_config_var
agronholm marked this conversation as resolved.
Show resolved Hide resolved
from zipfile import ZIP_DEFLATED, ZIP_STORED

import pkg_resources
Expand Down Expand Up @@ -55,7 +54,7 @@ def get_platform(archive_root):
def get_flag(var, fallback, expected=True, warn=True):
"""Use a fallback value for determining SOABI flags if the needed config
var is unset or unavailable."""
val = get_config_var(var)
val = sysconfig.get_config_var(var)
if val is None:
if warn:
warnings.warn(
Expand All @@ -69,8 +68,8 @@ def get_flag(var, fallback, expected=True, warn=True):


def get_abi_tag():
"""Return the ABI tag based on SOABI (if available) or emulate SOABI (PyPy)."""
soabi = get_config_var("SOABI")
"""Return the ABI tag based on SOABI (if available) or emulate SOABI (PyPy2)."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not really related, just noticed this) Is PyPy2 really still supported by wheel? I thought it requires Python 3.7+?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all platforms these days have a valid SOABI, even windows. So "PyPy2" is more of a generic placeholder for "weird platform".

soabi = sysconfig.get_config_var("SOABI")
impl = tags.interpreter_name()
if not soabi and impl in ("cp", "pp") and hasattr(sys, "maxunicode"):
d = ""
Expand All @@ -87,9 +86,9 @@ def get_abi_tag():
m = "m"

abi = f"{impl}{tags.interpreter_version()}{d}{m}{u}"
elif soabi and soabi.startswith("cpython-"):
elif soabi and impl == "cp":
abi = "cp" + soabi.split("-")[1]
elif soabi and soabi.startswith("pypy-"):
elif soabi and impl == "pp":
# we want something like pypy36-pp73
abi = "-".join(soabi.split("-")[:2])
abi = abi.replace(".", "_").replace("-", "_")
Expand Down
16 changes: 15 additions & 1 deletion tests/test_bdist_wheel.py
Expand Up @@ -5,11 +5,13 @@
import stat
import subprocess
import sys
import sysconfig
from zipfile import ZipFile

import pytest

from wheel.bdist_wheel import bdist_wheel
from wheel.bdist_wheel import bdist_wheel, get_abi_tag
from wheel.vendored.packaging import tags
from wheel.wheelfile import WheelFile

DEFAULT_FILES = {
Expand Down Expand Up @@ -218,3 +220,15 @@ def test_unix_epoch_timestamps(dummy_dist, monkeypatch, tmpdir):
"--build-number=2",
]
)


def test_get_abi_tag_old(monkeypatch):
monkeypatch.setattr(tags, "interpreter_name", lambda: "pp")
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "pypy36-pp73")
assert get_abi_tag() == "pypy36_pp73"


def test_get_abi_tag_new(monkeypatch):
monkeypatch.setattr(sysconfig, "get_config_var", lambda x: "pypy37-pp73-darwin")
monkeypatch.setattr(tags, "interpreter_name", lambda: "pp")
assert get_abi_tag() == "pypy37_pp73"