mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1831 from lorenzwalthert/renv-fix
Fix r hooks when hook repo is a package
This commit is contained in:
commit
478efe55c6
1 changed files with 9 additions and 11 deletions
|
|
@ -88,13 +88,11 @@ def install_environment(
|
||||||
env_dir = _get_env_dir(prefix, version)
|
env_dir = _get_env_dir(prefix, version)
|
||||||
with clean_path_on_failure(env_dir):
|
with clean_path_on_failure(env_dir):
|
||||||
os.makedirs(env_dir, exist_ok=True)
|
os.makedirs(env_dir, exist_ok=True)
|
||||||
path_desc_source = prefix.path('DESCRIPTION')
|
|
||||||
if os.path.exists(path_desc_source):
|
|
||||||
shutil.copy(path_desc_source, env_dir)
|
|
||||||
shutil.copy(prefix.path('renv.lock'), env_dir)
|
shutil.copy(prefix.path('renv.lock'), env_dir)
|
||||||
cmd_output_b(
|
cmd_output_b(
|
||||||
'Rscript', '--vanilla', '-e',
|
'Rscript', '--vanilla', '-e',
|
||||||
"""\
|
f"""\
|
||||||
|
prefix_dir <- {prefix.prefix_dir!r}
|
||||||
missing_pkgs <- setdiff(
|
missing_pkgs <- setdiff(
|
||||||
"renv", unname(installed.packages()[, "Package"])
|
"renv", unname(installed.packages()[, "Package"])
|
||||||
)
|
)
|
||||||
|
|
@ -109,15 +107,15 @@ def install_environment(
|
||||||
'renv::activate("', file.path(getwd()), '"); '
|
'renv::activate("', file.path(getwd()), '"); '
|
||||||
)
|
)
|
||||||
writeLines(activate_statement, 'activate.R')
|
writeLines(activate_statement, 'activate.R')
|
||||||
is_package <- tryCatch(
|
is_package <- tryCatch({{
|
||||||
suppressWarnings(
|
content_desc <- read.dcf(file.path(prefix_dir, 'DESCRIPTION'))
|
||||||
unname(read.dcf('DESCRIPTION')[,'Type'] == "Package")
|
suppressWarnings(unname(content_desc[,'Type']) == "Package")
|
||||||
),
|
}},
|
||||||
error = function(...) FALSE
|
error = function(...) FALSE
|
||||||
)
|
)
|
||||||
if (is_package) {
|
if (is_package) {{
|
||||||
renv::install(normalizePath('.'))
|
renv::install(prefix_dir)
|
||||||
}
|
}}
|
||||||
""",
|
""",
|
||||||
cwd=env_dir,
|
cwd=env_dir,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue