Skip to content

Commit

Permalink
renv 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuidoMaggio committed Aug 26, 2023
1 parent 6b853be commit efebcb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 52 deletions.
9 changes: 2 additions & 7 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,8 @@
},
"renv": {
"Package": "renv",
"Version": "1.0.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "4b22ac016fe54028b88d0c68badbd061"
"Version": "1.0.0",
"Source": "Repository"
},
"rlang": {
"Package": "rlang",
Expand Down
70 changes: 25 additions & 45 deletions renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@
local({

# the requested version of renv
version <- "1.0.2"
version <- "1.0.0"
attr(version, "sha") <- NULL

# the project directory
project <- getwd()

# use start-up diagnostics if enabled
diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE")
if (diagnostics) {
start <- Sys.time()
profile <- tempfile("renv-startup-", fileext = ".Rprof")
utils::Rprof(profile)
on.exit({
utils::Rprof(NULL)
elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L)
writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed)))
writeLines(sprintf("- Profile: %s", profile))
print(utils::summaryRprof(profile))
}, add = TRUE)
}

# figure out whether the autoloader is enabled
enabled <- local({

Expand Down Expand Up @@ -519,7 +504,7 @@ local({

# open the bundle for reading
# We use gzcon for everything because (from ?gzcon)
# > Reading from a connection which does not supply a 'gzip' magic
# > Reading from a connection which does not supply a gzip magic
# > header is equivalent to reading from the original connection
conn <- gzcon(file(bundle, open = "rb", raw = TRUE))
on.exit(close(conn))
Expand Down Expand Up @@ -782,12 +767,10 @@ local({
renv_bootstrap_validate_version <- function(version, description = NULL) {

# resolve description file
#
# avoid passing lib.loc to `packageDescription()` below, since R will
# use the loaded version of the package by default anyhow. note that
# this function should only be called after 'renv' is loaded
# https://github.com/rstudio/renv/issues/1625
description <- description %||% packageDescription("renv")
description <- description %||% {
path <- getNamespaceInfo("renv", "path")
packageDescription("renv", lib.loc = dirname(path))
}

# check whether requested version 'version' matches loaded version of renv
sha <- attr(version, "sha", exact = TRUE)
Expand Down Expand Up @@ -858,7 +841,7 @@ local({
hooks <- getHook("renv::autoload")
for (hook in hooks)
if (is.function(hook))
tryCatch(hook(), error = warnify)
tryCatch(hook(), error = warning)

# load the project
renv::load(project)
Expand Down Expand Up @@ -999,15 +982,10 @@ local({

}

renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) {
renv_bootstrap_version_friendly <- function(version, sha = NULL) {
sha <- sha %||% attr(version, "sha", exact = TRUE)
parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L)))
paste(parts, collapse = "")
}

renv_bootstrap_exec <- function(project, libpath, version) {
if (!renv_bootstrap_load(project, libpath, version))
renv_bootstrap_run(version, libpath)
parts <- c(version, sprintf("[sha: %s]", substring(sha, 1L, 7L)))
paste(parts, collapse = " ")
}

renv_bootstrap_run <- function(version, libpath) {
Expand Down Expand Up @@ -1039,14 +1017,6 @@ local({
commandArgs()[[1]] == "RStudio"
}

# Used to work around buglet in RStudio if hook uses readline
renv_bootstrap_flush_console <- function() {
tryCatch({
tools <- as.environment("tools:rstudio")
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
}, error = function(cnd) {})
}

renv_json_read <- function(file = NULL, text = NULL) {

jlerr <- NULL
Expand Down Expand Up @@ -1185,15 +1155,25 @@ local({
# construct full libpath
libpath <- file.path(root, prefix)

# attempt to load
if (renv_bootstrap_load(project, libpath, version))
return(TRUE)

if (renv_bootstrap_in_rstudio()) {
# RStudio only updates console once .Rprofile is finished, so
# instead run code on sessionInit
setHook("rstudio.sessionInit", function(...) {
renv_bootstrap_exec(project, libpath, version)
renv_bootstrap_flush_console()
renv_bootstrap_run(version, libpath)

# Work around buglet in RStudio if hook uses readline
tryCatch(
{
tools <- as.environment("tools:rstudio")
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
},
error = function(cnd) {}
)
})
} else {
renv_bootstrap_exec(project, libpath, version)
renv_bootstrap_run(version, libpath)
}

invisible()
Expand Down

0 comments on commit efebcb3

Please sign in to comment.