Skip to content

Commit

Permalink
Merge pull request #597 from lorenzwalthert/hook-dependencies-update
Browse files Browse the repository at this point in the history
Hook dependencies update
  • Loading branch information
lorenzwalthert authored Oct 15, 2024
2 parents 208dced + c0b1350 commit 9525a2e
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 28 deletions.
37 changes: 18 additions & 19 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Repositories": [
{
"Name": "RSPM",
"URL": "https://packagemanager.posit.co/cran/2024-09-12"
"URL": "https://packagemanager.posit.co/cran/2024-10-11"
}
]
},
Expand Down Expand Up @@ -137,10 +137,10 @@
},
"commonmark": {
"Package": "commonmark",
"Version": "1.9.1",
"Version": "1.9.2",
"Source": "Repository",
"Repository": "RSPM",
"Hash": "5d8225445acb167abf7797de48b2ee3c"
"Hash": "14eb0596f987c71535d07c3aff814742"
},
"cpp11": {
"Package": "cpp11",
Expand Down Expand Up @@ -214,14 +214,13 @@
},
"evaluate": {
"Package": "evaluate",
"Version": "0.24.0",
"Version": "1.0.1",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"methods"
"R"
],
"Hash": "a1066cbc05caee9a4bf6d90f194ff4da"
"Hash": "3fd29944b231036ad67c3edb32e02201"
},
"fs": {
"Package": "fs",
Expand All @@ -236,14 +235,14 @@
},
"glue": {
"Package": "glue",
"Version": "1.7.0",
"Version": "1.8.0",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"methods"
],
"Hash": "e0b3a53876554bd45879e596cdb10a52"
"Hash": "5899f1eaa825580172bb56c08266f37c"
},
"here": {
"Package": "here",
Expand All @@ -268,15 +267,15 @@
},
"hunspell": {
"Package": "hunspell",
"Version": "3.0.4",
"Version": "3.0.5",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"Rcpp",
"digest"
],
"Hash": "f543163714aba1ff9e8cfe76d8d15381"
"Hash": "e58f80d4c5b4f0bab1456956d6ca6aad"
},
"knitr": {
"Package": "knitr",
Expand Down Expand Up @@ -400,14 +399,14 @@
},
"ps": {
"Package": "ps",
"Version": "1.7.7",
"Version": "1.8.0",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"utils"
],
"Hash": "878b467580097e9c383acbb16adab57a"
"Hash": "4b9c8485b0c7eecdf0a9ba5132a45576"
},
"purrr": {
"Package": "purrr",
Expand Down Expand Up @@ -440,13 +439,13 @@
},
"renv": {
"Package": "renv",
"Version": "1.0.7",
"Version": "1.0.10",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"utils"
],
"Hash": "397b7b2a265bc5a7a06852524dabae20"
"Hash": "d0387d5687ec933dd7587efd4cfa2d85"
},
"rex": {
"Package": "rex",
Expand Down Expand Up @@ -507,7 +506,7 @@
},
"spelling": {
"Package": "spelling",
"Version": "2.3.0",
"Version": "2.3.1",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
Expand All @@ -516,7 +515,7 @@
"knitr",
"xml2"
],
"Hash": "632e9e83d3dc774d361b9415b15642bb"
"Hash": "e167300a047e21d28c754b00cbfc55ef"
},
"stringi": {
"Package": "stringi",
Expand Down Expand Up @@ -595,7 +594,7 @@
},
"xfun": {
"Package": "xfun",
"Version": "0.47",
"Version": "0.48",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
Expand All @@ -604,7 +603,7 @@
"stats",
"tools"
],
"Hash": "36ab21660e2d095fef0d83f689e0477c"
"Hash": "89e455b87c84e227eb7f60a1b4e5fe1f"
},
"xml2": {
"Package": "xml2",
Expand Down
105 changes: 96 additions & 9 deletions renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local({

# the requested version of renv
version <- "1.0.7"
version <- "1.0.10"
attr(version, "sha") <- NULL

# the project directory
Expand Down Expand Up @@ -98,6 +98,66 @@ local({
unloadNamespace("renv")

# load bootstrap tools
ansify <- function(text) {
if (renv_ansify_enabled())
renv_ansify_enhanced(text)
else
renv_ansify_default(text)
}

renv_ansify_enabled <- function() {

override <- Sys.getenv("RENV_ANSIFY_ENABLED", unset = NA)
if (!is.na(override))
return(as.logical(override))

pane <- Sys.getenv("RSTUDIO_CHILD_PROCESS_PANE", unset = NA)
if (identical(pane, "build"))
return(FALSE)

testthat <- Sys.getenv("TESTTHAT", unset = "false")
if (tolower(testthat) %in% "true")
return(FALSE)

iderun <- Sys.getenv("R_CLI_HAS_HYPERLINK_IDE_RUN", unset = "false")
if (tolower(iderun) %in% "false")
return(FALSE)

TRUE

}

renv_ansify_default <- function(text) {
text
}

renv_ansify_enhanced <- function(text) {

# R help links
pattern <- "`\\?(renv::(?:[^`])+)`"
replacement <- "`\033]8;;ide:help:\\1\a?\\1\033]8;;\a`"
text <- gsub(pattern, replacement, text, perl = TRUE)

# runnable code
pattern <- "`(renv::(?:[^`])+)`"
replacement <- "`\033]8;;ide:run:\\1\a\\1\033]8;;\a`"
text <- gsub(pattern, replacement, text, perl = TRUE)

# return ansified text
text

}

renv_ansify_init <- function() {

envir <- renv_envir_self()
if (renv_ansify_enabled())
assign("ansify", renv_ansify_enhanced, envir = envir)
else
assign("ansify", renv_ansify_default, envir = envir)

}

`%||%` <- function(x, y) {
if (is.null(x)) y else x
}
Expand Down Expand Up @@ -142,7 +202,10 @@ local({
# compute common indent
indent <- regexpr("[^[:space:]]", lines)
common <- min(setdiff(indent, -1L)) - leave
paste(substring(lines, common), collapse = "\n")
text <- paste(substring(lines, common), collapse = "\n")

# substitute in ANSI links for executable renv code
ansify(text)

}

Expand Down Expand Up @@ -306,7 +369,11 @@ local({
)

if ("headers" %in% names(formals(utils::download.file)))
args$headers <- renv_bootstrap_download_custom_headers(url)
{
headers <- renv_bootstrap_download_custom_headers(url)
if (length(headers) && is.character(headers))
args$headers <- headers
}

do.call(utils::download.file, args)

Expand Down Expand Up @@ -385,10 +452,22 @@ local({
for (type in types) {
for (repos in renv_bootstrap_repos()) {

# build arguments for utils::available.packages() call
args <- list(type = type, repos = repos)

# add custom headers if available -- note that
# utils::available.packages() will pass this to download.file()
if ("headers" %in% names(formals(utils::download.file)))
{
headers <- renv_bootstrap_download_custom_headers(url)
if (length(headers) && is.character(headers))
args$headers <- headers
}

# retrieve package database
db <- tryCatch(
as.data.frame(
utils::available.packages(type = type, repos = repos),
do.call(utils::available.packages, args),
stringsAsFactors = FALSE
),
error = identity
Expand Down Expand Up @@ -470,23 +549,31 @@ local({

}

renv_bootstrap_github_token <- function() {
for (envvar in c("GITHUB_TOKEN", "GITHUB_PAT", "GH_TOKEN")) {
envval <- Sys.getenv(envvar, unset = NA)
if (!is.na(envval))
return(envval)
}
}

renv_bootstrap_download_github <- function(version) {

enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE")
if (!identical(enabled, "TRUE"))
return(FALSE)

# prepare download options
pat <- Sys.getenv("GITHUB_PAT")
if (nzchar(Sys.which("curl")) && nzchar(pat)) {
token <- renv_bootstrap_github_token()
if (nzchar(Sys.which("curl")) && nzchar(token)) {
fmt <- "--location --fail --header \"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "curl", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
} else if (nzchar(Sys.which("wget")) && nzchar(pat)) {
} else if (nzchar(Sys.which("wget")) && nzchar(token)) {
fmt <- "--header=\"Authorization: token %s\""
extra <- sprintf(fmt, pat)
extra <- sprintf(fmt, token)
saved <- options("download.file.method", "download.file.extra")
options(download.file.method = "wget", download.file.extra = extra)
on.exit(do.call(base::options, saved), add = TRUE)
Expand Down

0 comments on commit 9525a2e

Please sign in to comment.