Skip to content

Commit

Permalink
Use P3M date that supports macos binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Mar 23, 2024
1 parent cc5f7e3 commit 9e6718e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
8 changes: 6 additions & 2 deletions R/pkgDep.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#' @family dependency functions
#'
#' @seealso [pkgDep()]
basePkgs <- function()names(which(installed.packages()[, "Priority"] == "base"))

basePkgs <- function() names(which(installed.packages()[, "Priority"] == "base"))

availPkgNames <- function(pdb) {
pdb[, "Package"]
}

#' Retrieves package dependencies.
#'
Expand Down Expand Up @@ -78,6 +80,8 @@ pkgDep <- function(pkg, availPkgs, repos = getOption("repos"), type = "source",


pkgInAvail <- pkg %in% availPkgs[, "Package"]
pkgInAvail <- pkg %in% availPkgNames(availPkgs)
# browser()
if (sum(pkgInAvail) == 0 ) stop("No valid packages in pkg")
if (sum(pkgInAvail) < length(pkg)) {
warning("Package not recognized: ", paste(pkg[!pkgInAvail], collapse = ", "))
Expand Down
30 changes: 17 additions & 13 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ mock_write_packages <- function(dir, type = "source", r_version) {


# Create sample repo from MRAN snapshot
.createSampleRepo <- function(MRAN, path, pkgs, Rversion = "4.0") {
.createSampleRepo <- function(MRAN, path, pkgs, Rversion = "4.0", types) {
if (missing(MRAN)) MRAN <- MRAN("2024-01-02")
if (missing(path)) path <- file.path(tempdir(), "miniCRAN", Sys.Date())
if (missing(pkgs)) pkgs <- c("chron", "curl")
if (missing(types)) types <- set_test_types()

pdb_source <- pkgAvail(repos = MRAN, type = "source", Rversion = Rversion)
pdb_win <- pkgAvail(repos = MRAN, type = "win.binary", Rversion = Rversion)
Expand All @@ -109,19 +110,22 @@ mock_write_packages <- function(dir, type = "source", r_version) {
.env = "miniCRAN",
{

pkgList_source <- pkgDep(pkgs, availPkgs = pdb_source, repos = MRAN,
type = "source", suggests = FALSE, Rversion = Rversion)

makeRepo(pkgList_source, path = path, repos = MRAN,
type = "source",
quiet = TRUE, Rversion = Rversion)
for (type in types) {
pkgList_source <- pkgDep(pkgs, availPkgs = pdb_source, repos = MRAN,
type = type, suggests = FALSE, Rversion = Rversion)

makeRepo(pkgList_source, path = path, repos = MRAN,
type = type,
quiet = TRUE, Rversion = Rversion)

}

pkgList_win <- pkgDep(pkgs, availPkgs = pdb_win, repos = MRAN,
type = "win.binary",
suggests = FALSE, Rversion = Rversion)
makeRepo(pkgList_win, path = path, repos = MRAN,
type = "win.binary",
quiet = TRUE, Rversion = Rversion)
# pkgList_win <- pkgDep(pkgs, availPkgs = pdb_win, repos = MRAN,
# type = "win.binary",
# suggests = FALSE, Rversion = Rversion)
# makeRepo(pkgList_win, path = path, repos = MRAN,
# type = "win.binary",
# quiet = TRUE, Rversion = Rversion)

# pkgList_mac <- pkgDep(pkgs, availPkgs = pdb_mac, repos = MRAN,
# type = "mac.binary",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-3-makeRepo.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


{
revolution <- MRAN("2024-01-02")
revolution <- MRAN("2023-08-04")
if (!is.online(revolution, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
Expand Down
17 changes: 10 additions & 7 deletions tests/testthat/test-5-updateRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
if (file.exists(repo_root)) unlink(repo_root, recursive = TRUE)
dir.create(repo_root, recursive = TRUE, showWarnings = FALSE)

revolution <- MRAN("2020-01-02")
revolution <- MRAN("2023-08-31")
if (!is.online(revolution, tryHttp = FALSE)) {
# Use http:// for older versions of R
revolution <- sub("^https://", "http://", revolution)
}
rvers <- "4.0"
pkgs <- c("chron", "curl")
pkgs <- c("chron", "XML")

types <- intersect(
set_test_types(),
Expand All @@ -28,16 +28,19 @@
test_that("sample repo is setup correctly", {
skip_if_offline(revolution)

type <- types[1]
pdb <<- lapply(types, pkgAvail, repos = revolution, Rversion = rvers, quiet = TRUE)
expect_type(pdb, "list")
pkgList <<- lapply(types, function(type) {
pkgDep(pkg = pkgs, type = types[type], availPkgs = pdb[[type]],
# type <- names(type)
pkgDep(pkg = pkgs, type = names(type), availPkgs = pdb[[type]],
repos = revolution, suggests = FALSE, Rversion = rvers)
})
expect_type(pkgList, "list")

z <- .createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers, pkgs = pkgs)
expect_type(z, "character")
z <- .createSampleRepo(path = repo_root, MRAN = revolution, Rversion = rvers,
pkgs = pkgs, types = names(types))
# expect_type(z, "character")
pkg_names <- unname(pkgAvail(repo_root, quiet = TRUE)[, "Package"])
expect_true(all(pkgs %in% pkg_names))
})
Expand Down Expand Up @@ -193,9 +196,9 @@ for (pkg_type in names(types)) {
)

# In the following allow for differences between mac.binary and other types
expect_gt(nrow(old), 1)
expect_gte(nrow(old), 1)
expect_equal(ncol(old), 4)
expect_true( "Rcpp" %in% rownames(old))
expect_true( "XML" %in% rownames(old))

mockr::with_mock(
download_packages = mock_download_packages,
Expand Down

0 comments on commit 9e6718e

Please sign in to comment.