Skip to content

Commit cf57e35

Browse files
lorenzwalthertasottile
authored andcommitted
install package from prefix_dir, not env_dir (which yields empty pkg)
1 parent 54c49ab commit cf57e35

File tree

1 file changed

+9
-11
lines changed
  • pre_commit/languages

1 file changed

+9
-11
lines changed

pre_commit/languages/r.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ def install_environment(
8888
env_dir = _get_env_dir(prefix, version)
8989
with clean_path_on_failure(env_dir):
9090
os.makedirs(env_dir, exist_ok=True)
91-
path_desc_source = prefix.path('DESCRIPTION')
92-
if os.path.exists(path_desc_source):
93-
shutil.copy(path_desc_source, env_dir)
9491
shutil.copy(prefix.path('renv.lock'), env_dir)
9592
cmd_output_b(
9693
'Rscript', '--vanilla', '-e',
97-
"""\
94+
f"""\
95+
prefix_dir <- {prefix.prefix_dir!r}
9896
missing_pkgs <- setdiff(
9997
"renv", unname(installed.packages()[, "Package"])
10098
)
@@ -109,15 +107,15 @@ def install_environment(
109107
'renv::activate("', file.path(getwd()), '"); '
110108
)
111109
writeLines(activate_statement, 'activate.R')
112-
is_package <- tryCatch(
113-
suppressWarnings(
114-
unname(read.dcf('DESCRIPTION')[,'Type'] == "Package")
115-
),
110+
is_package <- tryCatch({{
111+
content_desc <- read.dcf(file.path(prefix_dir, 'DESCRIPTION'))
112+
suppressWarnings(unname(content_desc[,'Type']) == "Package")
113+
}},
116114
error = function(...) FALSE
117115
)
118-
if (is_package) {
119-
renv::install(normalizePath('.'))
120-
}
116+
if (is_package) {{
117+
renv::install(prefix_dir)
118+
}}
121119
""",
122120
cwd=env_dir,
123121
)

0 commit comments

Comments
 (0)