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

Better discovery of macos system version to determine proper platform tag #314

Merged
merged 9 commits into from
Oct 23, 2019
114 changes: 114 additions & 0 deletions tests/test_macosx_libfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import os
import sys
import distutils.util

from wheel.macosx_libfile import extract_macosx_min_system_version
from wheel.pep425tags import get_platform


def test_read_from_dynlib():
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata",
"macosx_minimal_system_version")
versions = [
("test_lib_10_6_fat.dynlib", "10.6"),
("test_lib_10_10_fat.dynlib", "10.10"),
("test_lib_10_14_fat.dynlib", "10.14"),
("test_lib_10_6.dynlib", "10.6"),
("test_lib_10_10.dynlib", "10.10"),
("test_lib_10_14.dynlib", "10.14"),
("test_lib_10_6_386.dynlib", "10.6"),
("test_lib_10_10_386.dynlib", "10.10"),
("test_lib_10_14_386.dynlib", "10.14"),
("test_lib_multiple_fat.dynlib", "10.14")
]
for file_name, ver in versions:
extracted = extract_macosx_min_system_version(
os.path.join(dylib_dir, file_name)
)
str_ver = str(extracted[0]) + "." + str(extracted[1])
assert str_ver == ver
assert extract_macosx_min_system_version(
os.path.join(dylib_dir, "test_lib.c")
) is None


def return_factory(return_val):
def fun(*args, **kwargs):
return return_val

return fun


class TestGetPlatformMacosx:
def test_simple(self, monkeypatch):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.14-x86_64"))
assert get_platform(dylib_dir) == "macosx_10_14_x86_64"

def test_version_bump(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
assert get_platform(dylib_dir) == "macosx_10_14_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs higher macosx version than" in captured.err

def test_information_about_problematic_files_python_version(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_10_fat.dynlib"])]
))
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs higher macosx version than" in captured.err
assert "your python is compiled against." in captured.err
assert "test_lib_10_10_fat.dynlib" in captured.err

def test_information_about_problematic_files_env_variable(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8")
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_10_fat.dynlib"])]
))
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs higher macosx version than" in captured.err
assert "is set in MACOSX_DEPLOYMENT_TARGET variable." in captured.err
assert "test_lib_10_10_fat.dynlib" in captured.err

def test_bump_platform_tag_by_env_variable(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_6_fat.dynlib"])]
))
assert get_platform(dylib_dir) == "macosx_10_9_x86_64"
monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.10")
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
assert captured.err == ""

def test_warning_on_to_low_env_variable(self, monkeypatch, capsys):
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version")
monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64"))
monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8")
monkeypatch.setattr(os, "walk", return_factory(
[(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_6_fat.dynlib"])]
))
assert get_platform(dylib_dir) == "macosx_10_9_x86_64"
captured = capsys.readouterr()
assert "MACOSX_DEPLOYMENT_TARGET is set to lower value than your python" in captured.err


def test_get_platform_linux(monkeypatch):
monkeypatch.setattr(distutils.util, "get_platform", return_factory("linux_x86_64"))
monkeypatch.setattr(sys, "maxsize", 2147483647)
assert get_platform(None) == "linux_i686"
13 changes: 13 additions & 0 deletions tests/testdata/macosx_minimal_system_version/test_lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int num_of_letters(char* text){
int num = 0;
char * lett = text;
while (lett != 0){
if (*lett >= 'a' && *lett <= 'z'){
num += 1;
} else if (*lett >= 'A' && *lett <= 'Z'){
num += 1;
}
lett += 1;
}
return num;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 9 additions & 2 deletions wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class bdist_wheel(Command):
"temporary directory for creating the distribution"),
('plat-name=', 'p',
"platform name to embed in generated filenames "
"(default: %s)" % get_platform()),
"(default: %s)" % get_platform(None)),
('keep-temp', 'k',
"keep the pseudo-installation tree around after " +
"creating the distribution archive"),
Expand Down Expand Up @@ -150,9 +150,15 @@ def get_tag(self):
elif self.root_is_pure:
plat_name = 'any'
else:
plat_name = self.plat_name or get_platform()
# macosx contains system version in platform name so need special handle
if self.plat_name and not self.plat_name.startswith("macosx"):
plat_name = self.plat_name
else:
plat_name = get_platform(self.bdist_dir)
Czaki marked this conversation as resolved.
Show resolved Hide resolved

if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647:
plat_name = 'linux_i686'

plat_name = plat_name.replace('-', '_').replace('.', '_')

if self.root_is_pure:
Expand All @@ -173,6 +179,7 @@ def get_tag(self):
abi_tag = str(get_abi_tag()).lower()
tag = (impl, abi_tag, plat_name)
supported_tags = pep425tags.get_supported(
self.bdist_dir,
supplied_platform=plat_name if self.plat_name_supplied else None)
# XXX switch to this alternate implementation for non-pure:
if not self.py_limited_api:
Expand Down
Loading