From 2f30c35822b13d1fed58b11affb39ecdeefabdfd Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 4 Mar 2024 15:43:36 -0500 Subject: [PATCH 01/13] add default BioC_mirror for CI=TRUE env --- R/repositories.R | 35 ++++++++++++++++++++++++++++------- R/utilities.R | 6 ++++++ R/version.R | 8 +++++--- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 78eb99c8..45dae084 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -3,9 +3,9 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" .repositories_check_repos_envopt <- function() { - opt <- Sys.getenv("BIOCMANAGER_CHECK_REPOSITORIES", TRUE) - opt <- getOption("BiocManager.check_repositories", opt) - isTRUE(as.logical(opt)) + .env_opt_lgl( + "BIOCMANAGER_CHECK_REPOSITORIES", "BiocManager.check_repositories", TRUE + ) } .repositories_site_repository <- @@ -68,11 +68,30 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" repos } +.repositories_ci_mirror_envopt <- + function() +{ + .env_opt_lgl( + "BIOCMANAGER_USE_CI_MIRROR", "BiocManager.use_ci_mirror", TRUE + ) && as.logical(Sys.getenv("CI")) +} + +.BIOCONDUCTOR_CI_MIRROR <- "https://ci-mirror.bioconductor.org" + +.repositories_bioc_mirror <- function() { + if ( + .repositories_ci_mirror_envopt() && .url_exists(.BIOCONDUCTOR_CI_MIRROR) + ) + .BIOCONDUCTOR_CI_MIRROR + else + getOption("BioC_mirror", "https://bioconductor.org") +} + #' @importFrom stats setNames .repositories_bioc <- function(version, ..., type = NULL) { - mirror <- getOption("BioC_mirror", "https://bioconductor.org") + mirror <- .repositories_bioc_mirror() paths <- c( BioCsoft = "bioc", BioCann = "data/annotation", @@ -256,9 +275,11 @@ repositories <- function( .repositories_use_container_repo <- function() { - opt <- Sys.getenv("BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", TRUE) - opt <- getOption("BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", opt) - isTRUE(as.logical(opt)) + .env_opt_lgl( + "BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", + "BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", + TRUE + ) } #' @rdname repositories diff --git a/R/utilities.R b/R/utilities.R index 68071942..fc2392e3 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -33,6 +33,12 @@ } } +.env_opt_lgl <- function(envvar, option, default) { + opt <- Sys.getenv(envvar, default) + opt <- getOption(option, opt) + isTRUE(as.logical(opt)) +} + .sQuote <- function(x) sprintf("'%s'", as.character(x)) diff --git a/R/version.R b/R/version.R index f72d23e4..1072b697 100644 --- a/R/version.R +++ b/R/version.R @@ -78,9 +78,11 @@ format.version_sentinel <- .version_validity_online_check <- function() { - opt <- Sys.getenv("BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", TRUE) - opt <- getOption("BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", opt) - opt <- isTRUE(as.logical(opt)) + opt <- .env_opt_lgl( + "BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", + "BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", + TRUE + ) if (.VERSION_MAP$WARN_NO_ONLINE_CONFIG && !opt) { .VERSION_MAP$WARN_NO_ONLINE_CONFIG <- FALSE From 5d1ccfe25c07ae3622ede3d96eed3f1c91abd556 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 5 Mar 2024 15:51:27 +0000 Subject: [PATCH 02/13] remove .env_opt_lgl --- R/repositories.R | 20 +++++++++----------- R/version.R | 8 +++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 45dae084..1a5f9a55 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -3,9 +3,9 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" .repositories_check_repos_envopt <- function() { - .env_opt_lgl( - "BIOCMANAGER_CHECK_REPOSITORIES", "BiocManager.check_repositories", TRUE - ) + opt <- Sys.getenv("BIOCMANAGER_CHECK_REPOSITORIES", TRUE) + opt <- getOption("BiocManager.check_repositories", opt) + isTRUE(as.logical(opt)) } .repositories_site_repository <- @@ -71,9 +71,9 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" .repositories_ci_mirror_envopt <- function() { - .env_opt_lgl( - "BIOCMANAGER_USE_CI_MIRROR", "BiocManager.use_ci_mirror", TRUE - ) && as.logical(Sys.getenv("CI")) + opt <- Sys.getenv("BIOCMANAGER_USE_CI_MIRROR", TRUE) + opt <- getOption("BiocManager.use_ci_mirror", opt) + isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI")) } .BIOCONDUCTOR_CI_MIRROR <- "https://ci-mirror.bioconductor.org" @@ -275,11 +275,9 @@ repositories <- function( .repositories_use_container_repo <- function() { - .env_opt_lgl( - "BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", - "BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", - TRUE - ) + opt <- Sys.getenv("BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", TRUE) + opt <- getOption("BIOCONDUCTOR_USE_CONTAINER_REPOSITORY", opt) + isTRUE(as.logical(opt)) } #' @rdname repositories diff --git a/R/version.R b/R/version.R index 1072b697..f72d23e4 100644 --- a/R/version.R +++ b/R/version.R @@ -78,11 +78,9 @@ format.version_sentinel <- .version_validity_online_check <- function() { - opt <- .env_opt_lgl( - "BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", - "BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", - TRUE - ) + opt <- Sys.getenv("BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", TRUE) + opt <- getOption("BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS", opt) + opt <- isTRUE(as.logical(opt)) if (.VERSION_MAP$WARN_NO_ONLINE_CONFIG && !opt) { .VERSION_MAP$WARN_NO_ONLINE_CONFIG <- FALSE From 5f166d4eac3553218f9fab378ea8c238649cf1bb Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 5 Mar 2024 19:04:14 +0000 Subject: [PATCH 03/13] use BioC_mirror for containerRepository - fallback to bioconductor.org - update docs --- R/repositories.R | 51 +++++++++++++++++++++++++++++++++++---------- man/repositories.Rd | 16 +++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 1a5f9a55..6138e91b 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -1,4 +1,4 @@ -BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" +BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" .repositories_check_repos_envopt <- function() @@ -73,7 +73,7 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" { opt <- Sys.getenv("BIOCMANAGER_USE_CI_MIRROR", TRUE) opt <- getOption("BiocManager.use_ci_mirror", opt) - isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI")) + isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } .BIOCONDUCTOR_CI_MIRROR <- "https://ci-mirror.bioconductor.org" @@ -82,9 +82,10 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" if ( .repositories_ci_mirror_envopt() && .url_exists(.BIOCONDUCTOR_CI_MIRROR) ) - .BIOCONDUCTOR_CI_MIRROR + mirror_url <- .BIOCONDUCTOR_CI_MIRROR else - getOption("BioC_mirror", "https://bioconductor.org") + mirror_url <- "https://bioconductor.org" + getOption("BioC_mirror", mirror_url) } #' @importFrom stats setNames @@ -169,8 +170,9 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" #' the appropriate CRAN repository. #' #' To install binary packages on containerized versions of Bioconductor, -#' a default binary package location URL is set as a package constant, -#' see `BiocManager:::BINARY_BASE_URL`. Binary package installations +#' a default binary package location URL is resolved from the +#' `getOption("BioC_mirror")` (or the default `https://bioconductor.org`) +#' and the `BiocManager:::BINARY_SLUG_URL`. Binary package installations #' are enabled by default for Bioconductor Docker containers. Anyone #' wishing to opt out of the binary package installation can set either the #' variable or the option, \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY}, to @@ -204,6 +206,12 @@ BINARY_BASE_URL <- "https://bioconductor.org/packages/%s/container-binaries/%s" #' `repositories()` as a basis for constructing the `repos =` argument #' to `install.packages()` and related functions. #' +#' On Continuous Integration (CI) platforms, `BiocManager` re-routes +#' requests to low-cost mirror sites. Users may opt out of this by +#' setting either the option or the variable to `FALSE`, i.e., +#' `options(BiocManager.use_ci_mirror = FALSE)` or +#' \env{BIOCMANAGER_USE_CI_MIRROR}. +#' #' @return `repositories()`: named `character()` of repositories. #' #' @seealso @@ -282,16 +290,14 @@ repositories <- function( #' @rdname repositories #' -#' @aliases BINARY_BASE_URL -#' #' @description `containerRepository()` reports the location of the repository #' of binary packages for fast installation within containerized versions #' of Bioconductor, if available. #' #' @details #' -#' The unexported URL to the base repository is available with -#' `BiocManager:::BINARY_BASE_URL`. +#' The binary URL is a combination of `getOption("BioC_mirror")` and +#' `BiocManager:::BINARY_SLUG_URL`. #' #' \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY} is an environment #' variable or global `options()` which, when set to `FALSE`, avoids @@ -334,7 +340,30 @@ containerRepository <- return(character()) ## does the binary repository exist? - binary_repos0 <- sprintf(BINARY_BASE_URL, version, platform) + mirror <- .repositories_bioc_mirror() + .repositories_try_container_url(version, mirror) +} + +.repositories_try_container_url <- function(version, mirror) { + bioc_url <- paste0(mirror, BINARY_SLUG_URL) + binary_repos0 <- sprintf(bioc_url, version, platform) + packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") + url <- url(packages) + tryCatch({ + suppressWarnings(open(url, "rb")) + close(url) + setNames(binary_repos0, "BioCcontainers") + }, error = function(...) { + close(url) + .repositories_try_cont_url2( + version = version, mirror = "https://bioconductor.org" + ) + }) +} + +.repositories_try_cont_url2 <- function(version, mirror) { + bioc_url <- paste0(mirror, BINARY_SLUG_URL) + binary_repos0 <- sprintf(bioc_url, version, platform) packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") url <- url(packages) tryCatch({ diff --git a/man/repositories.Rd b/man/repositories.Rd index 27a0710c..9db08b1f 100644 --- a/man/repositories.Rd +++ b/man/repositories.Rd @@ -4,7 +4,6 @@ \alias{repositories} \alias{BiocManager.check_repositories} \alias{containerRepository} -\alias{BINARY_BASE_URL} \title{Display current Bioconductor and CRAN repositories.} \usage{ repositories( @@ -61,8 +60,9 @@ best practice is to use packages from the same release, and from the appropriate CRAN repository. To install binary packages on containerized versions of Bioconductor, -a default binary package location URL is set as a package constant, -see \code{BiocManager:::BINARY_BASE_URL}. Binary package installations +a default binary package location URL is resolved from the +\code{getOption("BioC_mirror")} (or the default \verb{https://bioconductor.org}) +and the \code{BiocManager:::BINARY_SLUG_URL}. Binary package installations are enabled by default for Bioconductor Docker containers. Anyone wishing to opt out of the binary package installation can set either the variable or the option, \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY}, to @@ -96,8 +96,14 @@ as much as possible to \emph{Bioconductor} best practices, use \code{repositories()} as a basis for constructing the \verb{repos =} argument to \code{install.packages()} and related functions. -The unexported URL to the base repository is available with -\code{BiocManager:::BINARY_BASE_URL}. +On Continuous Integration (CI) platforms, \code{BiocManager} re-routes +requests to low-cost mirror sites. Users may opt out of this by +setting either the option or the variable to \code{FALSE}, i.e., +\code{options(BiocManager.use_ci_mirror = FALSE)} or +\env{BIOCMANAGER_USE_CI_MIRROR}. + +The binary URL is a combination of \code{getOption("BioC_mirror")} and +\code{BiocManager:::BINARY_SLUG_URL}. \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY} is an environment variable or global \code{options()} which, when set to \code{FALSE}, avoids From 37304572309f4b0b7f069963cd1967a16b1b5e35 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Tue, 5 Mar 2024 23:30:44 +0000 Subject: [PATCH 04/13] remove .BIOCONDUCTOR_CI_MIRROR - read from config.yaml - find CI in institution value --- R/repositories.R | 40 ++++++++++++++++++++++++++++++++++------ R/version.R | 25 ++++++++++++++++--------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 6138e91b..f1c49361 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -76,13 +76,40 @@ BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } -.BIOCONDUCTOR_CI_MIRROR <- "https://ci-mirror.bioconductor.org" +.repositories_config_section <- function(sections, headings, inner_tag) { + grps <- grep(headings, sections) + start <- match(grep(inner_tag, sections), grps) + if (!length(start)) + return(setNames(character(), character())) + end <- ifelse( + length(grps) < start + 1L, length(sections), grps[start + 1] - 1L + ) + sections[seq(grps[start] + 1, end)] +} + +.repositories_config_mirror_element <- function(txt, tag) { + section <- trimws(.version_config_section(txt = txt, tag = tag)) + section <- .repositories_config_section( + section, "-\\sinstitution:.*", "Bioconductor.*CI.*" + ) + mkey_val <- Filter(function(x) startsWith(x, "https_mirror_url"), section) + sub("https_mirror_url: (.*)", "\\1", mkey_val) +} + +.repositories_read_bioc_mirrors <- + function(config = "https://bioconductor.org/config.yaml") +{ + txt <- .version_map_read_online(config) + mirror <- .repositories_config_mirror_element(txt, "mirrors:") + if (!length(mirror) || !nzchar(mirror)) + mirror <- "https://bioconductor.org" +} .repositories_bioc_mirror <- function() { if ( .repositories_ci_mirror_envopt() && .url_exists(.BIOCONDUCTOR_CI_MIRROR) ) - mirror_url <- .BIOCONDUCTOR_CI_MIRROR + mirror_url <- .repositories_read_bioc_mirrors() else mirror_url <- "https://bioconductor.org" getOption("BioC_mirror", mirror_url) @@ -341,10 +368,10 @@ containerRepository <- ## does the binary repository exist? mirror <- .repositories_bioc_mirror() - .repositories_try_container_url(version, mirror) + .repositories_try_container_url(version, mirror, platform) } -.repositories_try_container_url <- function(version, mirror) { +.repositories_try_container_url <- function(version, mirror, platform) { bioc_url <- paste0(mirror, BINARY_SLUG_URL) binary_repos0 <- sprintf(bioc_url, version, platform) packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") @@ -356,12 +383,13 @@ containerRepository <- }, error = function(...) { close(url) .repositories_try_cont_url2( - version = version, mirror = "https://bioconductor.org" + version = version, mirror = "https://bioconductor.org", + platform = platform ) }) } -.repositories_try_cont_url2 <- function(version, mirror) { +.repositories_try_cont_url2 <- function(version, mirror, platform) { bioc_url <- paste0(mirror, BINARY_SLUG_URL) binary_repos0 <- sprintf(bioc_url, version, platform) packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") diff --git a/R/version.R b/R/version.R index f72d23e4..cdbfb591 100644 --- a/R/version.R +++ b/R/version.R @@ -100,26 +100,27 @@ format.version_sentinel <- txt } -.version_map_config_element <- - function(txt, tag) -{ +.version_config_section <- function(txt, tag) { grps <- grep("^[^[:blank:]]", txt) start <- match(grep(tag, txt), grps) if (!length(start)) return(setNames(character(), character())) end <- ifelse(length(grps) < start + 1L, length(txt), grps[start + 1] - 1L) - map <- txt[seq(grps[start] + 1, end)] - map <- trimws(gsub("\"", "", sub(" #.*", "", map))) + txt[seq(grps[start] + 1, end)] +} +.version_map_config_element <- + function(txt, tag) +{ + map <- .version_config_section(txt = txt, tag = tag) + map <- trimws(gsub("\"", "", sub(" #.*", "", map))) pattern <- "(.*): (.*)" key <- sub(pattern, "\\1", map) value <- sub(pattern, "\\2", map) setNames(value, key) } -.version_map_get_online <- - function(config) -{ +.version_map_read_online <- function(config) { toggle_warning <- FALSE withCallingHandlers({ txt <- .version_map_get_online_config(config) @@ -130,7 +131,13 @@ format.version_sentinel <- }) if (toggle_warning) .VERSION_MAP$WARN_NO_ONLINE_CONFIG <- FALSE + txt +} +.version_map_get_online <- + function(config) +{ + txt <- .version_map_read_online(config = config) if (!length(txt) || inherits(txt, "error")) return(.VERSION_MAP_SENTINEL) @@ -170,7 +177,7 @@ format.version_sentinel <- BiocStatus = factor( status, levels = .VERSION_TAGS - ) + ) )) } From 9d8454c0431707ef26dac11fe28eabb1d447644f Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 15:52:59 +0000 Subject: [PATCH 05/13] re-use .version_config_section --- R/repositories.R | 26 ++++++++++---------------- R/version.R | 6 +++--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index f1c49361..b7af1b3b 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -76,40 +76,34 @@ BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } -.repositories_config_section <- function(sections, headings, inner_tag) { - grps <- grep(headings, sections) - start <- match(grep(inner_tag, sections), grps) - if (!length(start)) - return(setNames(character(), character())) - end <- ifelse( - length(grps) < start + 1L, length(sections), grps[start + 1] - 1L - ) - sections[seq(grps[start] + 1, end)] -} - .repositories_config_mirror_element <- function(txt, tag) { - section <- trimws(.version_config_section(txt = txt, tag = tag)) - section <- .repositories_config_section( - section, "-\\sinstitution:.*", "Bioconductor.*CI.*" + section <- .version_config_section( + txt = txt, grp = "^[^[:blank:]]", tag = tag + ) + section <- .version_config_section( + trimws(section), "-\\sinstitution:.*", "Bioconductor.*CI.*" ) mkey_val <- Filter(function(x) startsWith(x, "https_mirror_url"), section) sub("https_mirror_url: (.*)", "\\1", mkey_val) } .repositories_read_bioc_mirrors <- - function(config = "https://bioconductor.org/config.yaml") + function(config) { txt <- .version_map_read_online(config) mirror <- .repositories_config_mirror_element(txt, "mirrors:") if (!length(mirror) || !nzchar(mirror)) mirror <- "https://bioconductor.org" + mirror } .repositories_bioc_mirror <- function() { if ( .repositories_ci_mirror_envopt() && .url_exists(.BIOCONDUCTOR_CI_MIRROR) ) - mirror_url <- .repositories_read_bioc_mirrors() + mirror_url <- .repositories_read_bioc_mirrors( + config = "https://bioconductor.org/config.yaml" + ) else mirror_url <- "https://bioconductor.org" getOption("BioC_mirror", mirror_url) diff --git a/R/version.R b/R/version.R index cdbfb591..92824688 100644 --- a/R/version.R +++ b/R/version.R @@ -100,8 +100,8 @@ format.version_sentinel <- txt } -.version_config_section <- function(txt, tag) { - grps <- grep("^[^[:blank:]]", txt) +.version_config_section <- function(txt, grp, tag) { + grps <- grep(grp, txt) start <- match(grep(tag, txt), grps) if (!length(start)) return(setNames(character(), character())) @@ -112,7 +112,7 @@ format.version_sentinel <- .version_map_config_element <- function(txt, tag) { - map <- .version_config_section(txt = txt, tag = tag) + map <- .version_config_section(txt = txt, grp = "^[^[:blank:]]", tag = tag) map <- trimws(gsub("\"", "", sub(" #.*", "", map))) pattern <- "(.*): (.*)" key <- sub(pattern, "\\1", map) From 3f3a568c89c919f35f0865ec335a4af7ebaec34d Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 16:57:54 +0000 Subject: [PATCH 06/13] minor --- R/repositories.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index b7af1b3b..32fc8f57 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -77,9 +77,7 @@ BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" } .repositories_config_mirror_element <- function(txt, tag) { - section <- .version_config_section( - txt = txt, grp = "^[^[:blank:]]", tag = tag - ) + section <- .version_config_section(txt, "^[^[:blank:]]", tag) section <- .version_config_section( trimws(section), "-\\sinstitution:.*", "Bioconductor.*CI.*" ) From 8c16f73d8cf9369cfd083f1c51abdafc5ddcc9c6 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 18:41:29 +0000 Subject: [PATCH 07/13] remove .url_exists --- R/repositories.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 32fc8f57..c9e0a32d 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -96,9 +96,7 @@ BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" } .repositories_bioc_mirror <- function() { - if ( - .repositories_ci_mirror_envopt() && .url_exists(.BIOCONDUCTOR_CI_MIRROR) - ) + if (.repositories_ci_mirror_envopt()) mirror_url <- .repositories_read_bioc_mirrors( config = "https://bioconductor.org/config.yaml" ) From 77a22382f9eaaee39368b2bf8a1a70fec4349bb7 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 20:35:52 +0000 Subject: [PATCH 08/13] try url con twice with different inputs --- R/repositories.R | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index c9e0a32d..3cf7ffe5 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -1,4 +1,4 @@ -BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" +.BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" .repositories_check_repos_envopt <- function() @@ -189,7 +189,7 @@ BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" #' To install binary packages on containerized versions of Bioconductor, #' a default binary package location URL is resolved from the #' `getOption("BioC_mirror")` (or the default `https://bioconductor.org`) -#' and the `BiocManager:::BINARY_SLUG_URL`. Binary package installations +#' and the `BiocManager:::.BINARY_SLUG_URL`. Binary package installations #' are enabled by default for Bioconductor Docker containers. Anyone #' wishing to opt out of the binary package installation can set either the #' variable or the option, \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY}, to @@ -314,7 +314,7 @@ repositories <- function( #' @details #' #' The binary URL is a combination of `getOption("BioC_mirror")` and -#' `BiocManager:::BINARY_SLUG_URL`. +#' `BiocManager:::.BINARY_SLUG_URL`. #' #' \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY} is an environment #' variable or global `options()` which, when set to `FALSE`, avoids @@ -361,35 +361,31 @@ containerRepository <- .repositories_try_container_url(version, mirror, platform) } -.repositories_try_container_url <- function(version, mirror, platform) { - bioc_url <- paste0(mirror, BINARY_SLUG_URL) +.repositories_try_url_con <- function(version, mirror, platform, FUN, ...) { + bioc_url <- paste0(mirror, .BINARY_SLUG_URL) binary_repos0 <- sprintf(bioc_url, version, platform) packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") url <- url(packages) tryCatch({ suppressWarnings(open(url, "rb")) - close(url) setNames(binary_repos0, "BioCcontainers") }, error = function(...) { - close(url) - .repositories_try_cont_url2( - version = version, mirror = "https://bioconductor.org", - platform = platform - ) - }) + FUN(...) + }, finally = {close(url)}) } -.repositories_try_cont_url2 <- function(version, mirror, platform) { - bioc_url <- paste0(mirror, BINARY_SLUG_URL) - binary_repos0 <- sprintf(bioc_url, version, platform) - packages <- paste0(contrib.url(binary_repos0), "/PACKAGES.gz") - url <- url(packages) - tryCatch({ - suppressWarnings(open(url, "rb")) - close(url) - setNames(binary_repos0, "BioCcontainers") - }, error = function(...) { - close(url) - character() - }) +.repositories_try_container_url <- function(version, mirror, platform) { + .repositories_try_url_con( + version = version, + mirror = mirror, + platform = platform, + FUN = function(...) { + .repositories_try_url_con( + version = version, + mirror = "https://bioconductor.org", + platform = platform, + FUN = character + ) + } + ) } From 914b34221d292a211a8f27a52bff979e8340bd59 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 20:40:11 +0000 Subject: [PATCH 09/13] update docs --- man/repositories.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/repositories.Rd b/man/repositories.Rd index 9db08b1f..333c189a 100644 --- a/man/repositories.Rd +++ b/man/repositories.Rd @@ -62,7 +62,7 @@ the appropriate CRAN repository. To install binary packages on containerized versions of Bioconductor, a default binary package location URL is resolved from the \code{getOption("BioC_mirror")} (or the default \verb{https://bioconductor.org}) -and the \code{BiocManager:::BINARY_SLUG_URL}. Binary package installations +and the \code{BiocManager:::.BINARY_SLUG_URL}. Binary package installations are enabled by default for Bioconductor Docker containers. Anyone wishing to opt out of the binary package installation can set either the variable or the option, \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY}, to @@ -103,7 +103,7 @@ setting either the option or the variable to \code{FALSE}, i.e., \env{BIOCMANAGER_USE_CI_MIRROR}. The binary URL is a combination of \code{getOption("BioC_mirror")} and -\code{BiocManager:::BINARY_SLUG_URL}. +\code{BiocManager:::.BINARY_SLUG_URL}. \env{BIOCONDUCTOR_USE_CONTAINER_REPOSITORY} is an environment variable or global \code{options()} which, when set to \code{FALSE}, avoids From 71c9613a2a7f6cb7c196913773bccafb740167e5 Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 20:45:37 +0000 Subject: [PATCH 10/13] remove .env_opt_lgl --- R/utilities.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index fc2392e3..68071942 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -33,12 +33,6 @@ } } -.env_opt_lgl <- function(envvar, option, default) { - opt <- Sys.getenv(envvar, default) - opt <- getOption(option, opt) - isTRUE(as.logical(opt)) -} - .sQuote <- function(x) sprintf("'%s'", as.character(x)) From d74df144a4573da31d48b2df231a3a1412e0f66d Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 21:08:28 +0000 Subject: [PATCH 11/13] code cleanup --- R/repositories.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 3cf7ffe5..273b477e 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -76,32 +76,32 @@ isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } -.repositories_config_mirror_element <- function(txt, tag) { - section <- .version_config_section(txt, "^[^[:blank:]]", tag) +.repositories_config_mirror_element <- function(config) { + txt <- .version_map_read_online(config) + section <- .version_config_section(txt, "^[^[:blank:]]", "mirrors:") section <- .version_config_section( trimws(section), "-\\sinstitution:.*", "Bioconductor.*CI.*" ) - mkey_val <- Filter(function(x) startsWith(x, "https_mirror_url"), section) - sub("https_mirror_url: (.*)", "\\1", mkey_val) + m_value <- Filter(function(x) startsWith(x, "https_mirror_url"), section) + murl <- sub("https_mirror_url: (.*)", "\\1", m_value) + if (!length(murl) || !nzchar(murl)) + murl <- "https://bioconductor.org" + murl } .repositories_read_bioc_mirrors <- function(config) { - txt <- .version_map_read_online(config) - mirror <- .repositories_config_mirror_element(txt, "mirrors:") - if (!length(mirror) || !nzchar(mirror)) - mirror <- "https://bioconductor.org" + mirror <- "https://bioconductor.org" + if (.repositories_ci_mirror_envopt()) + mirror <- .repositories_config_mirror_element(config) mirror } .repositories_bioc_mirror <- function() { - if (.repositories_ci_mirror_envopt()) - mirror_url <- .repositories_read_bioc_mirrors( - config = "https://bioconductor.org/config.yaml" - ) - else - mirror_url <- "https://bioconductor.org" + mirror_url <- .repositories_read_bioc_mirrors( + "https://bioconductor.org/config.yaml" + ) getOption("BioC_mirror", mirror_url) } From 52318b5009cbdf6db37da00431fa7548eaf0e7ea Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 6 Mar 2024 21:36:17 +0000 Subject: [PATCH 12/13] add more robust sub pattern - unit tests --- R/repositories.R | 15 ++++++++------- tests/testthat/test_repositories.R | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 273b477e..3e736680 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -76,14 +76,13 @@ isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } -.repositories_config_mirror_element <- function(config) { - txt <- .version_map_read_online(config) +.repositories_config_mirror_element <- function(txt) { section <- .version_config_section(txt, "^[^[:blank:]]", "mirrors:") section <- .version_config_section( trimws(section), "-\\sinstitution:.*", "Bioconductor.*CI.*" ) - m_value <- Filter(function(x) startsWith(x, "https_mirror_url"), section) - murl <- sub("https_mirror_url: (.*)", "\\1", m_value) + mvalue <- Filter(function(x) startsWith(x, "https_mirror_url"), section) + murl <- sub("https_mirror_url:\\s*(.*)", "\\1", mvalue) if (!length(murl) || !nzchar(murl)) murl <- "https://bioconductor.org" murl @@ -93,13 +92,15 @@ function(config) { mirror <- "https://bioconductor.org" - if (.repositories_ci_mirror_envopt()) - mirror <- .repositories_config_mirror_element(config) + if (.repositories_ci_mirror_envopt()) { + txt <- .version_map_read_online(config) + mirror <- .repositories_config_mirror_element(txt) + } mirror } .repositories_bioc_mirror <- function() { - mirror_url <- .repositories_read_bioc_mirrors( + mirror_url <- .repositories_read_bioc_mirror( "https://bioconductor.org/config.yaml" ) getOption("BioC_mirror", mirror_url) diff --git a/tests/testthat/test_repositories.R b/tests/testthat/test_repositories.R index 6892aa20..e7dae486 100644 --- a/tests/testthat/test_repositories.R +++ b/tests/testthat/test_repositories.R @@ -169,6 +169,33 @@ test_that("'.repositories_filter()' works", { expect_equal(.repositories_filter(repos), repos0) }) +test_that("config.yaml is parsed correctly", { + test.config <- c( + "mirrors:", + " - 1-Bioconductor:", + " - institution: Bioconductor CI redirect", + " https_mirror_url: https://foobar.com/" + ) + expect_identical( + .repositories_config_mirror_element( + test.config + ), + "https://foobar.com/" + ) + test.config <- c( + "mirrors:", + " - 1-Bioconductor:", + " - institution: Bioconductor CI redirect", + " https_mirror_url: " + ) + expect_identical( + .repositories_config_mirror_element( + test.config + ), + "https://bioconductor.org" + ) +}) + test_that("'containerRepository' uses 'type' argument", { skip_if_offline() bin_url <- "https://bioconductor.org/packages/%s/container-binaries/%s" From 3fbda6ff5f20ffa5288a76695bad049273addadf Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Thu, 14 Mar 2024 15:22:21 +0000 Subject: [PATCH 13/13] function name changes --- R/repositories.R | 23 +++++++++++++---------- tests/testthat/test_repositories.R | 6 +++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/R/repositories.R b/R/repositories.R index 3e736680..014226d0 100644 --- a/R/repositories.R +++ b/R/repositories.R @@ -1,4 +1,5 @@ .BINARY_SLUG_URL <- "/packages/%s/container-binaries/%s" +.BIOC_DOMAIN_URL <- "https://bioconductor.org" .repositories_check_repos_envopt <- function() @@ -76,25 +77,27 @@ isTRUE(as.logical(opt)) && as.logical(Sys.getenv("CI", FALSE)) } -.repositories_config_mirror_element <- function(txt) { +.repositories_config_mirror_url <- function(txt) { section <- .version_config_section(txt, "^[^[:blank:]]", "mirrors:") section <- .version_config_section( trimws(section), "-\\sinstitution:.*", "Bioconductor.*CI.*" ) - mvalue <- Filter(function(x) startsWith(x, "https_mirror_url"), section) - murl <- sub("https_mirror_url:\\s*(.*)", "\\1", mvalue) - if (!length(murl) || !nzchar(murl)) - murl <- "https://bioconductor.org" - murl + mirror_value <- Filter( + function(x) startsWith(x, "https_mirror_url"), section + ) + mirror <- sub("https_mirror_url:\\s*(.*)", "\\1", mirror_value) + if (!length(mirror) || !nzchar(mirror)) + mirror <- .BIOC_DOMAIN_URL + mirror } -.repositories_read_bioc_mirrors <- +.repositories_read_bioc_mirror <- function(config) { - mirror <- "https://bioconductor.org" + mirror <- .BIOC_DOMAIN_URL if (.repositories_ci_mirror_envopt()) { txt <- .version_map_read_online(config) - mirror <- .repositories_config_mirror_element(txt) + mirror <- .repositories_config_mirror_url(txt) } mirror } @@ -383,7 +386,7 @@ containerRepository <- FUN = function(...) { .repositories_try_url_con( version = version, - mirror = "https://bioconductor.org", + mirror = .BIOC_DOMAIN_URL, platform = platform, FUN = character ) diff --git a/tests/testthat/test_repositories.R b/tests/testthat/test_repositories.R index e7dae486..ca101c16 100644 --- a/tests/testthat/test_repositories.R +++ b/tests/testthat/test_repositories.R @@ -177,7 +177,7 @@ test_that("config.yaml is parsed correctly", { " https_mirror_url: https://foobar.com/" ) expect_identical( - .repositories_config_mirror_element( + .repositories_config_mirror_url( test.config ), "https://foobar.com/" @@ -189,10 +189,10 @@ test_that("config.yaml is parsed correctly", { " https_mirror_url: " ) expect_identical( - .repositories_config_mirror_element( + .repositories_config_mirror_url( test.config ), - "https://bioconductor.org" + .BIOC_DOMAIN_URL ) })