Skip to content

Commit 6055af8

Browse files
committed
Make shlex behaviour of entry more consistent
1 parent 0de174f commit 6055af8

7 files changed

Lines changed: 19 additions & 17 deletions

File tree

pre_commit/languages/docker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import hashlib
55
import os
6-
import shlex
76

87
from pre_commit import five
98
from pre_commit.languages import helpers
@@ -83,8 +82,8 @@ def run_hook(repo_cmd_runner, hook, file_args):
8382
# automated cleanup of docker images.
8483
build_docker_image(repo_cmd_runner, pull=False)
8584

86-
entry_parts = shlex.split(hook['entry'])
87-
entry_executable, entry_args = entry_parts[0], entry_parts[1:]
85+
hook_cmd = helpers.to_cmd(hook)
86+
entry_executable, cmd_rest = hook_cmd[0], hook_cmd[1:]
8887

8988
cmd = (
9089
'docker', 'run',
@@ -94,6 +93,6 @@ def run_hook(repo_cmd_runner, hook, file_args):
9493
'--workdir', '/src',
9594
'--entrypoint', entry_executable,
9695
docker_tag(repo_cmd_runner)
97-
)
96+
) + cmd_rest
9897

99-
return xargs(cmd + tuple(entry_args) + tuple(hook['args']), file_args)
98+
return xargs(cmd, file_args)

pre_commit/languages/helpers.py

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

3+
import shlex
4+
35
from pre_commit.util import cmd_output
46

57

@@ -12,3 +14,7 @@ def environment_dir(ENVIRONMENT_DIR, language_version):
1214
return None
1315
else:
1416
return '{}-{}'.format(ENVIRONMENT_DIR, language_version)
17+
18+
19+
def to_cmd(hook):
20+
return tuple(shlex.split(hook['entry'])) + tuple(hook['args'])

pre_commit/languages/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ def install_environment(
6464

6565
def run_hook(repo_cmd_runner, hook, file_args):
6666
with in_env(repo_cmd_runner, hook['language_version']):
67-
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
67+
return xargs(helpers.to_cmd(hook), file_args)

pre_commit/languages/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ def install_environment(
8383

8484
def run_hook(repo_cmd_runner, hook, file_args):
8585
with in_env(repo_cmd_runner, hook['language_version']):
86-
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
86+
return xargs(helpers.to_cmd(hook), file_args)

pre_commit/languages/ruby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ def install_environment(
128128

129129
def run_hook(repo_cmd_runner, hook, file_args):
130130
with in_env(repo_cmd_runner, hook['language_version']):
131-
return xargs((hook['entry'],) + tuple(hook['args']), file_args)
131+
return xargs(helpers.to_cmd(hook), file_args)

pre_commit/languages/script.py

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

3+
from pre_commit.languages import helpers
34
from pre_commit.xargs import xargs
45

56

@@ -16,7 +17,6 @@ def install_environment(
1617

1718

1819
def run_hook(repo_cmd_runner, hook, file_args):
19-
return xargs(
20-
(repo_cmd_runner.prefix_dir + hook['entry'],) + tuple(hook['args']),
21-
file_args,
22-
)
20+
cmd = helpers.to_cmd(hook)
21+
cmd = (repo_cmd_runner.prefix_dir + cmd[0],) + cmd[1:]
22+
return xargs(cmd, file_args)

pre_commit/languages/system.py

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

3-
import shlex
4-
3+
from pre_commit.languages import helpers
54
from pre_commit.xargs import xargs
65

76

@@ -18,6 +17,4 @@ def install_environment(
1817

1918

2019
def run_hook(repo_cmd_runner, hook, file_args):
21-
return xargs(
22-
tuple(shlex.split(hook['entry'])) + tuple(hook['args']), file_args,
23-
)
20+
return xargs(helpers.to_cmd(hook), file_args)

0 commit comments

Comments
 (0)