Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mesonpy/_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def _get_macosx_platform_tag() -> str:
# Override the macOS version if one is provided via the
# MACOSX_DEPLOYMENT_TARGET environment variable.
try:
version = tuple(map(int, os.environ.get('MACOSX_DEPLOYMENT_TARGET', '').split('.')))[:2]
parts = os.environ.get('MACOSX_DEPLOYMENT_TARGET', '').split('.')[:2]
version = tuple(map(int, parts + ['0'] * (2 - len(parts))))
except ValueError:
version = tuple(map(int, ver.split('.')))[:2]

Expand Down Expand Up @@ -164,7 +165,8 @@ def _get_ios_platform_tag() -> str:
# Override the iOS version if one is provided via the
# IPHONEOS_DEPLOYMENT_TARGET environment variable.
try:
version = tuple(map(int, os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', '').split('.')))[:2]
parts = os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', '').split('.')[:2]
version = tuple(map(int, parts + ['0'] * (2 - len(parts))))
except ValueError:
version = tuple(map(int, platform.ios_ver().release.split('.')))[:2] # type: ignore[attr-defined]

Expand Down
13 changes: 11 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def fixture(tmp_path_session):
def generate_wheel_fixture(package):
@pytest.fixture(scope='session')
def fixture(tmp_path_session):
with chdir(package_dir / package), in_git_repo_context():
with chdir(package_dir / package):
return tmp_path_session / mesonpy.build_wheel(tmp_path_session)
return fixture

Expand All @@ -163,7 +163,7 @@ def generate_editable_fixture(package):
@pytest.fixture(scope='session')
def fixture(tmp_path_session):
shutil.rmtree(package_dir / package / '.mesonpy' / 'editable', ignore_errors=True)
with chdir(package_dir / package), in_git_repo_context():
with chdir(package_dir / package):
return tmp_path_session / mesonpy.build_editable(tmp_path_session)
return fixture

Expand All @@ -183,3 +183,12 @@ def disable_pip_version_check():
mpatch = pytest.MonkeyPatch()
yield mpatch.setenv('PIP_DISABLE_PIP_VERSION_CHECK', '1')
mpatch.undo()


@pytest.fixture(autouse=True, scope='session')
def cleanenv():
# Cannot use the 'monkeypatch' fixture because of scope mismatch.
mpatch = pytest.MonkeyPatch()
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
yield mpatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)
mpatch.undo()
19 changes: 9 additions & 10 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ def get_abi3_suffix():
ABI3SUFFIX = get_abi3_suffix()


@pytest.fixture()
def cleanenv(monkeypatch):
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
monkeypatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)


def test_wheel_tag(cleanenv):
def test_wheel_tag():
assert str(mesonpy._tags.Tag()) == f'{INTERPRETER}-{ABI}-{PLATFORM}'
assert str(mesonpy._tags.Tag(abi='abi3')) == f'{INTERPRETER}-abi3-{PLATFORM}'

Expand All @@ -61,6 +55,11 @@ def test_macos_platform_tag(monkeypatch):
for minor in range(3):
monkeypatch.setenv('MACOSX_DEPLOYMENT_TARGET', f'{major}.{minor}')
assert next(packaging.tags.mac_platforms((major, minor))) == mesonpy._tags.get_platform_tag()
for major in range(11, 13):
monkeypatch.setenv('MACOSX_DEPLOYMENT_TARGET', f'{major}.0')
assert next(packaging.tags.mac_platforms((major, 0))) == mesonpy._tags.get_platform_tag()
monkeypatch.setenv('MACOSX_DEPLOYMENT_TARGET', f'{major}')
assert next(packaging.tags.mac_platforms((major, 0))) == mesonpy._tags.get_platform_tag()


@pytest.mark.skipif(sys.platform != 'darwin', reason='macOS specific test')
Expand Down Expand Up @@ -118,14 +117,14 @@ def test_tag_purelib_wheel():
assert str(builder.tag) == 'py3-none-any'


def test_tag_platlib_wheel(cleanenv):
def test_tag_platlib_wheel():
builder = wheel_builder_test_factory({
'platlib': [f'extension{SUFFIX}'],
})
assert str(builder.tag) == f'{INTERPRETER}-{ABI}-{PLATFORM}'


def test_tag_stable_abi(cleanenv):
def test_tag_stable_abi():
builder = wheel_builder_test_factory({
'platlib': [f'extension{ABI3SUFFIX}'],
}, limited_api=True)
Expand All @@ -136,7 +135,7 @@ def test_tag_stable_abi(cleanenv):

@pytest.mark.xfail(sys.version_info < (3, 8) and sys.platform == 'win32', reason='Extension modules suffix without ABI tags')
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not support the stable ABI')
def test_tag_mixed_abi(cleanenv):
def test_tag_mixed_abi():
builder = wheel_builder_test_factory({
'platlib': [f'extension{ABI3SUFFIX}', f'another{SUFFIX}'],
}, pure=False, limited_api=True)
Expand Down
Loading