11from __future__ import unicode_literals
22
3+ import contextlib
34import os
45
6+ from pre_commit .envcontext import envcontext
7+ from pre_commit .envcontext import Var
58from pre_commit .languages import helpers
69from pre_commit .util import clean_path_on_failure
710from pre_commit .xargs import xargs
1114BUILD_CONFIG = 'release'
1215
1316
17+ def get_env_patch (venv ):
18+ bin_path = os .path .join (venv , BUILD_DIR , BUILD_CONFIG )
19+ patches = (
20+ ('PATH' , (
21+ bin_path , os .pathsep , Var ('PATH' ),
22+ )),
23+ )
24+ return patches
25+
26+
27+ @contextlib .contextmanager
28+ def in_env (repo_cmd_runner ):
29+ envdir = os .path .join (
30+ repo_cmd_runner .prefix_dir ,
31+ helpers .environment_dir (ENVIRONMENT_DIR , 'default' ),
32+ )
33+ with envcontext (get_env_patch (envdir )):
34+ yield
35+
36+
1437def install_environment (
1538 repo_cmd_runner ,
1639 version = 'default' ,
1740 additional_dependencies = (),
1841):
42+ assert version == 'default' , (
43+ 'Pre-commit does not support language_version for docker '
44+ )
1945 directory = repo_cmd_runner .path (helpers .environment_dir (
2046 ENVIRONMENT_DIR , 'default' ,
2147 ))
@@ -32,9 +58,5 @@ def install_environment(
3258
3359
3460def run_hook (repo_cmd_runner , hook , file_args ):
35- directory = repo_cmd_runner .path (helpers .environment_dir (
36- ENVIRONMENT_DIR , 'default' ,
37- ))
38- cmd = helpers .to_cmd (hook )
39- full_binary_path = os .path .join (directory , BUILD_DIR , BUILD_CONFIG , cmd [0 ])
40- return xargs ((full_binary_path ,) + cmd [1 :], file_args )
61+ with in_env (repo_cmd_runner ):
62+ return xargs (helpers .to_cmd (hook ), file_args )
0 commit comments