Skip to content

Commit 2ed0eaa

Browse files
authored
Merge pull request pre-commit#2277 from lorenzwalthert/always-binary
Avoid build-time dependencies by prioritising binary over source dependencies for R
2 parents e0e536b + 65755af commit 2ed0eaa

File tree

1 file changed

+20
-5
lines changed
  • pre_commit/languages

1 file changed

+20
-5
lines changed

pre_commit/languages/r.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def install_environment(
103103
shutil.copy(prefix.path('renv.lock'), env_dir)
104104
shutil.copytree(prefix.path('renv'), os.path.join(env_dir, 'renv'))
105105

106-
cmd_output_b(
107-
_rscript_exec(), '--vanilla', '-e',
108-
f"""\
106+
r_code_inst_environment = f"""\
109107
prefix_dir <- {prefix.prefix_dir!r}
110108
options(
111109
repos = c(CRAN = "https://cran.rstudio.com"),
@@ -132,19 +130,36 @@ def install_environment(
132130
if (is_package) {{
133131
renv::install(prefix_dir)
134132
}}
135-
""",
133+
"""
134+
135+
cmd_output_b(
136+
_rscript_exec(), '--vanilla', '-e',
137+
_inline_r_setup(r_code_inst_environment),
136138
cwd=env_dir,
137139
)
138140
if additional_dependencies:
141+
r_code_inst_add = 'renv::install(commandArgs(trailingOnly = TRUE))'
139142
with in_env(prefix, version):
140143
cmd_output_b(
141144
_rscript_exec(), *RSCRIPT_OPTS, '-e',
142-
'renv::install(commandArgs(trailingOnly = TRUE))',
145+
_inline_r_setup(r_code_inst_add),
143146
*additional_dependencies,
144147
cwd=env_dir,
145148
)
146149

147150

151+
def _inline_r_setup(code: str) -> str:
152+
"""
153+
Some behaviour of R cannot be configured via env variables, but can
154+
only be configured via R options once R has started. These are set here.
155+
"""
156+
with_option = f"""\
157+
options(install.packages.compile.from.source = "never")
158+
{code}
159+
"""
160+
return with_option
161+
162+
148163
def run_hook(
149164
hook: Hook,
150165
file_args: Sequence[str],

0 commit comments

Comments
 (0)