Skip to content

Commit

Permalink
Allow bdist_wheel working without ctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Apr 25, 2024
1 parent 0a4f40e commit 4c3d81f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
38 changes: 38 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import builtins
import functools
import os.path
import platform
import shutil
Expand Down Expand Up @@ -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

0 comments on commit 4c3d81f

Please sign in to comment.