Skip to content

Commit

Permalink
Fix #150 fix #149 fix#152 (#151)
Browse files Browse the repository at this point in the history
* Fix #150 fix #149

* Retry when hit by r-hub/pkgsearch#117

To make resolve more determinstic
  • Loading branch information
chainsawriot authored Jul 30, 2023
1 parent 3c236af commit eb76625
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rang
Title: Reconstructing Reproducible R Computational Environments
Version: 0.2.0
Version: 0.2.1
Authors@R:
c(person("Chung-hong", "Chan", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6232-7530")),
Expand Down
20 changes: 19 additions & 1 deletion R/memo_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ NULL

## one hr

.memo_search <- memoise::memoise(pkgsearch::cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60))
.cran_package_history <- function(package, max_retries = 5) {
n_retries <- 0
while(n_retries < max_retries) {
tryCatch({
return(pkgsearch::cran_package_history(package))
}, error = function(e) {
if (grepl("parse error: premature EOF", e$message)) {
n_retries <<- n_retries + 1
##message("retrying in 2s...")
Sys.sleep(2)
} else {
stop(e)
}
})
}
stop("Can't query this package: ", package, call. = FALSE)
}

.memo_search <- memoise::memoise(.cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60))

.rver <- function() {
suppressWarnings(jsonlite::fromJSON(readLines("https://api.r-hub.io/rversions/r-versions"), simplifyVector = TRUE))
Expand Down
8 changes: 4 additions & 4 deletions R/resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,17 @@ print.rang <- function(x, all_pkgs = FALSE, ...) {
return(res)
}

.gh <- function(path,ref = NULL,...){
.gh <- function(path,ref = NULL,...) {
url <- httr::parse_url("https://api.github.com/")
url <- httr::modify_url(url, path = path)
token <- Sys.getenv("GITHUB_PAT", NA_character_)
if(is.na(token)){
if(is.na(token)) {
token <- Sys.getenv("GITHUB_TOKEN", NA_character_)
}
if(is.na(token)){
if(is.na(token)) {
token <- ""
}
config <- httr::add_headers(Accept = "application/vnd.github.v3+json",Authorization=token)
config <- httr::add_headers(Accept = "application/vnd.github.v3+json", Authorization = paste0("token ", token))
params <- list(ref = ref,...)
request_results <- httr::GET(httr::modify_url(url, path = path), config, query = params)
status_code <- httr::status_code(request_results)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ test_that("Non-cran must enforce caching ref #22", {
## })

test_that("Integration of as_pkgrefs() in resolve() for sessionInfo()", {
skip_if_offline()
skip_on_cran()
x <- resolve(c("cran::sna"), snapshot_date = "2020-05-01", query_sysreqs = FALSE)
si <- readRDS("../testdata/sessionInfo2.RDS")
expect_error(graph <- resolve(si, snapshot_date = "2020-05-01", query_sysreqs = FALSE), NA)
Expand Down

0 comments on commit eb76625

Please sign in to comment.