Skip to content

Commit

Permalink
Allow bdist_wheel working without ctypes (#613)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Grönholm <[email protected]>
  • Loading branch information
youknowone and agronholm authored May 6, 2024
1 parent 4ec2ae3 commit 376373b
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -25,7 +25,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 @@ -72,6 +71,8 @@ def get_platform(archive_root: str | None) -> str:
"""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
22 changes: 22 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 importlib
import os.path
import platform
import shutil
Expand Down Expand Up @@ -421,3 +423,23 @@ def test_platform_linux32(reported, expected, monkeypatch):
cmd.root_is_pure = False
_, _, actual = cmd.get_tag()
assert actual == expected


def test_no_ctypes(monkeypatch) -> None:
def _fake_import(name: str, *args, **kwargs):
if name == "ctypes":
raise ModuleNotFoundError("No module named %s" % name)

return importlib.__import__(name, *args, **kwargs)

# Install an importer shim that refuses to load ctypes
monkeypatch.setattr(builtins, "__import__", _fake_import)

# Unload all wheel modules
for module in list(sys.modules):
if module.startswith("wheel"):
monkeypatch.delitem(sys.modules, module)

from wheel import bdist_wheel

assert bdist_wheel

0 comments on commit 376373b

Please sign in to comment.