Skip to content

Commit

Permalink
Update text fix #157 (#158)
Browse files Browse the repository at this point in the history
* Update text fix #157 ?

* f

* MF

* Allow `.cache_rsrc` to use `cran_mirror`
  • Loading branch information
chainsawriot authored Oct 6, 2023
1 parent 984583b commit 19f022b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/installation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 14 additions & 14 deletions tests/testthat/test_resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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")))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")))
Expand Down Expand Up @@ -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")))
})

Expand Down Expand Up @@ -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")))
})
Expand All @@ -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"))
Expand All @@ -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)))
})
Expand All @@ -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)))
Expand All @@ -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")))
Expand Down

0 comments on commit 19f022b

Please sign in to comment.