skip nodeenv with language_version=system

This commit is contained in:
Anthony Sottile 2020-09-07 13:43:15 -07:00
parent f511afe40e
commit f8f6d150be
3 changed files with 9 additions and 34 deletions

View file

@ -26,12 +26,9 @@ healthy = helpers.basic_healthy
@functools.lru_cache(maxsize=1)
def get_default_version() -> str:
# nodeenv does not yet support `-n system` on windows
if sys.platform == 'win32':
return C.DEFAULT
# if node is already installed, we can save a bunch of setup time by
# using the installed version
elif all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')):
if all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')):
return 'system'
else:
return C.DEFAULT
@ -84,11 +81,13 @@ def install_environment(
if sys.platform == 'win32': # pragma: no cover
envdir = fr'\\?\{os.path.normpath(envdir)}'
with clean_path_on_failure(envdir):
if version != 'system':
cmd = [
sys.executable, '-mnodeenv', '--prebuilt', '--clean-src', envdir,
sys.executable, '-mnodeenv', '--prebuilt', '--clean-src',
envdir,
]
if version != C.DEFAULT:
cmd.extend(['-n', version])
cmd.extend(['--node', version])
cmd_output_b(*cmd)
with in_env(prefix, version):

View file

@ -1,4 +1,3 @@
import sys
from unittest import mock
import pytest
@ -11,37 +10,17 @@ from pre_commit.languages.node import get_default_version
ACTUAL_GET_DEFAULT_VERSION = get_default_version.__wrapped__
@pytest.fixture
def is_linux():
with mock.patch.object(sys, 'platform', 'linux'):
yield
@pytest.fixture
def is_win32():
with mock.patch.object(sys, 'platform', 'win32'):
yield
@pytest.fixture
def find_exe_mck():
with mock.patch.object(parse_shebang, 'find_executable') as mck:
yield mck
@pytest.mark.usefixtures('is_linux')
def test_sets_system_when_node_and_npm_are_available(find_exe_mck):
find_exe_mck.return_value = '/path/to/exe'
assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
@pytest.mark.usefixtures('is_linux')
def test_uses_default_when_node_and_npm_are_not_available(find_exe_mck):
find_exe_mck.return_value = None
assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT
@pytest.mark.usefixtures('is_win32')
def test_sets_default_on_windows(find_exe_mck):
find_exe_mck.return_value = '/path/to/exe'
assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT

View file

@ -234,7 +234,6 @@ def test_run_a_docker_image_hook(tempdir_factory, store, hook_id):
)
@xfailif_windows # pragma: win32 no cover
def test_run_a_node_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'node_hooks_repo',
@ -260,7 +259,6 @@ def test_run_versioned_node_hook(tempdir_factory, store):
)
@xfailif_windows # pragma: win32 no cover
def test_node_hook_with_npm_userconfig_set(tempdir_factory, store, tmpdir):
cfg = tmpdir.join('cfg')
cfg.write('cache=/dne\n')
@ -541,7 +539,6 @@ def test_additional_ruby_dependencies_installed(tempdir_factory, store):
assert 'tins' in output
@xfailif_windows # pragma: win32 no cover
def test_additional_node_dependencies_installed(tempdir_factory, store):
path = make_repo(tempdir_factory, 'node_hooks_repo')
config = make_config_from_repo(path)