From 19f022b1f635e94c00566e6662658ec8c42fe9fc Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 6 Oct 2023 17:41:33 +0200 Subject: [PATCH] Update text fix #157 (#158) * Update text fix #157 ? * f * MF * Allow `.cache_rsrc` to use `cran_mirror` --- R/cache.R | 4 ++-- R/installation.R | 2 +- tests/testthat/test_resolve.R | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/R/cache.R b/R/cache.R index 7b47ed9..b654c1a 100644 --- a/R/cache.R +++ b/R/cache.R @@ -119,7 +119,7 @@ NULL invisible(base_dir) } -.cache_rsrc <- function(r_version, base_dir, verbose) { +.cache_rsrc <- function(r_version, base_dir, verbose, cran_mirror) { cache_dir <- file.path(base_dir, "cache", "rsrc") if (!dir.exists(cache_dir)) { dir.create(cache_dir, recursive = TRUE) @@ -132,7 +132,7 @@ NULL } download_dir <- paste0("R-", major_version) tar_file <- paste0("R-", r_version, file_extension) - url <- paste0("https://cran.r-project.org/src/base/", download_dir, "/", tar_file) + url <- paste0(cran_mirror, "src/base/", download_dir, "/", tar_file) tar_path <- file.path(cache_dir, tar_file) download.file(url = url, destfile = tar_path, quiet = !verbose) if (!file.exists(tar_path)) { diff --git a/R/installation.R b/R/installation.R index 87f4da5..de0684a 100644 --- a/R/installation.R +++ b/R/installation.R @@ -377,7 +377,7 @@ export_renv <- function(rang, path = ".") { copy_all = copy_all) if (isTRUE(cache)) { .cache_rsrc(r_version = r_version, base_dir = base_dir, - verbose = verbose) + verbose = verbose, cran_mirror = cran_mirror) .cache_debian(debian_version = debian_version, base_dir = base_dir, verbose = verbose) } diff --git a/tests/testthat/test_resolve.R b/tests/testthat/test_resolve.R index 3ffaaf4..7192e99 100644 --- a/tests/testthat/test_resolve.R +++ b/tests/testthat/test_resolve.R @@ -80,7 +80,7 @@ test_that("cache #17", { expect_false(file.exists(file.path(temp_dir, "cache/rpkgs", "LDAvis_0.3.2.tar.gz"))) expect_false(file.exists(file.path(temp_dir, "cache/rpkgs", "proxy_0.4-27.tar.gz"))) expect_false(file.exists(file.path(temp_dir, "cache/rpkgs", "RJSONIO_1.3-1.6.tar.gz"))) - expect_silent(dockerize(rang_ok, output_dir = temp_dir, cache = TRUE, verbose = FALSE)) + expect_silent(dockerize(rang_ok, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE)) x <- readLines(file.path(temp_dir, "Dockerfile")) expect_true(any(grepl("^COPY cache", x))) expect_true(dir.exists(file.path(temp_dir, "cache/rpkgs"))) @@ -96,7 +96,7 @@ test_that("cache for R < 3.1 and R >= 2.1", { rang_rio <- readRDS("../testdata/rang_rio_old.RDS") expect_equal(rang_rio$r_version, "3.0.1") temp_dir <- .generate_temp_dir() - dockerize(rang_rio, output_dir = temp_dir, cache = TRUE, verbose = FALSE) + dockerize(rang_rio, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE) x <- readLines(file.path(temp_dir, "Dockerfile")) expect_true(any(grepl("^COPY cache", x))) expect_true(dir.exists(file.path(temp_dir, "cache/rpkgs"))) @@ -135,13 +135,13 @@ test_that("Non-cran must enforce caching ref #22", { temp_dir <- .generate_temp_dir() graph <- readRDS("../testdata/ancientsna.RDS") expect_equal(graph$ranglets[[1]]$pkgref, "github::cran/sna") - expect_error(dockerize(graph, output_dir = temp_dir, verbose = FALSE)) ## cache = FALSE - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE)) ## cache = FALSE + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) temp_dir <- .generate_temp_dir() graph <- readRDS("../testdata/anciente1071.RDS") expect_equal(graph$ranglets[[1]]$pkgref, "cran::e1071") - expect_error(dockerize(graph, output_dir = temp_dir, verbose = FALSE), NA) - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) }) ## This should be tested. But this takes too long without cache. @@ -180,7 +180,7 @@ test_that("cache bioc pkgs", { expect_false(any(grepl("^COPY cache", x))) expect_false(dir.exists(file.path(temp_dir, "cache/rpkgs"))) expect_false(file.exists(file.path(temp_dir, "cache/rpkgs", "BiocGenerics_0.44.0.tar.gz"))) - expect_silent(dockerize(rang_bioc, output_dir = temp_dir, cache = TRUE, verbose = FALSE)) + expect_silent(dockerize(rang_bioc, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE)) x <- readLines(file.path(temp_dir, "Dockerfile")) expect_true(any(grepl("^COPY cache", x))) expect_true(dir.exists(file.path(temp_dir, "cache/rpkgs"))) @@ -238,7 +238,7 @@ test_that("issue 89", { x <- resolve("bioc::GenomeInfoDbData", snapshot_date = "2023-01-01") expect_equal(x$ranglets[["bioc::GenomeInfoDbData"]]$original$x_uid, "data/annotation") temp_dir <- .generate_temp_dir() - expect_error(dockerize(x, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) + expect_error(dockerize(x, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) expect_true(file.exists(file.path(temp_dir, "cache/rpkgs", "GenomeInfoDbData_1.2.9.tar.gz"))) }) @@ -291,7 +291,7 @@ test_that("dockerize local package as tarball", { expect_error(suppressWarnings(graph <- resolve("local::../testdata/askpass_1.1.tar.gz", snapshot_date = "2023-01-01")), NA) expect_error(dockerize(graph, output_dir = temp_dir)) ## cache = FALSE temp_dir <- .generate_temp_dir() - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) ## cache = FALSE + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) expect_true(file.exists(file.path(temp_dir, "cache/rpkgs", "sys_3.4.1.tar.gz"))) expect_true(file.exists(file.path(temp_dir, "cache/rpkgs", "raw_askpass_1.1.tar.gz"))) }) @@ -303,7 +303,7 @@ test_that("dockerize local package as tarball", { expect_error(suppressWarnings(graph <- resolve("local::../testdata/askpass", snapshot_date = "2023-01-01")), NA) expect_error(dockerize(graph, output_dir = temp_dir)) ## cache = FALSE temp_dir <- .generate_temp_dir() - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) expect_true(file.exists(file.path(temp_dir, "cache/rpkgs", "sys_3.4.1.tar.gz"))) expect_true(dir.exists(file.path(temp_dir, "cache/rpkgs", "dir_askpass_1.1"))) x <- readLines(file.path(temp_dir, "rang.R")) @@ -322,7 +322,7 @@ test_that("dockerize R1.3.1 local", { skip_on_cran() expect_error(suppressWarnings(graph <- resolve("../testdata/sna_0.3.tar.gz", snapshot_date = "2001-09-11")), NA) temp_dir <- .generate_temp_dir() - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) x <- readLines(file.path(temp_dir, "rang.R")) expect_true(any(grepl("^## DEBUG INFO: CMD", x))) }) @@ -333,10 +333,10 @@ test_that("skip_r17", { expect_error(suppressWarnings(graph <- resolve("../testdata/sna_0.3.tar.gz", snapshot_date = "2003-04-17")), NA) expect_equal(graph$r_version, "1.7.0") temp_dir <- .generate_temp_dir() - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE), NA) ## skip_r17 = TRUE + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) ## skip_r17 = TRUE x <- readLines(file.path(temp_dir, "Dockerfile")) expect_true(any(grepl("^RUN bash \\$COMPILE_PATH 1\\.8\\.0", x))) - expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, skip_r17 = FALSE), NA) + expect_error(dockerize(graph, output_dir = temp_dir, cache = TRUE, verbose = FALSE, skip_r17 = FALSE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE), NA) x <- readLines(file.path(temp_dir, "Dockerfile")) expect_false(any(grepl("^RUN bash \\$COMPILE_PATH 1\\.8\\.0", x))) expect_true(any(grepl("^RUN bash \\$COMPILE_PATH 1\\.7\\.0", x))) @@ -354,7 +354,7 @@ test_that("dockerize with inst/rang", { temp_dir <- .generate_temp_dir() dir.create(temp_dir) use_rang(temp_dir, verbose = FALSE) - dockerize(rang_ok, output_dir = temp_dir, verbose = FALSE, cache = TRUE) + dockerize(rang_ok, output_dir = temp_dir, verbose = FALSE, cache = TRUE, cran_mirror = "https://cloud.r-project.org/", check_cran_mirror = FALSE) expect_true("inst/rang/rang.R" %in% list.files(temp_dir, recursive = TRUE)) expect_false("rang.R" %in% list.files(temp_dir, recursive = TRUE)) expect_true(dir.exists(file.path(temp_dir, "inst/rang/cache")))