Skip to content

Commit

Permalink
Merge pull request #97 from schochastics/snapshot_date
Browse files Browse the repository at this point in the history
set snapshot date depending on pkgs (#53,#55)
  • Loading branch information
chainsawriot authored Feb 27, 2023
2 parents 17edbfc + 2cc6a00 commit 5a31317
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 713 deletions.
4 changes: 2 additions & 2 deletions R/as_pkgrefs.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ as_pkgrefs.default <- function(x, ...) {
#' @rdname as_pkgrefs
#' @export
as_pkgrefs.character <- function(x, bioc_version = NULL, ...) {
if(.detect_renv_lockfile(x)){
if(.is_renv_lockfile(x)){
return(.extract_pkgrefs_renv_lockfile(path = x))
}
if(.is_directory(x)){
Expand Down Expand Up @@ -89,7 +89,7 @@ as_pkgrefs.sessionInfo <- function(x, ...) {
## }
}

.detect_renv_lockfile <- function(path){
.is_renv_lockfile <- function(path){
# assuming all renv lockfiles are called renv.lock and path is only length 1
if(length(path)!=1){
return(FALSE)
Expand Down
37 changes: 27 additions & 10 deletions R/resolve.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,7 @@ resolve <- function(pkgs, snapshot_date, no_enhances = TRUE, no_suggests = TRUE,
if (!os %in% supported_os) {
stop("Don't know how to resolve ", os, ". Supported OSes are: ", paste(supported_os, collapse = ", "))
}
if (missing(snapshot_date)) {
if (isTRUE(verbose)) {
cat("No `snapshot_date`: Assuming `snapshot_date` to be a month ago.\n")
}
snapshot_date <- Sys.Date() - 30
}
snapshot_date <- parsedate::parse_date(snapshot_date)
if (snapshot_date >= parsedate::parse_date(Sys.Date())) {
stop("We don't know the future.", call. = FALSE)
}
snapshot_date <- .extract_date(pkgs = pkgs, date = snapshot_date, verbose = verbose)
bioc_version <- .generate_bioc_version(snapshot_date = snapshot_date, pkgs = pkgs)
pkgrefs <- as_pkgrefs(pkgs, bioc_version = bioc_version)
output <- list()
Expand Down Expand Up @@ -362,6 +353,32 @@ print.rang <- function(x, all_pkgs = FALSE, ...) {
}
}

.extract_date <- function(pkgs,date,verbose = FALSE){
if(missing(date)){
snapshot_date <- NA
if(.is_directory(pkgs)){
snapshot_date <- max(file.mtime(dir(pkgs,recursive = TRUE)))
}
if(.is_renv_lockfile(pkgs)){
snapshot_date <- file.mtime(pkgs)
}
if(is.na(snapshot_date)){
if (isTRUE(verbose)) {
cat("No `snapshot_date`: Assuming `snapshot_date` to be a month ago.\n")
}
snapshot_date <- Sys.Date() - 30
}
} else{
snapshot_date <- date
}
snapshot_date <- parsedate::parse_date(snapshot_date)
if (snapshot_date > parsedate::parse_date(Sys.time())) {
stop("We don't know the future.", call. = FALSE)
}
snapshot_date
}


## extract all the pkgrefs of deps and pkgs: for .sysreqs
.extract_pkgrefs <- function(rang) {
original_pkgrefs <- names(rang$ranglets)
Expand Down
Binary file modified tests/testdata/bioc_renv.RDS
Binary file not shown.
Loading

0 comments on commit 5a31317

Please sign in to comment.