Skip to content

Commit

Permalink
BUG: allow to overwrite macOS platform tag via _PYTHON_HOST_PLATFORM
Browse files Browse the repository at this point in the history
Use sysconfig.get_platform() instead of platform.mac_ver() to base the
platform tag computation.  The ability to overwrite the value returned
by former via the _PYTHON_HOST_PLATFORM environment variable is used
in macOS extension modules cross-compilation.

See mesonbuild#222 for background.
  • Loading branch information
dnicolodi committed Nov 23, 2022
1 parent 47363b5 commit e917c60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mesonpy/_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def get_abi_tag() -> str:
return abi.replace('.', '_').replace('-', '_')


def _get_macosx_platform_tag() -> str:
ver, x, arch = platform.mac_ver()
def _get_macosx_platform_tag(platform: str) -> str:
_, ver, arch = platform.split('-', 2)

# Override the macOS version if one is provided via the
# MACOS_DEPLOYMENT_TARGET environment variable.
Expand Down Expand Up @@ -133,7 +133,7 @@ def _get_macosx_platform_tag() -> str:
def get_platform_tag() -> str:
platform = sysconfig.get_platform()
if platform.startswith('macosx'):
return _get_macosx_platform_tag()
return _get_macosx_platform_tag(platform)
if _32_BIT_INTERPRETER:
# 32-bit Python running on a 64-bit kernel.
if platform == 'linux-x86_64':
Expand Down
8 changes: 8 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def test_macos_platform_tag(monkeypatch):
assert next(packaging.tags.mac_platforms((major, minor))) == mesonpy._tags.get_platform_tag()


@pytest.mark.skipif(platform.system() != 'Darwin', reason='macOS specific test')
def test_python_host_platform_env_var(monkeypatch):
monkeypatch.setenv('_PYTHON_HOST_PLATFORM', 'macosx-12.0-arm64')
mesonpy._tags.get_platform_tag() == 'macosx-12.0-arm64'
monkeypatch.setenv('_PYTHON_HOST_PLATFORM', 'macosx-11.1-x86_64')
mesonpy._tags.get_platform_tag() == 'macosx-11.0-x86_64'


def wheel_builder_test_factory(monkeypatch, content):
files = defaultdict(list)
files.update({key: [(pathlib.Path(x), os.path.join('build', x)) for x in value] for key, value in content.items()})
Expand Down

0 comments on commit e917c60

Please sign in to comment.