mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
make in_env part of the language api
This commit is contained in:
parent
bcf0230772
commit
ae34a962d7
23 changed files with 73 additions and 92 deletions
|
|
@ -5,7 +5,6 @@ import os
|
|||
from typing import Generator
|
||||
from typing import Sequence
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import PatchesT
|
||||
from pre_commit.envcontext import Var
|
||||
|
|
@ -27,8 +26,8 @@ def get_env_patch(venv: str) -> PatchesT: # pragma: win32 no cover
|
|||
|
||||
|
||||
@contextlib.contextmanager # pragma: win32 no cover
|
||||
def in_env(prefix: Prefix) -> Generator[None, None, None]:
|
||||
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, C.DEFAULT)
|
||||
def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
|
||||
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||
with envcontext(get_env_patch(envdir)):
|
||||
yield
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ def install_environment(
|
|||
) -> None: # pragma: win32 no cover
|
||||
helpers.assert_version_default('swift', version)
|
||||
helpers.assert_no_additional_deps('swift', additional_dependencies)
|
||||
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, C.DEFAULT)
|
||||
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||
|
||||
# Build the swift package
|
||||
os.mkdir(envdir)
|
||||
|
|
@ -55,5 +54,4 @@ def run_hook(
|
|||
file_args: Sequence[str],
|
||||
color: bool,
|
||||
) -> tuple[int, bytes]: # pragma: win32 no cover
|
||||
with in_env(hook.prefix):
|
||||
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
|
||||
return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue