Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bdist_wheel working without ctypes #613

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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__
agronholm marked this conversation as resolved.
Show resolved Hide resolved


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