mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2796 from m-rsha/os-name
prefer `sys.platform` over `os.name` when checking for windows OS
This commit is contained in:
commit
321685ee0e
8 changed files with 13 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
||||||
|
|
@ -26,7 +27,7 @@ def get_env_patch(env: str) -> PatchesT:
|
||||||
# $CONDA_PREFIX/Scripts and $CONDA_PREFIX. Whereas the latter only
|
# $CONDA_PREFIX/Scripts and $CONDA_PREFIX. Whereas the latter only
|
||||||
# seems to be used for python.exe.
|
# seems to be used for python.exe.
|
||||||
path: SubstitutionT = (os.path.join(env, 'bin'), os.pathsep, Var('PATH'))
|
path: SubstitutionT = (os.path.join(env, 'bin'), os.pathsep, Var('PATH'))
|
||||||
if os.name == 'nt': # pragma: no cover (platform specific)
|
if sys.platform == 'win32': # pragma: win32 cover
|
||||||
path = (env, os.pathsep, *path)
|
path = (env, os.pathsep, *path)
|
||||||
path = (os.path.join(env, 'Scripts'), os.pathsep, *path)
|
path = (os.path.join(env, 'Scripts'), os.pathsep, *path)
|
||||||
path = (os.path.join(env, 'Library', 'bin'), os.pathsep, *path)
|
path = (os.path.join(env, 'Library', 'bin'), os.pathsep, *path)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ def _read_pyvenv_cfg(filename: str) -> dict[str, str]:
|
||||||
|
|
||||||
def bin_dir(venv: str) -> str:
|
def bin_dir(venv: str) -> str:
|
||||||
"""On windows there's a different directory for the virtualenv"""
|
"""On windows there's a different directory for the virtualenv"""
|
||||||
bin_part = 'Scripts' if os.name == 'nt' else 'bin'
|
bin_part = 'Scripts' if sys.platform == 'win32' else 'bin'
|
||||||
return os.path.join(venv, bin_part)
|
return os.path.join(venv, bin_part)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ def norm_version(version: str) -> str | None:
|
||||||
elif _sys_executable_matches(version): # virtualenv defaults to our exe
|
elif _sys_executable_matches(version): # virtualenv defaults to our exe
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if os.name == 'nt': # pragma: no cover (windows)
|
if sys.platform == 'win32': # pragma: no cover (windows)
|
||||||
version_exec = _find_by_py_launcher(version)
|
version_exec = _find_by_py_launcher(version)
|
||||||
if version_exec:
|
if version_exec:
|
||||||
return version_exec
|
return version_exec
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str | None]:
|
||||||
return returncode, stdout, stderr
|
return returncode, stdout, stderr
|
||||||
|
|
||||||
|
|
||||||
if os.name != 'nt': # pragma: win32 no cover
|
if sys.platform != 'win32': # pragma: win32 no cover
|
||||||
from os import openpty
|
from os import openpty
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
import contextlib
|
import contextlib
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ def cmd_output_mocked_pre_commit_home(
|
||||||
return ret, out.replace('\r\n', '\n'), None
|
return ret, out.replace('\r\n', '\n'), None
|
||||||
|
|
||||||
|
|
||||||
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
xfailif_windows = pytest.mark.xfail(sys.platform == 'win32', reason='windows')
|
||||||
|
|
||||||
|
|
||||||
def run_opts(
|
def run_opts(
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ def test_read_pyvenv_cfg_non_utf8(tmpdir):
|
||||||
|
|
||||||
def test_norm_version_expanduser():
|
def test_norm_version_expanduser():
|
||||||
home = os.path.expanduser('~')
|
home = os.path.expanduser('~')
|
||||||
if os.name == 'nt': # pragma: nt cover
|
if sys.platform == 'win32': # pragma: win32 cover
|
||||||
path = r'~\python343'
|
path = r'~\python343'
|
||||||
expected_path = fr'{home}\python343'
|
expected_path = fr'{home}\python343'
|
||||||
else: # pragma: nt no cover
|
else: # pragma: win32 no cover
|
||||||
path = '~/.pyenv/versions/3.4.3/bin/python'
|
path = '~/.pyenv/versions/3.4.3/bin/python'
|
||||||
expected_path = f'{home}/.pyenv/versions/3.4.3/bin/python'
|
expected_path = f'{home}/.pyenv/versions/3.4.3/bin/python'
|
||||||
result = python.norm_version(path)
|
result = python.norm_version(path)
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ def test_normexe_does_not_exist_sep():
|
||||||
assert excinfo.value.args == ('Executable `./i-dont-exist-lol` not found',)
|
assert excinfo.value.args == ('Executable `./i-dont-exist-lol` not found',)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(os.name == 'nt', reason='posix only')
|
@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
|
||||||
def test_normexe_not_executable(tmpdir): # pragma: win32 no cover
|
def test_normexe_not_executable(tmpdir): # pragma: win32 no cover
|
||||||
tmpdir.join('exe').ensure()
|
tmpdir.join('exe').ensure()
|
||||||
with tmpdir.as_cwd(), pytest.raises(OSError) as excinfo:
|
with tmpdir.as_cwd(), pytest.raises(OSError) as excinfo:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
|
@ -198,7 +199,7 @@ def test_intermixed_stdout_stderr(tempdir_factory, store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(os.name == 'nt', reason='ptys are posix-only')
|
@pytest.mark.xfail(sys.platform == 'win32', reason='ptys are posix-only')
|
||||||
def test_output_isatty(tempdir_factory, store):
|
def test_output_isatty(tempdir_factory, store):
|
||||||
_test_hook_repo(
|
_test_hook_repo(
|
||||||
tempdir_factory, store, 'stdout_stderr_repo',
|
tempdir_factory, store, 'stdout_stderr_repo',
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ def test_xargs_propagate_kwargs_to_cmd():
|
||||||
assert b'Pre commit is awesome' in stdout
|
assert b'Pre commit is awesome' in stdout
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(os.name == 'nt', reason='posix only')
|
@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
|
||||||
def test_xargs_color_true_makes_tty():
|
def test_xargs_color_true_makes_tty():
|
||||||
retcode, out = xargs.xargs(
|
retcode, out = xargs.xargs(
|
||||||
(sys.executable, '-c', 'import sys; print(sys.stdout.isatty())'),
|
(sys.executable, '-c', 'import sys; print(sys.stdout.isatty())'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue