diff --git a/mesonpy/_tags.py b/mesonpy/_tags.py index 60edf094d..9c09fe5a1 100644 --- a/mesonpy/_tags.py +++ b/mesonpy/_tags.py @@ -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] @@ -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] diff --git a/tests/conftest.py b/tests/conftest.py index b53161d61..af737968c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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 @@ -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() diff --git a/tests/test_tags.py b/tests/test_tags.py index bb39fd6d9..62aa61934 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -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}' @@ -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') @@ -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) @@ -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)