Skip to content

Commit 420902f

Browse files
committed
fix r local hooks
`language: r` acts more like `language: script` so we have to *not* append the prefix when run with `repo: local`
1 parent 6eacdd4 commit 420902f

File tree

12 files changed

+51
-6
lines changed

12 files changed

+51
-6
lines changed

pre_commit/commands/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def _run_single_hook(
195195
hook.entry,
196196
hook.args,
197197
filenames,
198+
is_local=hook.src == 'local',
198199
require_serial=hook.require_serial,
199200
color=use_color,
200201
)

pre_commit/languages/all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def run_hook(
6666
args: Sequence[str],
6767
file_args: Sequence[str],
6868
*,
69+
is_local: bool,
6970
require_serial: bool,
7071
color: bool,
7172
) -> tuple[int, bytes]:

pre_commit/languages/docker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def run_hook(
127127
args: Sequence[str],
128128
file_args: Sequence[str],
129129
*,
130+
is_local: bool,
130131
require_serial: bool,
131132
color: bool,
132133
) -> tuple[int, bytes]: # pragma: win32 no cover

pre_commit/languages/docker_image.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def run_hook(
1919
args: Sequence[str],
2020
file_args: Sequence[str],
2121
*,
22+
is_local: bool,
2223
require_serial: bool,
2324
color: bool,
2425
) -> tuple[int, bytes]: # pragma: win32 no cover

pre_commit/languages/fail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def run_hook(
1818
args: Sequence[str],
1919
file_args: Sequence[str],
2020
*,
21+
is_local: bool,
2122
require_serial: bool,
2223
color: bool,
2324
) -> tuple[int, bytes]:

pre_commit/languages/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def basic_run_hook(
146146
args: Sequence[str],
147147
file_args: Sequence[str],
148148
*,
149+
is_local: bool,
149150
require_serial: bool,
150151
color: bool,
151152
) -> tuple[int, bytes]:

pre_commit/languages/pygrep.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def run_hook(
9393
args: Sequence[str],
9494
file_args: Sequence[str],
9595
*,
96+
is_local: bool,
9697
require_serial: bool,
9798
color: bool,
9899
) -> tuple[int, bytes]:

pre_commit/languages/r.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
3535
yield
3636

3737

38-
def _prefix_if_file_entry(entry: list[str], prefix: Prefix) -> Sequence[str]:
39-
if entry[1] == '-e':
38+
def _prefix_if_file_entry(
39+
entry: list[str],
40+
prefix: Prefix,
41+
*,
42+
is_local: bool,
43+
) -> Sequence[str]:
44+
if entry[1] == '-e' or is_local:
4045
return entry[1:]
4146
else:
4247
return (prefix.path(entry[1]),)
@@ -73,11 +78,14 @@ def _cmd_from_hook(
7378
prefix: Prefix,
7479
entry: str,
7580
args: Sequence[str],
81+
*,
82+
is_local: bool,
7683
) -> tuple[str, ...]:
7784
cmd = shlex.split(entry)
7885
_entry_validate(cmd)
7986

80-
return (cmd[0], *RSCRIPT_OPTS, *_prefix_if_file_entry(cmd, prefix), *args)
87+
cmd_part = _prefix_if_file_entry(cmd, prefix, is_local=is_local)
88+
return (cmd[0], *RSCRIPT_OPTS, *cmd_part, *args)
8189

8290

8391
def install_environment(
@@ -153,10 +161,11 @@ def run_hook(
153161
args: Sequence[str],
154162
file_args: Sequence[str],
155163
*,
164+
is_local: bool,
156165
require_serial: bool,
157166
color: bool,
158167
) -> tuple[int, bytes]:
159-
cmd = _cmd_from_hook(prefix, entry, args)
168+
cmd = _cmd_from_hook(prefix, entry, args, is_local=is_local)
160169
return helpers.run_xargs(
161170
cmd,
162171
file_args,

pre_commit/languages/script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def run_hook(
1818
args: Sequence[str],
1919
file_args: Sequence[str],
2020
*,
21+
is_local: bool,
2122
require_serial: bool,
2223
color: bool,
2324
) -> tuple[int, bytes]:

testing/language_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def run_language(
1616
file_args: Sequence[str] = (),
1717
version: str = C.DEFAULT,
1818
deps: Sequence[str] = (),
19+
is_local: bool = False,
1920
) -> tuple[int, bytes]:
2021
prefix = Prefix(str(path))
2122

@@ -26,6 +27,7 @@ def run_language(
2627
exe,
2728
args,
2829
file_args,
30+
is_local=is_local,
2931
require_serial=True,
3032
color=False,
3133
)

0 commit comments

Comments
 (0)