Skip to content

Commit

Permalink
defer creation of .renvignore
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed May 22, 2024
1 parent c462750 commit 538ae47
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
29 changes: 0 additions & 29 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,6 @@ renv_cache_version_previous <- function() {
paste("v", number - 1L, sep = "")
}

renv_cache_init <- function() {

if (testing() || checking())
return()

root <- renv_paths_root()
if (!file.exists(root))
return()

# try to create cache directories
caches <- renv_paths_cache()
status <- catch(ensure_directory(caches))
if (inherits(status, "error"))
return()

# if the cache appears to be within the project directory,
# then drop a '.renvignore' file within so it's not scanned
#
# https://github.com/rstudio/renv/issues/1655
for (cache in caches) {
if (renv_path_within(cache, getwd())) {
ignorefile <- file.path(cache, ".renvignore")
if (!file.exists(ignorefile))
writeLines("*", con = ignorefile)
}
}

}

# given a record, find a compatible version of that package in the cache,
# using a computed hash if available; if no hash is available, then try
# to match based on the package name + version
Expand Down
1 change: 0 additions & 1 deletion R/consent.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ consent <- function(provided = FALSE) {
# cache the user response
options(renv.consent = TRUE)
ensure_directory(root)
renv_cache_init()
writef("- %s has been created.", renv_path_pretty(root))

invisible(TRUE)
Expand Down
18 changes: 18 additions & 0 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,26 @@ renv_load_switch <- function(project) {

}

renv_load_cache_renvignore <- function(project) {

if (testing() || checking())
return()

if (!renv_cache_config_enabled(project))
return()

caches <- renv_paths_cache()
ensure_directory(caches)
renv_renvignore_create(
paths = caches,
create = TRUE
)

}

renv_load_cache <- function(project) {

renv_load_cache_renvignore(project)
if (!interactive())
return(FALSE)

Expand Down
14 changes: 14 additions & 0 deletions R/renvignore.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,17 @@ renv_renvignore_pattern_extra <- function(key, root) {
patterns[[key]]

}

renv_renvignore_create <- function(paths,
create = FALSE,
contents = "*")
{
for (path in paths) {
if (file.exists(path)) {
ignorefile <- file.path(path, ".renvignore")
if (!file.exists(ignorefile))
writeLines(contents, con = ignorefile)
}
}
}

3 changes: 3 additions & 0 deletions R/restore.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ restore <- function(project = NULL,
libpaths <- renv_libpaths_resolve(library)
lockfile <- lockfile %||% renv_lockfile_load(project = project, strict = TRUE)

# set up .renvignore defensively
renv_load_cache_renvignore(project = project)

# check and ask user if they need to activate first
renv_activate_prompt("restore", library, prompt, project)

Expand Down
3 changes: 3 additions & 0 deletions R/snapshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ snapshot <- function(project = NULL,
repos <- renv_repos_validate(repos)
renv_scope_options(repos = repos)

# set up .renvignore defensively
renv_load_cache_renvignore(project = project)

if (!is.null(lockfile))
renv_activate_prompt("snapshot", library, prompt, project)

Expand Down
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ renv_zzz_load <- function() {
renv_envvars_init()
renv_log_init()
renv_methods_init()
renv_cache_init()
renv_libpaths_init()
renv_patch_init()
renv_sandbox_init()
Expand Down

0 comments on commit 538ae47

Please sign in to comment.