diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index 6b811ee3..8475b782 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -24,7 +24,6 @@ from setuptools import Command from . import __version__ as wheel_version -from .macosx_libfile import calculate_macosx_platform_tag from .metadata import pkginfo_to_metadata from .util import log from .vendored.packaging import tags @@ -68,6 +67,8 @@ def get_platform(archive_root): """Return our platform name 'win32', 'linux_x86_64'""" result = sysconfig.get_platform() if result.startswith("macosx") and archive_root is not None: + from .macosx_libfile import calculate_macosx_platform_tag + result = calculate_macosx_platform_tag(archive_root, result) elif _is_32bit_interpreter(): if result == "linux-x86_64": diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index b440b649..46012786 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -1,5 +1,7 @@ from __future__ import annotations +import builtins +import functools import os.path import platform import shutil @@ -421,3 +423,39 @@ def test_platform_linux32(reported, expected, monkeypatch): cmd.root_is_pure = False _, _, actual = cmd.get_tag() assert actual == expected + + +builtin_import = builtins.__import__ + + +def _fake_import(name: str, *args, **kwargs): + if name == "ctypes": + raise ModuleNotFoundError("No module named %s" % name) + return builtin_import(name, *args, **kwargs) + + +def mock_import(func): + @functools.wraps(func) + def wrap() -> None: + wheel_module_items = [ + item for item in sys.modules.items() if item[0].startswith("wheel") + ] + try: + builtins.__import__ = _fake_import + for name, _ in wheel_module_items: + del sys.modules[name] + return func() + finally: + # restore original modules + builtins.__import__ = builtin_import + for name, module in wheel_module_items: + sys.modules[name] = module + + return wrap + + +@mock_import +def test_no_ctypes() -> None: + from wheel import bdist_wheel + + assert bdist_wheel