Skip to content

Commit

Permalink
MAINT: use sys.platform instead of platform.system()
Browse files Browse the repository at this point in the history
The latter is not well defined on some systems.
  • Loading branch information
dnicolodi committed Sep 2, 2023
1 parent ed82060 commit e361d29
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,16 @@ def _is_native(self, file: Union[str, pathlib.Path]) -> bool:
self._project.build() # the project needs to be built for this :/

with open(file, 'rb') as f:
if platform.system() == 'Linux':
if sys.platform == 'linux':
return f.read(4) == b'\x7fELF' # ELF
elif platform.system() == 'Darwin':
elif sys.platform == 'darwin':
return f.read(4) in (
b'\xfe\xed\xfa\xce', # 32-bit
b'\xfe\xed\xfa\xcf', # 64-bit
b'\xcf\xfa\xed\xfe', # arm64
b'\xca\xfe\xba\xbe', # universal / fat (same as java class so beware!)
)
elif platform.system() == 'Windows':
elif sys.platform == 'win32':
return f.read(2) == b'MZ'

# For unknown platforms, check for file extensions.
Expand Down Expand Up @@ -795,7 +795,7 @@ def _wheel_builder(self) -> _WheelBuilder:
@property
def _build_command(self) -> List[str]:
assert self._ninja is not None # help mypy out
if platform.system() == 'Windows':
if sys.platform == 'win32':
# On Windows use 'meson compile' to setup the MSVC compiler
# environment. Using the --ninja-args option allows to
# provide the exact same semantics for the compile arguments
Expand Down
5 changes: 2 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import ast
import os
import platform
import shutil
import sys
import textwrap
Expand Down Expand Up @@ -122,7 +121,7 @@ def wrapper(self, cmd):
['meson', 'dist'],
# wheel: calls to 'meson setup', 'meson compile', and 'meson install'
['meson', 'setup'],
['meson', 'compile'] if platform.system() == 'Windows' else ['ninja'],
['meson', 'compile'] if sys.platform == 'win32' else ['ninja'],
['meson', 'install']
]

Expand Down Expand Up @@ -239,7 +238,7 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
project.build()


@pytest.mark.skipif(not os.getenv('CI') or platform.system() != 'Windows', reason='Requires MSVC')
@pytest.mark.skipif(not os.getenv('CI') or sys.platform != 'win32', reason='Requires MSVC')
def test_compiler(venv, package_detect_compiler, tmp_path):
# Check that things are setup properly to use the MSVC compiler on
# Windows. This effectively means running the compilation step
Expand Down
7 changes: 3 additions & 4 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import importlib.machinery
import os
import pathlib
import platform
import sys
import sysconfig

Expand Down Expand Up @@ -44,7 +43,7 @@ def test_wheel_tag():
assert str(mesonpy._tags.Tag(abi='abi3')) == f'{INTERPRETER}-abi3-{PLATFORM}'


@pytest.mark.skipif(platform.system() != 'Darwin', reason='macOS specific test')
@pytest.mark.skipif(sys.platform != 'darwin', reason='macOS specific test')
def test_macos_platform_tag(monkeypatch):
for minor in range(9, 16):
monkeypatch.setenv('MACOSX_DEPLOYMENT_TARGET', f'10.{minor}')
Expand All @@ -55,7 +54,7 @@ def test_macos_platform_tag(monkeypatch):
assert next(packaging.tags.mac_platforms((major, minor))) == mesonpy._tags.get_platform_tag()


@pytest.mark.skipif(platform.system() != 'Darwin', reason='macOS specific test')
@pytest.mark.skipif(sys.platform != 'darwin', reason='macOS specific test')
def test_python_host_platform(monkeypatch):
monkeypatch.setenv('_PYTHON_HOST_PLATFORM', 'macosx-12.0-arm64')
assert mesonpy._tags.get_platform_tag().endswith('arm64')
Expand Down Expand Up @@ -98,7 +97,7 @@ def test_tag_stable_abi(monkeypatch):
assert str(builder.tag) == f'{INTERPRETER}-abi3-{PLATFORM}'


@pytest.mark.skipif(sys.version_info < (3, 8) and platform.system() == 'Windows',
@pytest.mark.skipif(sys.version_info < (3, 8) and sys.platform == 'win32',
reason='Extension modules filename suffix without ABI tags')
def test_tag_mixed_abi(monkeypatch):
builder = wheel_builder_test_factory(monkeypatch, {
Expand Down
12 changes: 6 additions & 6 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_contents_license_file(wheel_license_file):
assert artifact.read('license_file-1.0.0.dist-info/LICENSE.custom').rstrip() == b'Hello!'


@pytest.mark.skipif(platform.system() not in {'Linux', 'Darwin'}, reason='Not supported on this platform')
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_contents(package_library, wheel_library):
artifact = wheel.wheelfile.WheelFile(wheel_library)

Expand All @@ -154,14 +154,14 @@ def test_contents(package_library, wheel_library):
}


@pytest.mark.skipif(platform.system() not in {'Linux', 'Darwin'}, reason='Not supported on this platform')
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_local_lib(venv, wheel_link_against_local_lib):
venv.pip('install', wheel_link_against_local_lib)
output = venv.python('-c', 'import example; print(example.example_sum(1, 2))')
assert int(output) == 3


@pytest.mark.skipif(platform.system() not in {'Linux', 'Darwin'}, reason='Not supported on this platform')
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_rpath(wheel_link_against_local_lib, tmp_path):
artifact = wheel.wheelfile.WheelFile(wheel_link_against_local_lib)
artifact.extractall(tmp_path)
Expand All @@ -174,7 +174,7 @@ def test_rpath(wheel_link_against_local_lib, tmp_path):
assert '@loader_path/.link_against_local_lib.mesonpy.libs' in dylib.rpath


@pytest.mark.skipif(platform.system() not in {'Linux', 'Darwin'}, reason='Not supported on this platform')
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_uneeded_rpath(wheel_purelib_and_platlib, tmp_path):
artifact = wheel.wheelfile.WheelFile(wheel_purelib_and_platlib)
artifact.extractall(tmp_path)
Expand All @@ -190,7 +190,7 @@ def test_uneeded_rpath(wheel_purelib_and_platlib, tmp_path):
assert 'mesonpy.libs' not in rpath


@pytest.mark.skipif(platform.system() not in {'Linux', 'Darwin'}, reason='Not supported on this platform')
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_executable_bit(wheel_executable_bit):
artifact = wheel.wheelfile.WheelFile(wheel_executable_bit)

Expand Down Expand Up @@ -249,7 +249,7 @@ def test_purelib_platlib_split(package_purelib_platlib_split, tmp_path):
project.wheel(tmp_path)


@pytest.mark.skipif(platform.system() != 'Darwin', reason='macOS specific test')
@pytest.mark.skipif(sys.platform != 'darwin', reason='macOS specific test')
@pytest.mark.parametrize(('arch'), ['x86_64', 'arm64'])
def test_archflags_envvar(package_purelib_and_platlib, monkeypatch, tmp_path, arch):
try:
Expand Down

0 comments on commit e361d29

Please sign in to comment.