Skip to content

Commit

Permalink
Merge pull request #2277 from lorenzwalthert/always-binary
Browse files Browse the repository at this point in the history
Avoid build-time dependencies by prioritising binary over source dependencies for R
  • Loading branch information
asottile committed Mar 5, 2022
2 parents e0e536b + 65755af commit 2ed0eaa
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pre_commit/languages/r.py
Expand Up @@ -103,9 +103,7 @@ def install_environment(
shutil.copy(prefix.path('renv.lock'), env_dir)
shutil.copytree(prefix.path('renv'), os.path.join(env_dir, 'renv'))

cmd_output_b(
_rscript_exec(), '--vanilla', '-e',
f"""\
r_code_inst_environment = f"""\
prefix_dir <- {prefix.prefix_dir!r}
options(
repos = c(CRAN = "https://cran.rstudio.com"),
Expand All @@ -132,19 +130,36 @@ def install_environment(
if (is_package) {{
renv::install(prefix_dir)
}}
""",
"""

cmd_output_b(
_rscript_exec(), '--vanilla', '-e',
_inline_r_setup(r_code_inst_environment),
cwd=env_dir,
)
if additional_dependencies:
r_code_inst_add = 'renv::install(commandArgs(trailingOnly = TRUE))'
with in_env(prefix, version):
cmd_output_b(
_rscript_exec(), *RSCRIPT_OPTS, '-e',
'renv::install(commandArgs(trailingOnly = TRUE))',
_inline_r_setup(r_code_inst_add),
*additional_dependencies,
cwd=env_dir,
)


def _inline_r_setup(code: str) -> str:
"""
Some behaviour of R cannot be configured via env variables, but can
only be configured via R options once R has started. These are set here.
"""
with_option = f"""\
options(install.packages.compile.from.source = "never")
{code}
"""
return with_option


def run_hook(
hook: Hook,
file_args: Sequence[str],
Expand Down

0 comments on commit 2ed0eaa

Please sign in to comment.