Skip to content

Commit

Permalink
removed anytime as dep (and fixed some indentions)
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Feb 26, 2023
1 parent 9c66720 commit a2c8a40
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Imports:
anytime,
parsedate,
fastmap,
jsonlite,
memoise,
Expand Down
2 changes: 1 addition & 1 deletion R/memo_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NULL
map <- trimws(gsub("\"", "", sub(" #.*", "", map)))
pattern <- "(.*): (.*)"
bioc_ver <- sub(pattern, "\\1", map)
bioc_date <- anytime::anytime(sub(pattern, "\\2", map), tz = "UTC", asUTC = TRUE)
bioc_date <- parsedate::parse_date(sub(pattern, "\\2", map))
data.frame(version = bioc_ver, date=bioc_date)
}

Expand Down
56 changes: 28 additions & 28 deletions R/resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
} else {
allvers <- .memo_rver()
}
allvers$date <- anytime::anytime(allvers$date, tz = "UTC", asUTC = TRUE)
allvers$date <- parsedate::parse_date(allvers$date)
utils::tail(allvers[allvers$date < snapshot_date,], 1)$version
}

Expand All @@ -14,7 +14,7 @@
} else {
allvers <- .memo_biocver()
}
allvers$date <- anytime::anytime(allvers$date, tz = "UTC", asUTC = TRUE)
allvers$date <- parsedate::parse_date(allvers$date)
utils::tail(allvers[allvers$date < snapshot_date,], 1)[,1:2]
}

Expand All @@ -38,9 +38,9 @@
}

.query_snapshot_dependencies_cran <- function(handle = "rtoot", snapshot_date = "2022-12-10", bioc_version = NULL) {
snapshot_date <- anytime::anytime(snapshot_date, tz = "UTC", asUTC = TRUE)
snapshot_date <- parsedate::parse_date(snapshot_date)
search_res <- .memo_search(handle)
search_res$pubdate <- anytime::anytime(search_res$crandb_file_date, tz = "UTC", asUTC = TRUE)
search_res$pubdate <- parsedate::parse_date(search_res$crandb_file_date)
snapshot_versions <- search_res[search_res$pubdate <= snapshot_date,]
if (nrow(snapshot_versions) == 0) {
stop("No snapshot version exists for ", handle, ".", call. = FALSE)
Expand All @@ -61,7 +61,7 @@
}

.query_snapshot_dependencies_github <- function(handle = "schochastics/rtoot", snapshot_date = "2022-12-10", bioc_version = NULL) {
snapshot_date <- anytime::anytime(snapshot_date, tz = "UTC", asUTC = TRUE)
snapshot_date <- parsedate::parse_date(snapshot_date)
sha <- .query_sha(handle, snapshot_date)
repo_descr <- .gh(paste0("/repos/", handle,"/contents/DESCRIPTION"), ref = sha$sha)
con <- url(repo_descr$download_url)
Expand All @@ -79,10 +79,10 @@
}

.query_snapshot_dependencies_bioc <- function(handle = "BiocGenerics", snapshot_date = "2022-01-10") {
snapshot_date <- anytime::anytime(snapshot_date, tz = "UTC", asUTC = TRUE)
snapshot_date <- parsedate::parse_date(snapshot_date)
bioc_version_df <- .query_biocver(snapshot_date) ## a dataframe!
search_res <- .memo_search_bioc(bioc_version_df$version)
search_res$pubdate <- anytime::anytime(bioc_version_df$date, tz = "UTC", asUTC = TRUE)
search_res$pubdate <- parsedate::parse_date(bioc_version_df$date)
latest_version <- search_res[search_res$Package==handle,]
if (nrow(latest_version) == 0) {
stop("No snapshot version exists for ", handle, ".", call. = FALSE)
Expand Down Expand Up @@ -112,7 +112,7 @@
commits <- .gh(paste0("/repos/", handle, "/commits"), per_page = 100, page = k)
k <- k + 1
}
list(sha = commits[[idx]]$sha, x_pubdate = anytime::anytime(dates[[idx]], tz = "UTC", asUTC = TRUE))
list(sha = commits[[idx]]$sha, x_pubdate = parsedate::parse_date(dates[[idx]]))
}

# parse a description file from github repo
Expand Down Expand Up @@ -256,8 +256,8 @@ resolve <- function(pkgs, snapshot_date, no_enhances = TRUE, no_suggests = TRUE,
}
snapshot_date <- Sys.Date() - 30
}
snapshot_date <- anytime::anytime(snapshot_date, tz = "UTC", asUTC = TRUE)
if (snapshot_date >= anytime::anytime(Sys.Date())) {
snapshot_date <- parsedate::parse_date(snapshot_date)
if (snapshot_date >= parsedate::parse_date(Sys.Date())) {
stop("We don't know the future.", call. = FALSE)
}
bioc_version <- .generate_bioc_version(snapshot_date = snapshot_date, pkgs = pkgs)
Expand Down Expand Up @@ -565,22 +565,22 @@ query_sysreqs <- function(rang, os = "ubuntu-20.04") {
}

.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)){
token <- Sys.getenv("GITHUB_TOKEN", NA_character_)
}
if(is.na(token)){
token <- ""
}
config <- httr::add_headers(Accept = "application/vnd.github.v3+json",Authorization=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)
if (!status_code %in% c(200)) {
stop(paste0("github request failed with status code: ", status_code,"\n",
"The requested URL was: ",request_results$url), call. = FALSE)
}
httr::content(request_results)
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)){
token <- Sys.getenv("GITHUB_TOKEN", NA_character_)
}
if(is.na(token)){
token <- ""
}
config <- httr::add_headers(Accept = "application/vnd.github.v3+json",Authorization=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)
if (!status_code %in% c(200)) {
stop(paste0("github request failed with status code: ", status_code,"\n",
"The requested URL was: ",request_results$url), call. = FALSE)
}
httr::content(request_results)
}
6 changes: 3 additions & 3 deletions tests/testthat/test_pkgref.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ test_that("as_pkgrefs renv_lockfile", {
})

test_that(".detect_renv_lockfile false",{
expect_false(.detect_renv_lockfile("./testdata/graph.RDS"))
expect_false(.detect_renv_lockfile(c("../testdata/graph.RDS", "../testdata/renv.lock")))
expect_false(.detect_renv_lockfile("../testdata/fake_renv.lock"))
expect_false(.detect_renv_lockfile("./testdata/graph.RDS"))
expect_false(.detect_renv_lockfile(c("../testdata/graph.RDS", "../testdata/renv.lock")))
expect_false(.detect_renv_lockfile("../testdata/fake_renv.lock"))
})
12 changes: 9 additions & 3 deletions tests/testthat/test_resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ test_that("issue 89", {
})

test_that("integration of renv to resolve", {
skip_if_offline()
skip_on_cran()
expect_error(X <- resolve("../testdata/renv.lock", snapshot_date = "2023-01-01"), NA)
skip_if_offline()
skip_on_cran()
expect_error(X <- resolve("../testdata/renv.lock", snapshot_date = "2023-01-01"), NA)
})

test_that(".gh error handling", {
skip_if_offline()
skip_on_cran()
expect_error(.gh("path/is/wrong"))
})

0 comments on commit a2c8a40

Please sign in to comment.