Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .query_sysreqs_bioc testable #91

Merged
merged 3 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions R/resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,18 @@ query_sysreqs <- function(rang, os = "ubuntu-20.04") {
}
pkgs <- .memo_search_bioc(bioc_version = "release")
raw_sys_reqs <- pkgs$SystemRequirements[pkgs$Package %in% handles]
baseurl <- "https://sysreqs.r-hub.io/map/"
singleline_sysreqs <- paste0(raw_sys_reqs[!is.na(raw_sys_reqs)], collapse = ", ")
singleline_sysreqs <- gsub("\\n", " ", singleline_sysreqs)
.query_singleline_sysreqs(singleline_sysreqs = singleline_sysreqs, arch = arch)
}

.query_singleline_sysreqs <- function(singleline_sysreqs, arch = "DEB") {
baseurl <- "https://sysreqs.r-hub.io/map/"
url <- utils::URLencode(paste0(baseurl, singleline_sysreqs))
checkable_cmds <- vapply(jsonlite::read_json(url), .extract_sys_package, character(1), arch = arch)
query_res <- jsonlite::read_json(url)
checkable_cmds <- vapply(query_res, .extract_sys_package, character(1), arch = arch)
uncheckable_cmds <- .extract_uncheckable_sysreqs(singleline_sysreqs, arch = arch)
return(c(checkable_cmds, uncheckable_cmds))
c(checkable_cmds[!is.na(checkable_cmds)], uncheckable_cmds)
}

## Not everything can be check from sysreqs DB, especially Bioc packages
Expand All @@ -506,6 +511,9 @@ query_sysreqs <- function(rang, os = "ubuntu-20.04") {
} else {
sys_pkg <- output[["buildtime"]]
}
if (is.null(sys_pkg)) {
return(NA_character_)
}
if (arch == "DEB") {
return(paste0("apt-get install -y ", sys_pkg))
}
Expand Down
Binary file added tests/testdata/sysreqs_gmp.RDS
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/testthat/test_resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,20 @@ test_that(".query_sysreqs_bioc with uncheckable info", {
expect_true("apt-get install -y libbz2-dev" %in% x) ## uncheckable
expect_true("apt-get install -y liblzma-dev" %in% x)
expect_true("apt-get install -y make" %in% x) ## checkable
expect_false("apt-get install -y" %in% x) ## the null response from C++
x <- .query_sysreqs_bioc("Rhtslib", "centos-7")
expect_true("yum install -y libbz2-devel" %in% x)
expect_true("yum install -y xz-devel" %in% x)
expect_true("yum install -y make" %in% x)
expect_false("yum install -y" %in% x) ## the null response from C++
x <- .query_singleline_sysreqs("libxml2", "DEB")
expect_equal(x, "apt-get install -y libxml2-dev")
x <- .query_singleline_sysreqs("C++", "DEB")
expect_equal(x, character(0))
x <- readRDS("../testdata/sysreqs_gmp.RDS")
## buildtime / runtime requirements
expect_equal(.extract_sys_package(x[[1]], arch = "DEB"),
"apt-get install -y libgmp-dev")
})

test_that("issue 89", {
Expand Down