Skip to content

Commit

Permalink
fix remove sysreqs.r-hub.io (#70)
Browse files Browse the repository at this point in the history
* bump version

* update test

* from pak::pkg_system_requirements to pak::pkg_sysreqs

* update test

* from sysreqs.r-hub.io to {pak}

* update news.md

* move R_USER_CACHE_DIR in setup file
  • Loading branch information
VincentGuyader authored Jun 17, 2024
1 parent e37fc1e commit 0b61619
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 108 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dockerfiler
Title: Easy Dockerfile Creation from R
Version: 0.2.2
Version: 0.2.2.9001
Authors@R: c(
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-7343-1846")),
Expand Down Expand Up @@ -41,5 +41,5 @@ Config/fusen/version: 0.5.1
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ importFrom(cli,cat_bullet)
importFrom(desc,desc_get)
importFrom(desc,desc_get_deps)
importFrom(fs,file_create)
importFrom(fs,file_delete)
importFrom(fs,file_exists)
importFrom(fs,file_temp)
importFrom(fs,path)
importFrom(glue,glue)
importFrom(jsonlite,fromJSON)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.2.2.xxxx

- remove sysreqs.r-hub.io to use {pak} instead for system requirement detection


# dockerfile 0.2.2

- fix : create a `use_pak` parameters in `dock_from_renv` to set `renv.config.pak.enabled = FALSE` instead of `renv.config.pak.enabled = TRUE` to avoid issues with {pak} during `renv::restore()`
Expand Down
78 changes: 5 additions & 73 deletions R/get_sysreqs.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' Get system requirements
#'
#' This function retrieves information about the
#' system requirements using the <https://sysreqs.r-hub.io>
#' API.
#' system requirements using the `pak::pkg_sysreqs()`.
#'
#' @param packages character vector. Packages names.
#' @param batch_n numeric. Number of simultaneous packages to ask.
Expand Down Expand Up @@ -30,76 +29,9 @@ get_sysreqs <- function(
)
)
)

sp <- split(
all_deps,
ceiling(
seq_along(all_deps) / batch_n
)
)


sort(
unique(
unname(
unlist(
lapply(
sp,
function(.x) {
get_batch_sysreqs(
.x,
quiet = quiet
)
}
)
)
)
)
)
raw_output <- pak::pkg_sysreqs(pkg = all_deps,sysreqs_platform = "debian")
unlist(raw_output$packages$system_packages)
out <- unlist(raw_output$packages$system_packages)
sort(unique(out[!is.na(out)]))
}

#' @importFrom fs file_delete file_temp
get_batch_sysreqs <- function(
all_deps,
quiet = TRUE
) {
url <- sprintf(
"https://sysreqs.r-hub.io/pkg/%s/linux-x86_64-debian-gcc",
paste(all_deps, collapse = ",")
)
path <- file_temp()

# Try to download, may fail if
# no internet or sysreq unavailable.
# In that case, we return ""
is_downloaded <- try(
{
suppressWarnings({
utils::download.file(
url,
path,
mode = "wb",
quiet = quiet
)
})
},
silent = TRUE
)

if (attempt::is_try_error(is_downloaded)) {
cat_red_bullet("Unable to query the sysreqs.")
cat_red_bullet("Possible explanation: no internet connection or sysreqs.r-hub.io is unavailable.")
out <- ""
} else {
out <- jsonlite::fromJSON(path)
}

try(
{
fs::file_delete(path)
},
silent = TRUE
)

unique(out[!is.na(out)])
}
3 changes: 1 addition & 2 deletions man/get_sysreqs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/setup_cache_dir.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
R_USER_CACHE_DIR<-tempfile()
dir.create(R_USER_CACHE_DIR)
Sys.setenv("R_USER_CACHE_DIR"=R_USER_CACHE_DIR)
31 changes: 2 additions & 29 deletions tests/testthat/test-get_sysreqs.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
test_that("get_sysreqs works", {
skip_on_cran()
skip_if_not(
attr(
curlGetHeaders(
"https://sysreqs.r-hub.io/pkg/mongolite/linux-x86_64-debian-gcc"
),
"status"
) == 200
)
res <- get_batch_sysreqs(
res <- get_sysreqs(
c("mongolite"),
quiet = TRUE
)
Expand All @@ -18,24 +10,5 @@ test_that("get_sysreqs works", {
expect_true(
inherits(res, "character")
)
# Test without internet
withr::with_envvar(
c(
"http_proxy" = "http://proxy:port",
"http_proxy_user" = "username",
"https_proxy" = "username",
"https_proxy_user" = "username",
"ftp_proxy" = "username"
),
res <- get_sysreqs(
packages = "mongolite",
quiet = TRUE,
batch_n = 30
)
)
expect_equal(
res,
""
#c("libsasl2-dev", "libssl-dev")
)

})

0 comments on commit 0b61619

Please sign in to comment.