Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pre_commit/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def _run_single_hook(
hook.entry,
hook.args,
filenames,
is_local=hook.src == 'local',
require_serial=hook.require_serial,
color=use_color,
)
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]: # pragma: win32 no cover
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]: # pragma: win32 no cover
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def basic_run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/pygrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
Expand Down
17 changes: 13 additions & 4 deletions pre_commit/languages/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
yield


def _prefix_if_file_entry(entry: list[str], prefix: Prefix) -> Sequence[str]:
if entry[1] == '-e':
def _prefix_if_file_entry(
entry: list[str],
prefix: Prefix,
*,
is_local: bool,
) -> Sequence[str]:
if entry[1] == '-e' or is_local:
return entry[1:]
else:
return (prefix.path(entry[1]),)
Expand Down Expand Up @@ -73,11 +78,14 @@ def _cmd_from_hook(
prefix: Prefix,
entry: str,
args: Sequence[str],
*,
is_local: bool,
) -> tuple[str, ...]:
cmd = shlex.split(entry)
_entry_validate(cmd)

return (cmd[0], *RSCRIPT_OPTS, *_prefix_if_file_entry(cmd, prefix), *args)
cmd_part = _prefix_if_file_entry(cmd, prefix, is_local=is_local)
return (cmd[0], *RSCRIPT_OPTS, *cmd_part, *args)


def install_environment(
Expand Down Expand Up @@ -153,10 +161,11 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
cmd = _cmd_from_hook(prefix, entry, args)
cmd = _cmd_from_hook(prefix, entry, args, is_local=is_local)
return helpers.run_xargs(
cmd,
file_args,
Expand Down
1 change: 1 addition & 0 deletions pre_commit/languages/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def run_hook(
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]:
Expand Down
2 changes: 2 additions & 0 deletions testing/language_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def run_language(
file_args: Sequence[str] = (),
version: str = C.DEFAULT,
deps: Sequence[str] = (),
is_local: bool = False,
) -> tuple[int, bytes]:
prefix = Prefix(str(path))

Expand All @@ -26,6 +27,7 @@ def run_language(
exe,
args,
file_args,
is_local=is_local,
require_serial=True,
color=False,
)
Expand Down
29 changes: 27 additions & 2 deletions tests/languages/r_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@


def test_r_parsing_file_no_opts_no_args(tmp_path):
cmd = r._cmd_from_hook(Prefix(str(tmp_path)), 'Rscript some-script.R', ())
cmd = r._cmd_from_hook(
Prefix(str(tmp_path)),
'Rscript some-script.R',
(),
is_local=False,
)
assert cmd == (
'Rscript',
'--no-save', '--no-restore', '--no-site-file', '--no-environ',
Expand All @@ -38,6 +43,7 @@ def test_r_parsing_file_no_opts_args(tmp_path):
Prefix(str(tmp_path)),
'Rscript some-script.R',
('--no-cache',),
is_local=False,
)
assert cmd == (
'Rscript',
Expand All @@ -48,14 +54,33 @@ def test_r_parsing_file_no_opts_args(tmp_path):


def test_r_parsing_expr_no_opts_no_args1(tmp_path):
cmd = r._cmd_from_hook(Prefix(str(tmp_path)), "Rscript -e '1+1'", ())
cmd = r._cmd_from_hook(
Prefix(str(tmp_path)),
"Rscript -e '1+1'",
(),
is_local=False,
)
assert cmd == (
'Rscript',
'--no-save', '--no-restore', '--no-site-file', '--no-environ',
'-e', '1+1',
)


def test_r_parsing_local_hook_path_is_not_expanded(tmp_path):
cmd = r._cmd_from_hook(
Prefix(str(tmp_path)),
'Rscript path/to/thing.R',
(),
is_local=True,
)
assert cmd == (
'Rscript',
'--no-save', '--no-restore', '--no-site-file', '--no-environ',
'path/to/thing.R',
)


def test_r_parsing_expr_no_opts_no_args2():
with pytest.raises(ValueError) as excinfo:
r._entry_validate(['Rscript', '-e', '1+1', '-e', 'letters'])
Expand Down
1 change: 1 addition & 0 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _hook_run(hook, filenames, color):
hook.entry,
hook.args,
filenames,
is_local=hook.src == 'local',
require_serial=hook.require_serial,
color=color,
)
Expand Down