mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
PR feedback fixes
This commit is contained in:
parent
c68ef12484
commit
14cebbb25f
1 changed files with 28 additions and 6 deletions
|
|
@ -1,7 +1,10 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from pre_commit.envcontext import envcontext
|
||||||
|
from pre_commit.envcontext import Var
|
||||||
from pre_commit.languages import helpers
|
from pre_commit.languages import helpers
|
||||||
from pre_commit.util import clean_path_on_failure
|
from pre_commit.util import clean_path_on_failure
|
||||||
from pre_commit.xargs import xargs
|
from pre_commit.xargs import xargs
|
||||||
|
|
@ -11,11 +14,34 @@ BUILD_DIR = '.build'
|
||||||
BUILD_CONFIG = 'release'
|
BUILD_CONFIG = 'release'
|
||||||
|
|
||||||
|
|
||||||
|
def get_env_patch(venv):
|
||||||
|
bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)
|
||||||
|
patches = (
|
||||||
|
('PATH', (
|
||||||
|
bin_path, os.pathsep, Var('PATH'),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
return patches
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def in_env(repo_cmd_runner):
|
||||||
|
envdir = os.path.join(
|
||||||
|
repo_cmd_runner.prefix_dir,
|
||||||
|
helpers.environment_dir(ENVIRONMENT_DIR, 'default'),
|
||||||
|
)
|
||||||
|
with envcontext(get_env_patch(envdir)):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
def install_environment(
|
def install_environment(
|
||||||
repo_cmd_runner,
|
repo_cmd_runner,
|
||||||
version='default',
|
version='default',
|
||||||
additional_dependencies=(),
|
additional_dependencies=(),
|
||||||
):
|
):
|
||||||
|
assert version == 'default', (
|
||||||
|
'Pre-commit does not support language_version for docker '
|
||||||
|
)
|
||||||
directory = repo_cmd_runner.path(helpers.environment_dir(
|
directory = repo_cmd_runner.path(helpers.environment_dir(
|
||||||
ENVIRONMENT_DIR, 'default',
|
ENVIRONMENT_DIR, 'default',
|
||||||
))
|
))
|
||||||
|
|
@ -32,9 +58,5 @@ def install_environment(
|
||||||
|
|
||||||
|
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
directory = repo_cmd_runner.path(helpers.environment_dir(
|
with in_env(repo_cmd_runner):
|
||||||
ENVIRONMENT_DIR, 'default',
|
return xargs(helpers.to_cmd(hook), file_args)
|
||||||
))
|
|
||||||
cmd = helpers.to_cmd(hook)
|
|
||||||
full_binary_path = os.path.join(directory, BUILD_DIR, BUILD_CONFIG, cmd[0])
|
|
||||||
return xargs((full_binary_path,) + cmd[1:], file_args)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue