mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
coursier: additional_dependencies support
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import os.path
|
||||
from typing import Generator
|
||||
from typing import Sequence
|
||||
|
||||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.envcontext import PatchesT
|
||||
from pre_commit.envcontext import Var
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.parse_shebang import find_executable
|
||||
from pre_commit.prefix import Prefix
|
||||
@@ -23,9 +24,8 @@ def install_environment(
|
||||
prefix: Prefix,
|
||||
version: str,
|
||||
additional_dependencies: Sequence[str],
|
||||
) -> None: # pragma: win32 no cover
|
||||
) -> None:
|
||||
helpers.assert_version_default('coursier', version)
|
||||
helpers.assert_no_additional_deps('coursier', additional_dependencies)
|
||||
|
||||
# Support both possible executable names (either "cs" or "coursier")
|
||||
executable = find_executable('cs') or find_executable('coursier')
|
||||
@@ -37,29 +37,40 @@ def install_environment(
|
||||
|
||||
envdir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
|
||||
channel = prefix.path('.pre-commit-channel')
|
||||
for app_descriptor in os.listdir(channel):
|
||||
_, app_file = os.path.split(app_descriptor)
|
||||
app, _ = os.path.splitext(app_file)
|
||||
helpers.run_setup_cmd(
|
||||
prefix,
|
||||
(
|
||||
executable,
|
||||
'install',
|
||||
'--default-channels=false',
|
||||
f'--channel={channel}',
|
||||
app,
|
||||
f'--dir={envdir}',
|
||||
),
|
||||
if os.path.isdir(channel):
|
||||
for app_descriptor in os.listdir(channel):
|
||||
_, app_file = os.path.split(app_descriptor)
|
||||
app, _ = os.path.splitext(app_file)
|
||||
helpers.run_setup_cmd(
|
||||
prefix,
|
||||
(
|
||||
executable,
|
||||
'install',
|
||||
'--default-channels=false',
|
||||
'--channel', channel,
|
||||
'--dir', envdir,
|
||||
app,
|
||||
),
|
||||
)
|
||||
elif not additional_dependencies:
|
||||
raise FatalError(
|
||||
'expected .pre-commit-channel dir or additional_dependencies',
|
||||
)
|
||||
|
||||
if additional_dependencies:
|
||||
install_cmd = (
|
||||
executable, 'install', '--dir', envdir, *additional_dependencies,
|
||||
)
|
||||
helpers.run_setup_cmd(prefix, install_cmd)
|
||||
|
||||
def get_env_patch(target_dir: str) -> PatchesT: # pragma: win32 no cover
|
||||
|
||||
def get_env_patch(target_dir: str) -> PatchesT:
|
||||
return (
|
||||
('PATH', (target_dir, os.pathsep, Var('PATH'))),
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager # pragma: win32 no cover
|
||||
@contextlib.contextmanager
|
||||
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)):
|
||||
|
||||
Reference in New Issue
Block a user