Skip to content

Commit

Permalink
Fixed PyPy SOABI parsing (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip authored Nov 2, 2022
1 parent 7627548 commit 747e1f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
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
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
Original file line number Diff line number Diff line change
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
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)."""
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
Original file line number Diff line number Diff line change
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"

0 comments on commit 747e1f6

Please sign in to comment.