Skip to content

Commit 14cebbb

Browse files
committed
PR feedback fixes
1 parent c68ef12 commit 14cebbb

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

pre_commit/languages/swift.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from __future__ import unicode_literals
22

3+
import contextlib
34
import os
45

6+
from pre_commit.envcontext import envcontext
7+
from pre_commit.envcontext import Var
58
from pre_commit.languages import helpers
69
from pre_commit.util import clean_path_on_failure
710
from pre_commit.xargs import xargs
@@ -11,11 +14,34 @@
1114
BUILD_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+
1437
def 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

3460
def 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

Comments
 (0)