Skip to content

Commit 005cb86

Browse files
committed
Allow '.format('-like strings in arguments. Resolves pre-commit#314.
1 parent 97735a3 commit 005cb86

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

pre_commit/prefixed_command_runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
from pre_commit.util import cmd_output
88

99

10-
def _replace_cmd(cmd, **kwargs):
11-
return [part.format(**kwargs) for part in cmd]
12-
13-
1410
class PrefixedCommandRunner(object):
1511
"""A PrefixedCommandRunner allows you to run subprocess commands with
1612
comand substitution.
@@ -37,7 +33,9 @@ def _create_path_if_not_exists(self):
3733

3834
def run(self, cmd, **kwargs):
3935
self._create_path_if_not_exists()
40-
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
36+
replaced_cmd = [
37+
part.replace('{prefix}', self.prefix_dir) for part in cmd
38+
]
4139
return cmd_output(*replaced_cmd, __popen=self.__popen, **kwargs)
4240

4341
def path(self, *parts):

tests/prefixed_command_runner_test.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pytest
88

99
from pre_commit import five
10-
from pre_commit.prefixed_command_runner import _replace_cmd
1110
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
1211
from pre_commit.util import CalledProcessError
1312

@@ -59,19 +58,6 @@ def makedirs_mock():
5958
return mock.Mock(spec=os.makedirs)
6059

6160

62-
@pytest.mark.parametrize(('input', 'kwargs', 'expected_output'), (
63-
([], {}, []),
64-
(['foo'], {}, ['foo']),
65-
([], {'foo': 'bar'}, []),
66-
(['{foo}/baz'], {'foo': 'bar'}, ['bar/baz']),
67-
(['foo'], {'foo': 'bar'}, ['foo']),
68-
(['foo', '{bar}'], {'bar': 'baz'}, ['foo', 'baz']),
69-
))
70-
def test_replace_cmd(input, kwargs, expected_output):
71-
ret = _replace_cmd(input, **kwargs)
72-
assert ret == expected_output
73-
74-
7561
@pytest.mark.parametrize(('input', 'expected_prefix'), (
7662
norm_slash(('.', './')),
7763
norm_slash(('foo', 'foo/')),

tests/repository_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ def test_run_hook_with_spaced_args(tempdir_factory, store):
178178
)
179179

180180

181+
@pytest.mark.integration
182+
def test_run_hook_with_curly_braced_arguments(tempdir_factory, store):
183+
_test_hook_repo(
184+
tempdir_factory, store, 'arg_per_line_hooks_repo',
185+
'arg-per-line',
186+
[],
187+
b"arg: hi {1}\narg: I'm {a} problem\n",
188+
config_kwargs={
189+
'hooks': [{
190+
'id': 'arg-per-line',
191+
'args': ['hi {1}', "I'm {a} problem"],
192+
}]
193+
},
194+
)
195+
196+
181197
@xfailif_no_pcre_support
182198
@pytest.mark.integration
183199
def test_pcre_hook_no_match(tempdir_factory, store):

0 commit comments

Comments
 (0)