1
0
Fork 0

Merging upstream version 2.3.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:19:27 +01:00
parent c869774b2b
commit ac2b33dbed
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
17 changed files with 261 additions and 37 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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