Skip to content

Commit c6b91c4

Browse files
Install executable to platlib and override mesonpy._WheelBuilder._has_extension_modules (#317)
1 parent f18b97e commit c6b91c4

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

meson.build

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ project(
55
default_options : ['warning_level=0'],
66
)
77

8-
# Setting `pure: true` routes the Python package to purelib, so platlib stays
9-
# empty. The bundled Hugo executable is installed under datadir and the marker
10-
# file below keeps the wheel tag at py3-none-<platform> instead of a
11-
# Python-version-specific ABI tag.
8+
# Setting `pure: false` routes both Python sources and the Hugo executable to
9+
# platlib, keeping them in the same site-packages subtree. This satisfies
10+
# auditwheel (ELF binaries must not be in purelib) and lets cli.py locate the
11+
# binary via Path(__file__).parent regardless of install scheme.
12+
# The marker file below keeps the wheel tag at py3-none-<platform> instead of
13+
# a Python-version-specific ABI tag.
1214
# See _has_extension_modules and _pure in mesonpy/__init__.py
13-
py = import('python').find_installation(pure: true)
15+
py = import('python').find_installation(pure: false)
1416

1517
go = find_program('go', required: true)
1618
git = find_program('git', required: true)

scripts/hugo_meson_python_wrapper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ def _maybe_set_host_platform(config_settings: dict[str, Any] | None) -> None:
9797
) # TODO: drop this hack/use of private API
9898

9999

100+
def _force_py3_none_tag() -> None:
101+
"""Force py3-none-<platform> instead of cp<XY>-cp<XY>-<platform>.
102+
103+
With pure: false, meson-python assumes every file in {platlib} is a CPython
104+
extension module and applies a Python-version-specific ABI tag. The Hugo
105+
binary is a Go executable that runs under any Python version, so we patch
106+
_has_extension_modules to always return False, and that causes meson-python
107+
to fall through to the py3-none-<platform> branch in its tag property.
108+
TODO: drop this hack/use of public API if meson-python someday exposes a way
109+
to opt out of the CPython ABI tag for non-extension platlib content.
110+
"""
111+
mesonpy._WheelBuilder._has_extension_modules = property(lambda _: False)
112+
113+
100114
# Unchanged meson-python PEP 517 entry points below
101115

102116

@@ -106,6 +120,7 @@ def build_wheel(
106120
metadata_directory: str | None = None,
107121
) -> str:
108122
_maybe_set_host_platform(config_settings)
123+
_force_py3_none_tag()
109124
return mesonpy.build_wheel(wheel_directory, config_settings, metadata_directory)
110125

111126

@@ -115,6 +130,7 @@ def build_editable(
115130
metadata_directory: str | None = None,
116131
) -> str:
117132
_maybe_set_host_platform(config_settings)
133+
_force_py3_none_tag()
118134
return mesonpy.build_editable(wheel_directory, config_settings, metadata_directory)
119135

120136

0 commit comments

Comments
 (0)