|
8 | 8 |
|
9 | 9 | from pre_commit.envcontext import envcontext |
10 | 10 | from pre_commit.envcontext import PatchesT |
| 11 | +from pre_commit.envcontext import UNSET |
11 | 12 | from pre_commit.hook import Hook |
12 | 13 | from pre_commit.languages import helpers |
13 | 14 | from pre_commit.prefix import Prefix |
|
23 | 24 | def get_env_patch(venv: str) -> PatchesT: |
24 | 25 | return ( |
25 | 26 | ('R_PROFILE_USER', os.path.join(venv, 'activate.R')), |
| 27 | + ('RENV_PROJECT', UNSET), |
26 | 28 | ) |
27 | 29 |
|
28 | 30 |
|
@@ -55,6 +57,10 @@ def _prefix_if_non_local_file_entry( |
55 | 57 | return (path,) |
56 | 58 |
|
57 | 59 |
|
| 60 | +def _rscript_exec() -> str: |
| 61 | + return os.path.join(os.getenv('R_HOME', ''), 'Rscript') |
| 62 | + |
| 63 | + |
58 | 64 | def _entry_validate(entry: Sequence[str]) -> None: |
59 | 65 | """ |
60 | 66 | Allowed entries: |
@@ -95,8 +101,9 @@ def install_environment( |
95 | 101 | os.makedirs(env_dir, exist_ok=True) |
96 | 102 | shutil.copy(prefix.path('renv.lock'), env_dir) |
97 | 103 | shutil.copytree(prefix.path('renv'), os.path.join(env_dir, 'renv')) |
| 104 | + |
98 | 105 | cmd_output_b( |
99 | | - 'Rscript', '--vanilla', '-e', |
| 106 | + _rscript_exec(), '--vanilla', '-e', |
100 | 107 | f"""\ |
101 | 108 | prefix_dir <- {prefix.prefix_dir!r} |
102 | 109 | options( |
@@ -130,7 +137,7 @@ def install_environment( |
130 | 137 | if additional_dependencies: |
131 | 138 | with in_env(prefix, version): |
132 | 139 | cmd_output_b( |
133 | | - 'Rscript', *RSCRIPT_OPTS, '-e', |
| 140 | + _rscript_exec(), *RSCRIPT_OPTS, '-e', |
134 | 141 | 'renv::install(commandArgs(trailingOnly = TRUE))', |
135 | 142 | *additional_dependencies, |
136 | 143 | cwd=env_dir, |
|
0 commit comments