Skip to content

Commit e361d29

Browse files
committed
MAINT: use sys.platform instead of platform.system()
The latter is not well defined on some systems.
1 parent ed82060 commit e361d29

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

mesonpy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,16 @@ def _is_native(self, file: Union[str, pathlib.Path]) -> bool:
398398
self._project.build() # the project needs to be built for this :/
399399

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

413413
# For unknown platforms, check for file extensions.
@@ -795,7 +795,7 @@ def _wheel_builder(self) -> _WheelBuilder:
795795
@property
796796
def _build_command(self) -> List[str]:
797797
assert self._ninja is not None # help mypy out
798-
if platform.system() == 'Windows':
798+
if sys.platform == 'win32':
799799
# On Windows use 'meson compile' to setup the MSVC compiler
800800
# environment. Using the --ninja-args option allows to
801801
# provide the exact same semantics for the compile arguments

tests/test_project.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import ast
66
import os
7-
import platform
87
import shutil
98
import sys
109
import textwrap
@@ -122,7 +121,7 @@ def wrapper(self, cmd):
122121
['meson', 'dist'],
123122
# wheel: calls to 'meson setup', 'meson compile', and 'meson install'
124123
['meson', 'setup'],
125-
['meson', 'compile'] if platform.system() == 'Windows' else ['ninja'],
124+
['meson', 'compile'] if sys.platform == 'win32' else ['ninja'],
126125
['meson', 'install']
127126
]
128127

@@ -239,7 +238,7 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
239238
project.build()
240239

241240

242-
@pytest.mark.skipif(not os.getenv('CI') or platform.system() != 'Windows', reason='Requires MSVC')
241+
@pytest.mark.skipif(not os.getenv('CI') or sys.platform != 'win32', reason='Requires MSVC')
243242
def test_compiler(venv, package_detect_compiler, tmp_path):
244243
# Check that things are setup properly to use the MSVC compiler on
245244
# Windows. This effectively means running the compilation step

tests/test_tags.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import importlib.machinery
66
import os
77
import pathlib
8-
import platform
98
import sys
109
import sysconfig
1110

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

4645

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

5756

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

10099

101-
@pytest.mark.skipif(sys.version_info < (3, 8) and platform.system() == 'Windows',
100+
@pytest.mark.skipif(sys.version_info < (3, 8) and sys.platform == 'win32',
102101
reason='Extension modules filename suffix without ABI tags')
103102
def test_tag_mixed_abi(monkeypatch):
104103
builder = wheel_builder_test_factory(monkeypatch, {

tests/test_wheel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_contents_license_file(wheel_license_file):
140140
assert artifact.read('license_file-1.0.0.dist-info/LICENSE.custom').rstrip() == b'Hello!'
141141

142142

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

@@ -154,14 +154,14 @@ def test_contents(package_library, wheel_library):
154154
}
155155

156156

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

163163

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

176176

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

192192

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

@@ -249,7 +249,7 @@ def test_purelib_platlib_split(package_purelib_platlib_split, tmp_path):
249249
project.wheel(tmp_path)
250250

251251

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

0 commit comments

Comments
 (0)