Skip to content

Commit

Permalink
BUG: disable abi3 wheel tag for PyPy
Browse files Browse the repository at this point in the history
PyPy supports the limited API but not the stable ABI.
  • Loading branch information
lpsinger authored and dnicolodi committed Aug 17, 2024
1 parent 691d312 commit 732edd1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
33 changes: 17 additions & 16 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,23 @@ def entrypoints_txt(self) -> bytes:

@cached_property
def _stable_abi(self) -> Optional[str]:
if self._limited_api:
# PyPy does not use a special extension module filename
# suffix for modules targeting the stable API.
if '__pypy__' not in sys.builtin_module_names:
# Verify stable ABI compatibility: examine files installed
# in {platlib} that look like extension modules, and raise
# an exception if any of them has a Python version
# specific extension filename suffix ABI tag.
for path, _ in self._manifest['platlib']:
match = _EXTENSION_SUFFIX_REGEX.match(path.name)
if match:
abi = match.group('abi')
if abi is not None and abi != 'abi3':
raise BuildError(
f'The package declares compatibility with Python limited API but extension '
f'module {os.fspath(path)!r} is tagged for a specific Python version.')
# PyPy supports the limited API but does not provide a stable
# ABI, therefore extension modules using the limited API do
# not use the stable ABI filename suffix and wheels should not
# be tagged with the abi3 tag.
if self._limited_api and '__pypy__' not in sys.builtin_module_names:
# Verify stable ABI compatibility: examine files installed
# in {platlib} that look like extension modules, and raise
# an exception if any of them has a Python version
# specific extension filename suffix ABI tag.
for path, _ in self._manifest['platlib']:
match = _EXTENSION_SUFFIX_REGEX.match(path.name)
if match:
abi = match.group('abi')
if abi is not None and abi != 'abi3':
raise BuildError(
f'The package declares compatibility with Python limited API but extension '
f'module {os.fspath(path)!r} is tagged for a specific Python version.')
return 'abi3'
return None

Expand Down
6 changes: 4 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ def test_tag_stable_abi():
builder = wheel_builder_test_factory({
'platlib': [f'extension{ABI3SUFFIX}'],
}, limited_api=True)
assert str(builder.tag) == f'{INTERPRETER}-abi3-{PLATFORM}'
# PyPy does not support the stable ABI.
abi = 'abi3' if '__pypy__' not in sys.builtin_module_names else ABI
assert str(builder.tag) == f'{INTERPRETER}-{abi}-{PLATFORM}'


@pytest.mark.xfail(sys.version_info < (3, 8) and sys.platform == 'win32', reason='Extension modules suffix without ABI tags')
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not use special modules suffix for stable ABI')
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not support the stable ABI')
def test_tag_mixed_abi():
builder = wheel_builder_test_factory({
'platlib': [f'extension{ABI3SUFFIX}', f'another{SUFFIX}'],
Expand Down
1 change: 1 addition & 0 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def test_skip_subprojects(package_subproject, tmp_path, arg):
# Requires Meson 1.3.0, see https://github.com/mesonbuild/meson/pull/11745.
@pytest.mark.skipif(MESON_VERSION < (1, 2, 99), reason='Meson version too old')
@pytest.mark.skipif(NOGIL_BUILD, reason='Free-threaded CPython does not support the limited API')
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not support the abi3 platform tag for wheels')
def test_limited_api(wheel_limited_api):
artifact = wheel.wheelfile.WheelFile(wheel_limited_api)
name = artifact.parsed_filename
Expand Down

0 comments on commit 732edd1

Please sign in to comment.