Skip to content

Commit 376373b

Browse files
Allow bdist_wheel working without ctypes (#613)
Co-authored-by: Alex Grönholm <[email protected]>
1 parent 4ec2ae3 commit 376373b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/wheel/bdist_wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from setuptools import Command
2626

2727
from . import __version__ as wheel_version
28-
from .macosx_libfile import calculate_macosx_platform_tag
2928
from .metadata import pkginfo_to_metadata
3029
from .util import log
3130
from .vendored.packaging import tags
@@ -72,6 +71,8 @@ def get_platform(archive_root: str | None) -> str:
7271
"""Return our platform name 'win32', 'linux_x86_64'"""
7372
result = sysconfig.get_platform()
7473
if result.startswith("macosx") and archive_root is not None:
74+
from .macosx_libfile import calculate_macosx_platform_tag
75+
7576
result = calculate_macosx_platform_tag(archive_root, result)
7677
elif _is_32bit_interpreter():
7778
if result == "linux-x86_64":

tests/test_bdist_wheel.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import builtins
4+
import importlib
35
import os.path
46
import platform
57
import shutil
@@ -421,3 +423,23 @@ def test_platform_linux32(reported, expected, monkeypatch):
421423
cmd.root_is_pure = False
422424
_, _, actual = cmd.get_tag()
423425
assert actual == expected
426+
427+
428+
def test_no_ctypes(monkeypatch) -> None:
429+
def _fake_import(name: str, *args, **kwargs):
430+
if name == "ctypes":
431+
raise ModuleNotFoundError("No module named %s" % name)
432+
433+
return importlib.__import__(name, *args, **kwargs)
434+
435+
# Install an importer shim that refuses to load ctypes
436+
monkeypatch.setattr(builtins, "__import__", _fake_import)
437+
438+
# Unload all wheel modules
439+
for module in list(sys.modules):
440+
if module.startswith("wheel"):
441+
monkeypatch.delitem(sys.modules, module)
442+
443+
from wheel import bdist_wheel
444+
445+
assert bdist_wheel

0 commit comments

Comments
 (0)