summaryrefslogtreecommitdiffstats
path: root/pre_commit/languages
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/languages')
-rw-r--r--pre_commit/languages/docker.py8
-rw-r--r--pre_commit/languages/node.py16
-rw-r--r--pre_commit/languages/python.py6
3 files changed, 21 insertions, 9 deletions
diff --git a/pre_commit/languages/docker.py b/pre_commit/languages/docker.py
index f449584..4091492 100644
--- a/pre_commit/languages/docker.py
+++ b/pre_commit/languages/docker.py
@@ -76,18 +76,18 @@ def install_environment(
os.mkdir(directory)
-def get_docker_user() -> str: # pragma: win32 no cover
+def get_docker_user() -> Tuple[str, ...]: # pragma: win32 no cover
try:
- return f'{os.getuid()}:{os.getgid()}'
+ return ('-u', f'{os.getuid()}:{os.getgid()}')
except AttributeError:
- return '1000:1000'
+ return ()
def docker_cmd() -> Tuple[str, ...]: # pragma: win32 no cover
return (
'docker', 'run',
'--rm',
- '-u', get_docker_user(),
+ *get_docker_user(),
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
# The `Z` option tells Docker to label the content with a private
# unshared label. Only the current container can use a private volume.
diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py
index 79ff807..9b636d3 100644
--- a/pre_commit/languages/node.py
+++ b/pre_commit/languages/node.py
@@ -1,4 +1,5 @@
import contextlib
+import functools
import os
import sys
from typing import Generator
@@ -6,6 +7,7 @@ from typing import Sequence
from typing import Tuple
import pre_commit.constants as C
+from pre_commit import parse_shebang
from pre_commit.envcontext import envcontext
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import Var
@@ -18,10 +20,22 @@ from pre_commit.util import cmd_output
from pre_commit.util import cmd_output_b
ENVIRONMENT_DIR = 'node_env'
-get_default_version = helpers.basic_get_default_version
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')):
+ return 'system'
+ else:
+ return C.DEFAULT
+
+
def _envdir(prefix: Prefix, version: str) -> str:
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
return prefix.path(directory)
diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
index 5073a8b..85d8281 100644
--- a/pre_commit/languages/python.py
+++ b/pre_commit/languages/python.py
@@ -182,8 +182,8 @@ def py_interface(
version: str,
additional_dependencies: Sequence[str],
) -> None:
- additional_dependencies = tuple(additional_dependencies)
directory = helpers.environment_dir(_dir, version)
+ install = ('python', '-mpip', 'install', '.', *additional_dependencies)
env_dir = prefix.path(directory)
with clean_path_on_failure(env_dir):
@@ -193,9 +193,7 @@ def py_interface(
python = os.path.realpath(sys.executable)
_make_venv(env_dir, python)
with in_env(prefix, version):
- helpers.run_setup_cmd(
- prefix, ('pip', 'install', '.') + additional_dependencies,
- )
+ helpers.run_setup_cmd(prefix, install)
return in_env, healthy, run_hook, install_environment