From 551bc2293f5d4cae5f65e91b57d4594878d62378 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sun, 8 Jun 2025 13:45:29 +0200 Subject: [PATCH 1/3] TST: apply environment variable cleanup to all tests This has no adverse consequence and makes it impossible to forget to add it to relevant tests, which is important because the tests are not commonly run with the environment variables set, making the failure hard to discover. --- tests/conftest.py | 9 +++++++++ tests/test_tags.py | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b53161d61..47c57e210 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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..75d5b650e 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}' @@ -118,14 +112,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 +130,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) From 01d00df480c1b5146fa52625916c37e8bd940496 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sun, 8 Jun 2025 13:50:31 +0200 Subject: [PATCH 2/3] TST: there is no need to build packages from a git repository --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 47c57e210..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 From 6a688b1dc811239694e8467a4fccae2f875f73be Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sun, 8 Jun 2025 22:50:40 +0200 Subject: [PATCH 3/3] BUG: allow $MACOSX_DEPLOYMENT_TARGET to be set to major version only Accept version specifiers containing only the major version, for example "11", in addition to the already supported major.minor and major.minor.patch formats, for example "11.0" or "11.0.0". --- mesonpy/_tags.py | 6 ++++-- tests/test_tags.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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/test_tags.py b/tests/test_tags.py index 75d5b650e..62aa61934 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -55,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')