From aba4eb106e23c1546b382c3aab298b0a970d8b1f Mon Sep 17 00:00:00 2001 From: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:29:05 +0200 Subject: [PATCH 1/4] renv 1.0.8 --- Makefile | 2 +- renv/activate.R | 105 ++++++++++++++++++++++--- scripts/output/extra/convertToNetCDF.R | 3 +- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 3a844b1205..738915e4e8 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ update-renv: ## Upgrade all pik-piam packages in your renv to the respective update-renv-all: ## Upgrade all packages (including CRAN packages) in your renv ## to the respective latest release and write renv.lock to archive. - Rscript -e 'renv::update(exclude = "renv"); piamenv::archiveRenv()' + Rscript -e 'renv::update(type = getOption("pkgType")); piamenv::archiveRenv()' archive-renv: ## Write renv.lock to archive. Rscript -e 'piamenv::archiveRenv()' diff --git a/renv/activate.R b/renv/activate.R index d13f9932a1..2ebe403479 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,7 @@ local({ # the requested version of renv - version <- "1.0.7" + version <- "1.0.8" attr(version, "sha") <- NULL # the project directory @@ -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 } @@ -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) } @@ -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) @@ -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 @@ -470,6 +549,14 @@ 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") @@ -477,16 +564,16 @@ local({ 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) diff --git a/scripts/output/extra/convertToNetCDF.R b/scripts/output/extra/convertToNetCDF.R index 99d9dffec7..22bd01fd5b 100644 --- a/scripts/output/extra/convertToNetCDF.R +++ b/scripts/output/extra/convertToNetCDF.R @@ -40,4 +40,5 @@ lapply(X = mzFiles, FUN = function(x) { }, error = function(e) { message("Error processing file: ", x, " - ", e$message) }) -}) \ No newline at end of file +}) + From f2f0171755729c3cbe707a800e6b79605a64a8d4 Mon Sep 17 00:00:00 2001 From: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:40:05 +0200 Subject: [PATCH 2/4] piamenv 0.5.5 --- .Rprofile | 4 ++-- DESCRIPTION | 2 +- scripts/output/extra/convertToNetCDF.R | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.Rprofile b/.Rprofile index 7913b2deba..43d47c62c3 100644 --- a/.Rprofile +++ b/.Rprofile @@ -36,6 +36,6 @@ if (isTRUE(rownames(installed.packages(priority = "NA")) == "renv")) { } # in case bootstrapping fails halfway, install piamenv and rely on requirement auto-fixing -if (tryCatch(utils::packageVersion("piamenv") < "0.3.4", error = function(error) TRUE)) { - renv::install("piamenv", prompt = FALSE) +if (tryCatch(utils::packageVersion("piamenv") < "0.5.5", error = function(error) TRUE)) { + renv::install("piamenv", type = getOption("pkgType"), prompt = FALSE) } diff --git a/DESCRIPTION b/DESCRIPTION index 3a199b5dbd..3cc18bc481 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ Imports: mip, mrcommons, patchwork, - piamenv (>= 0.3.4), + piamenv (>= 0.5.5), piamInterfaces (>= 0.20.7), piamutils, quitte, diff --git a/scripts/output/extra/convertToNetCDF.R b/scripts/output/extra/convertToNetCDF.R index 22bd01fd5b..5c079f35a7 100644 --- a/scripts/output/extra/convertToNetCDF.R +++ b/scripts/output/extra/convertToNetCDF.R @@ -41,4 +41,3 @@ lapply(X = mzFiles, FUN = function(x) { message("Error processing file: ", x, " - ", e$message) }) }) - From 41e804410068c486332ae7ac968a16d756b77850 Mon Sep 17 00:00:00 2001 From: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:59:20 +0200 Subject: [PATCH 3/4] require magpie4 2.12.6 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3cc18bc481..0f91ffe750 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,7 @@ Imports: m4fsdp, madrat, magclass (>= 6.14.0), - magpie4 (>= 2.12.0), + magpie4 (>= 2.12.6), MagpieNCGains, magpiesets, mip, From 42741bafedabb588c7a502a3948a521cc698b85e Mon Sep 17 00:00:00 2001 From: Pascal Sauer <156898545+pascal-sauer@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:06:36 +0200 Subject: [PATCH 4/4] renv 1.0.9 --- Makefile | 2 +- renv/activate.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 738915e4e8..18c6a289d2 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ update-renv: ## Upgrade all pik-piam packages in your renv to the respective update-renv-all: ## Upgrade all packages (including CRAN packages) in your renv ## to the respective latest release and write renv.lock to archive. - Rscript -e 'renv::update(type = getOption("pkgType")); piamenv::archiveRenv()' + Rscript -e 'renv::update(); piamenv::archiveRenv()' archive-renv: ## Write renv.lock to archive. Rscript -e 'piamenv::archiveRenv()' diff --git a/renv/activate.R b/renv/activate.R index 2ebe403479..c360bf2962 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,7 @@ local({ # the requested version of renv - version <- "1.0.8" + version <- "1.0.9" attr(version, "sha") <- NULL # the project directory