Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ce4a54

Browse files
committed
prefer sys.platform over os.name when checking for windows OS
1 parent 2822de9 commit 5ce4a54

8 files changed

Lines changed: 13 additions & 10 deletions

File tree

pre_commit/languages/conda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
import os
5+
import sys
56
from typing import Generator
67
from typing import Sequence
78

@@ -26,7 +27,7 @@ def get_env_patch(env: str) -> PatchesT:
2627
# $CONDA_PREFIX/Scripts and $CONDA_PREFIX. Whereas the latter only
2728
# seems to be used for python.exe.
2829
path: SubstitutionT = (os.path.join(env, 'bin'), os.pathsep, Var('PATH'))
29-
if os.name == 'nt': # pragma: no cover (platform specific)
30+
if sys.platform == 'win32': # pragma: win32 cover
3031
path = (env, os.pathsep, *path)
3132
path = (os.path.join(env, 'Scripts'), os.pathsep, *path)
3233
path = (os.path.join(env, 'Library', 'bin'), os.pathsep, *path)

pre_commit/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _read_pyvenv_cfg(filename: str) -> dict[str, str]:
4848

4949
def bin_dir(venv: str) -> str:
5050
"""On windows there's a different directory for the virtualenv"""
51-
bin_part = 'Scripts' if os.name == 'nt' else 'bin'
51+
bin_part = 'Scripts' if sys.platform == 'win32' else 'bin'
5252
return os.path.join(venv, bin_part)
5353

5454

@@ -137,7 +137,7 @@ def norm_version(version: str) -> str | None:
137137
elif _sys_executable_matches(version): # virtualenv defaults to our exe
138138
return None
139139

140-
if os.name == 'nt': # pragma: no cover (windows)
140+
if sys.platform == 'win32': # pragma: no cover (windows)
141141
version_exec = _find_by_py_launcher(version)
142142
if version_exec:
143143
return version_exec

pre_commit/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
119119
return returncode, stdout, stderr
120120

121121

122-
if os.name != 'nt': # pragma: win32 no cover
122+
if sys.platform != 'win32': # pragma: win32 no cover
123123
from os import openpty
124124
import termios
125125

testing/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import os.path
55
import subprocess
6+
import sys
67

78
import pytest
89

@@ -30,7 +31,7 @@ def cmd_output_mocked_pre_commit_home(
3031
return ret, out.replace('\r\n', '\n'), None
3132

3233

33-
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
34+
xfailif_windows = pytest.mark.xfail(sys.platform == 'win32', reason='windows')
3435

3536

3637
def run_opts(

tests/languages/python_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_read_pyvenv_cfg_non_utf8(tmpdir):
3636

3737
def test_norm_version_expanduser():
3838
home = os.path.expanduser('~')
39-
if os.name == 'nt': # pragma: nt cover
39+
if sys.platform == 'win32': # pragma: win32 cover
4040
path = r'~\python343'
4141
expected_path = fr'{home}\python343'
42-
else: # pragma: nt no cover
42+
else: # pragma: win32 no cover
4343
path = '~/.pyenv/versions/3.4.3/bin/python'
4444
expected_path = f'{home}/.pyenv/versions/3.4.3/bin/python'
4545
result = python.norm_version(path)

tests/parse_shebang_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_normexe_does_not_exist_sep():
9494
assert excinfo.value.args == ('Executable `./i-dont-exist-lol` not found',)
9595

9696

97-
@pytest.mark.xfail(os.name == 'nt', reason='posix only')
97+
@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
9898
def test_normexe_not_executable(tmpdir): # pragma: win32 no cover
9999
tmpdir.join('exe').ensure()
100100
with tmpdir.as_cwd(), pytest.raises(OSError) as excinfo:

tests/repository_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os.path
44
import shutil
5+
import sys
56
from typing import Any
67
from unittest import mock
78

@@ -198,7 +199,7 @@ def test_intermixed_stdout_stderr(tempdir_factory, store):
198199
)
199200

200201

201-
@pytest.mark.xfail(os.name == 'nt', reason='ptys are posix-only')
202+
@pytest.mark.xfail(sys.platform == 'win32', reason='ptys are posix-only')
202203
def test_output_isatty(tempdir_factory, store):
203204
_test_hook_repo(
204205
tempdir_factory, store, 'stdout_stderr_repo',

tests/xargs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_xargs_propagate_kwargs_to_cmd():
187187
assert b'Pre commit is awesome' in stdout
188188

189189

190-
@pytest.mark.xfail(os.name == 'nt', reason='posix only')
190+
@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
191191
def test_xargs_color_true_makes_tty():
192192
retcode, out = xargs.xargs(
193193
(sys.executable, '-c', 'import sys; print(sys.stdout.isatty())'),

0 commit comments

Comments
 (0)