diff --git a/DESCRIPTION b/DESCRIPTION index 3c5574e8..62c3049c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,7 @@ Imports: cli (>= 3.6.0), desc (>= 1.2), gh, + jsonlite, pkgcache (>= 2.1.0), pkgdepends (>= 0.5.0), rcmdcheck, @@ -31,8 +32,10 @@ Suggests: pingr, testthat (>= 3.0.4) Config/Needs/verdepcheck: + r-lib/cli, r-lib/desc, r-lib/gh, + jeroen/jsonlite, r-lib/pkgcache, r-lib/pkgdepends, r-lib/rcmdcheck, diff --git a/NAMESPACE b/NAMESPACE index ea456ab2..9e205165 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ S3method(get_release_date,remote_ref) S3method(get_release_date,remote_ref_cran) S3method(get_release_date,remote_ref_github) S3method(get_release_date,remote_ref_standard) +S3method(get_version,remote_ref) S3method(solve_ip,deps_installation_proposal) S3method(solve_ip,min_isolated_deps_installation_proposal) export(check_ip) @@ -20,6 +21,7 @@ export(get_ref_min) export(get_ref_min_incl_cran) export(get_ref_release) export(get_release_date) +export(get_version) export(install_ip) export(max_deps_check) export(min_cohort_deps_check) @@ -47,6 +49,7 @@ importFrom(cli,symbol) importFrom(desc,desc) importFrom(gh,gh) importFrom(gh,gh_gql) +importFrom(jsonlite,fromJSON) importFrom(pkgcache,cran_archive_list) importFrom(pkgcache,meta_cache_list) importFrom(pkgcache,ppm_repo_url) diff --git a/R/desc_utils.R b/R/desc_utils.R index 80983b3c..dcfc43fc 100644 --- a/R/desc_utils.R +++ b/R/desc_utils.R @@ -128,6 +128,7 @@ desc_cond_set_refs <- function(d, refs) { desc_to_ip <- function(d, config) { temp_desc <- tempfile() d$write(temp_desc) + cli::cli_alert_info(paste0("Creating temporary DESCRIPTION file: ", cli::col_blue(temp_desc))) pkgdepends::new_pkg_installation_proposal( refs = paste0("deps::", temp_desc), diff --git a/R/get_ref.R b/R/get_ref.R index 9171cf9a..33332b87 100644 --- a/R/get_ref.R +++ b/R/get_ref.R @@ -14,7 +14,7 @@ get_ref_min_incl_cran <- function(remote_ref, op = "", op_ver = "") { } #' @rdname get_ref_min_incl_cran -#' @exportS3Method get_ref_min_incl_cran remote_ref +#' @export #' @examples #' verdepcheck:::get_ref_min_incl_cran(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" @@ -25,7 +25,7 @@ get_ref_min_incl_cran.remote_ref <- function(remote_ref, op = "", op_ver = "") { #' @rdname get_ref_min_incl_cran #' @importFrom pkgdepends parse_pkg_ref -#' @exportS3Method get_ref_min_incl_cran remote_ref_github +#' @export #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" #' verdepcheck:::get_ref_min_incl_cran(pkgdepends::parse_pkg_ref("cran/dplyr")) get_ref_min_incl_cran.remote_ref_github <- function(remote_ref, op = "", op_ver = "") { @@ -77,9 +77,9 @@ get_ref_min <- function(remote_ref, op = "", op_ver = "") { } #' @rdname get_ref_min -#' @exportS3Method get_ref_min remote_ref +#' @export #' @examples -#' verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) +#' get_ref_min(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) get_ref_min.remote_ref <- function(remote_ref, op = "", op_ver = "") { remote_ref } @@ -88,26 +88,26 @@ get_ref_min.remote_ref <- function(remote_ref, op = "", op_ver = "") { #' to obtain historical data. #' #' @rdname get_ref_min -#' @exportS3Method get_ref_min remote_ref_cran +#' @export #' @importFrom cli cli_alert_danger #' @importFrom pkgcache cran_archive_list meta_cache_list #' @importFrom pkgdepends parse_pkg_ref #' @importFrom stats setNames #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" -#' verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("cran::dplyr")) +#' get_ref_min(pkgdepends::parse_pkg_ref("cran::dplyr")) get_ref_min.remote_ref_cran <- function(remote_ref, op = "", op_ver = "") { - if (remote_ref$atleast == "" && remote_ref$version != "") { + if (remote_ref$version != "") { return(remote_ref) } x_pkg_cache <- pkgcache::meta_cache_list(remote_ref$package) - x_pkg_cache_archive <- pkgcache::cran_archive_list(package = remote_ref$package) + x_pkg_cache_archive <- pkgcache::cran_archive_list(packages = remote_ref$package) pv <- unique(c(x_pkg_cache_archive$version, x_pkg_cache$version)) pv <- stats::setNames(package_version(pv), pv) pv <- filter_valid_version(pv, op, op_ver) min_ver <- Filter(function(x) x == min(pv), pv) - new_ref <- sprintf("%s@%s", remote_ref$ref, names(min_ver)) # @TODO deparse, add ver, parse again + new_ref <- sprintf("%s@%s", remote_ref$package, names(min_ver)) tryCatch( pkgdepends::parse_pkg_ref(new_ref), error = function(err) { @@ -125,9 +125,9 @@ get_ref_min.remote_ref_cran <- function(remote_ref, op = "", op_ver = "") { } #' @rdname get_ref_min -#' @exportS3Method get_ref_min remote_ref_standard +#' @export #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" -#' verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("dplyr")) +#' get_ref_min(pkgdepends::parse_pkg_ref("dplyr")) get_ref_min.remote_ref_standard <- function(remote_ref, op = "", op_ver = "") { get_ref_min.remote_ref_cran(remote_ref, op, op_ver) } @@ -136,11 +136,11 @@ get_ref_min.remote_ref_standard <- function(remote_ref, op = "", op_ver = "") { #' and then [`gh::gh()`] to download `DESCRIPTION` file and then read package version. #' #' @rdname get_ref_min -#' @exportS3Method get_ref_min remote_ref_github +#' @export #' @importFrom pkgdepends parse_pkg_ref #' #' @examplesIf gh::gh_token() != "" -#' verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("cran/dplyr")) +#' get_ref_min(pkgdepends::parse_pkg_ref("cran/dplyr")) get_ref_min.remote_ref_github <- function(remote_ref, op = "", op_ver = "") { if (remote_ref$commitish != "") { return(remote_ref) @@ -254,7 +254,7 @@ get_gh_tags <- function(org, repo, max_date = Sys.Date() + 1, min_date = as.Date #' @importFrom gh gh #' @keywords internal #' -#' @examples +#' @examplesIf gh::gh_token() != "" #' verdepcheck:::get_desc_from_gh("tidyverse", "dplyr") #' verdepcheck:::get_desc_from_gh("tidyverse", "dplyr", "v1.1.0") get_desc_from_gh <- function(org, repo, ref = "") { @@ -284,48 +284,72 @@ get_ref_max <- function(remote_ref) { #' #' @importFrom pkgdepends parse_pkg_ref #' @export +#' +#' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" +#' get_ref_release(pkgdepends::parse_pkg_ref("dplyr")) +#' get_ref_release(pkgdepends::parse_pkg_ref("tidyverse/dplyr")) get_ref_release <- function(remote_ref) { + # create list of ref candidates to check + # return the one of the highest version + # this is a named list of character with version values and refs names + ref_candidates <- list() if (check_if_on_cran(remote_ref)) { - return(pkgdepends::parse_pkg_ref(remote_ref$package)) + cran_ref <- remote_ref$package + cran_ver <- get_version(pkgdepends::parse_pkg_ref(cran_ref)) + ref_candidates <- c(ref_candidates, setNames(list(cran_ver), cran_ref)) } if (inherits(remote_ref, "remote_ref_github")) { - if (!is.null(remote_ref$commitish) && remote_ref$commitish != "") { - return(remote_ref) + gh_release_ref <- cond_parse_pkg_ref_release(remote_ref) + if (!is.null(gh_release_ref)) { + gh_release_ver <- get_version(gh_release_ref) + ref_candidates <- c(ref_candidates, setNames(list(gh_release_ver), gh_release_ref$ref)) } - if (!is.null(remote_ref$pull) && remote_ref$pull != "") { - return(remote_ref) + + if ( + (!is.null(remote_ref$commitish) && remote_ref$commitish != "") || + (!is.null(remote_ref$pull) && remote_ref$pull != "") + ) { + gh_ref <- remote_ref + gh_ver <- get_version(gh_ref) + ref_candidates <- c(ref_candidates, setNames(list(gh_ver), gh_ref$ref)) } - if (!is.null(remote_ref$release) && remote_ref$release != "") { - return(cond_parse_pkg_ref_release(remote_ref)) + } else { + input_ref <- remote_ref$ref + input_ver <- get_version(remote_ref) + ref_candidates <- c(ref_candidates, setNames(list(input_ver), input_ref)) + } + + if (length(ref_candidates) == 0 || all(is.na(ref_candidates))) { + return(remote_ref) + } else { + max_ver <- ref_candidates[[1]] + max_ref <- names(ref_candidates[1]) + for (i in seq_along(ref_candidates)) { + i_ver <- ref_candidates[[i]] + i_ref <- names(ref_candidates[i]) + if (!is.na(i_ver) && i_ver > max_ver) { + max_ref <- i_ref + max_ver <- i_ver + } } - return(cond_parse_pkg_ref_release(remote_ref)) + return(pkgdepends::parse_pkg_ref(max_ref)) } - return(remote_ref) } #' @importFrom pkgdepends parse_pkg_ref #' @importFrom remotes github_remote #' @keywords internal cond_parse_pkg_ref_release <- function(remote_ref) { + stopifnot(inherits(remote_ref, "remote_ref_github")) + has_release <- function(remote_ref) { isFALSE(inherits( - try(remotes::github_remote(sprintf("%s/%s@*release", remote_ref$username, remote_ref$repo))), + try(remotes::github_remote(sprintf("%s/%s@*release", remote_ref$username, remote_ref$repo)), silent = TRUE), "try-error" )) } parse_pkg_ref_remote <- function(remote_ref) { - # temporary fix for https://github.com/r-lib/pkgdepends/issues/275#issuecomment-1461787363 - # @TODO: replace it with below one-liner if fixed - # parse_pkg_ref(sprintf("%s/%s@*release", remote_ref$username, remote_ref$repo)) # nolint - pkgdepends::parse_pkg_ref( - sprintf( - "%s=%s/%s@%s", - remote_ref$package, - remote_ref$username, - remote_ref$repo, - remotes::github_remote(sprintf("%s/%s@*release", remote_ref$username, remote_ref$repo))$ref - ) - ) + parse_pkg_ref(sprintf("%s/%s@*release", remote_ref$username, remote_ref$repo)) # nolint } if (has_release(remote_ref)) { @@ -335,79 +359,91 @@ cond_parse_pkg_ref_release <- function(remote_ref) { } } +#' Get package version. +#' +#' @inheritParams get_ref_min +#' @returns Package version created with `package_version`. +#' +#' @export +get_version <- function(remote_ref) { + UseMethod("get_version", remote_ref) +} + +#' @rdname get_version +#' @importFrom pkgdepends new_pkg_deps +#' @export +#' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" +#' get_version(pkgdepends::parse_pkg_ref("dplyr")) +#' get_version(pkgdepends::parse_pkg_ref("tidyverse/dplyr")) +#' get_version(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) +get_version.remote_ref <- function(remote_ref) { + x <- pkgdepends::new_pkg_deps(remote_ref$ref, config = list(dependencies = FALSE)) + x$solve() + if (x$get_solution()$status == "FAILED") { + return(NA) + } else { + as.package_version(x$get_resolution()[1, "version"]) + } +} + + #' Get release date. #' #' @inheritParams get_ref_min -#' @inherit get_ref_min return +#' @returns Date #' #' @export get_release_date <- function(remote_ref) { UseMethod("get_release_date", remote_ref) } -#' Get release date from GitHub references -#' #' @rdname get_release_date -#' @exportS3Method get_release_date remote_ref_github +#' @export #' @importFrom gh gh_gql #' -#' @examplesIf gh::gh_token() != "" -#' remote_ref <- pkgdepends::parse_pkg_ref("tidyverse/dplyr@v1.1.0") -#' get_release_date(remote_ref) +#' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" && gh::gh_token() != "" +#' get_release_date(pkgdepends::parse_pkg_ref("tidyverse/dplyr@v1.1.0")) get_release_date.remote_ref_github <- function(remote_ref) { + x <- pkgdepends::new_pkg_deps(remote_ref$ref, config = list(dependencies = FALSE)) + x$solve() + if (x$get_solution()$status == "FAILED") { + return(as.Date(NA)) + } + + sha <- x$get_resolution()[1, "extra"][[1]]$remotesha + if (is.null(sha)) { + return(as.Date(NA)) + } + gql_query <- sprintf("{ repository(owner: \"%s\", name: \"%s\") { - refs(refPrefix: \"refs/tags/\", query: \"%s\", first: 100) { - edges { - node { - name - target { - ... on Commit { - committedDate - } - } - } + object(oid: \"%s\") { + ... on Commit { + committedDate } } } - }", remote_ref$username, remote_ref$repo, remote_ref$commitish) + }", remote_ref$username, remote_ref$repo, sha) resp <- try(gh::gh_gql(gql_query), silent = TRUE) - if (inherits(resp, "try-error") || is.null(resp$data$repository$refs$edges)) { - return(as.Date(NA_real_)) - } - - result <- vapply( - resp$data$repository$refs$edges, - function(x) { - if (x$node$name != remote_ref$commitish) { - return(as.Date(NA_real_)) - } - as.Date(x$node$target$committedDate) - }, - double(1) - ) - - result <- Filter(function(el) !is.na(el) && !is.null(el), result) - - if (length(result) == 0) { - return(as.Date(NA_real_)) + if (inherits(resp, "try-error") || is.null(resp$data$repository$object$committedDate)) { + return(as.Date(NA)) } - max(as.Date(result)) + as.Date(resp$data$repository$object$committedDate) } #' Get release date from GitHub references #' #' @rdname get_release_date -#' @exportS3Method get_release_date remote_ref_cran +#' @export #' #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" #' remote_ref <- pkgdepends::parse_pkg_ref("dplyr@1.1.0") #' get_release_date.remote_ref_cran(remote_ref) get_release_date.remote_ref_cran <- function(remote_ref) { result <- subset( - get_cran_data(remote_ref$package), + get_release_data(remote_ref$package), package_version(version, strict = FALSE) == package_version(remote_ref$version, strict = FALSE), select = "mtime" )[[1]][1] @@ -424,40 +460,53 @@ get_release_date.remote_ref <- function(remote_ref) { as.Date(NA_real_) } -#' Get CRAN/Bioconductor metadata information on packages +#' Get data for CRAN/Bioconductor package releases #' #' @importFrom pkgcache cran_archive_list meta_cache_list +#' @importFrom jsonlite fromJSON +#' #' @keywords internal #' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" -#' verdepcheck:::get_cran_data("dplyr") -#' verdepcheck:::get_cran_data("SummarizedExperiment") -get_cran_data <- function(package) { - cran_archive <- pkgcache::cran_archive_list(packages = package)[, c( - "package", "version", "mtime" - )] - cran_current <- pkgcache::meta_cache_list(packages = package)[, c( - "type", "package", "version", "published" - )] - if (all(is.na(cran_current$published))) { - # workaround of https://github.com/r-lib/pkgcache/issues/109 - if (is.null(pkgenv$cache_db)) { - pkgenv$cache_db <- tools::CRAN_package_db() - } - db <- subset(pkgenv$cache_db, Package == package) - cran_current <- data.frame( - type = "cran", - package = package, - version = db$Version, - published = as.POSIXct(db$`Date/Publication`) - ) - } +#' verdepcheck:::get_release_data("dplyr") +#' verdepcheck:::get_release_data("SummarizedExperiment") +get_release_data <- function(package) { + cran_archive <- pkgcache::cran_archive_list(packages = package)[, c("package", "version", "mtime")] + cran_current <- head( + pkgcache::meta_cache_list(packages = package)[, c("type", "package", "version", "published")], + 1 + ) - # Bioc custom logic as packages in Bioconductor do not return a published date - # this will be immediately obsolete if {pkgcache} starts to return a non-NA value - # note: a date is required for the `min_cohort` strategy - bioc_na_mtime_ix <- is.na(cran_current$published) & cran_current$type == "bioc" - if (NROW(cran_current[bioc_na_mtime_ix, ]) > 0) { - cran_current[bioc_na_mtime_ix, "published"] <- Sys.Date() + # handle missing dates + if (nrow(cran_current > 0)) { + if (is.na(cran_current$published)) { + if (cran_current$type == "cran") { + # in general, this should not happen for cran - https://github.com/r-lib/pkgcache/issues/109 + # this is a temporary workaround + if (is.null(pkgenv$cache_db)) { + pkgenv$cache_db <- tools::CRAN_package_db() + } + db <- subset(pkgenv$cache_db, pkgenv$cache_db$Package == package) + cran_current <- data.frame( + type = "cran", + package = package, + version = db$Version[1], + published = as.POSIXct(db$`Date/Publication`[1]) + ) + } else if (cran_current$type == "bioc") { + url <- sprintf( + "https://packagemanager.posit.co/__api__/repos/4/packages/%s?bioc_version=%s", + package, + pkgcache::bioc_version() + ) + release_date <- as.POSIXct(jsonlite::fromJSON(readLines(url, warn = FALSE))$occurred) + cran_current <- data.frame( + type = "bioc", + package = package, + version = cran_current$version, + published = release_date + ) + } + } } # Remove extra columns diff --git a/R/solve.R b/R/solve.R index 2fd25c1a..9b5d9185 100644 --- a/R/solve.R +++ b/R/solve.R @@ -9,7 +9,7 @@ solve_ip <- function(ip) { UseMethod("solve_ip", ip) } -#' @exportS3Method solve_ip deps_installation_proposal +#' @export solve_ip.deps_installation_proposal <- function(ip) { ip$solve() resolve_ignoring_release_remote(ip) @@ -24,7 +24,7 @@ solve_ip.deps_installation_proposal <- function(ip) { #' #' @importFrom stats na.omit #' -#' @exportS3Method solve_ip min_isolated_deps_installation_proposal +#' @export solve_ip.min_isolated_deps_installation_proposal <- function(ip) { # nolint ip$resolve() res <- ip$get_resolution() @@ -71,6 +71,11 @@ solve_ip.min_isolated_deps_installation_proposal <- function(ip) { # nolint new_res <- do.call(rbind, deps_res) + if (is.null(new_res)) { + ip$solve() + return(invisible(ip)) + } + # Keep only top versions in calculated resolution (new_res). # Very large resolution tables can become problematic and take a long to # converge to a solution. diff --git a/R/utils.R b/R/utils.R index 94d79282..89f44219 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,11 +10,12 @@ pkgenv <- new.env(parent = emptyenv()) default_config <- function() { list( dependencies = c(.desc_field, pkgdepends::as_pkg_dependencies(TRUE)$direct), + cran_mirror = pkgcache::repo_resolve("PPM@latest"), library = tempfile() ) } append_config <- function(x1, x2) { - append(x1, x2)[unique(c(names(x1), names(x2)))] + modifyList(x1, x2) } #' @importFrom utils installed.packages @@ -30,35 +31,25 @@ base_pkgs <- function() { #' get_ppm_snapshot_by_date("2023-08-01") #' get_ppm_snapshot_by_date(Sys.Date() + 10) get_ppm_snapshot_by_date <- function(date) { - fallback_repo <- file.path(pkgcache::ppm_repo_url(), "latest") - if (is.na(date) || is.infinite(date)) { - return(fallback_repo) - } - - snaps <- pkgcache::ppm_snapshots() - res <- as.character(as.Date(utils::head( - snaps[as.Date(snaps$date) > as.Date(date), "date"], - 1 - ))) - if (length(res) == 0) { - warning(sprintf( - paste0( - "Cannot find PPM snapshot for date after %s.", - " Will use latest ppm snapshot instead." - ), - as.character(date) - )) - return(fallback_repo) - } - parse_ppm_url(res) -} - -#' @importFrom pkgcache ppm_repo_url -parse_ppm_url <- function(snapshot) { - file.path(pkgcache::ppm_repo_url(), snapshot) + tryCatch( + { + # https://github.com/r-lib/pkgcache/issues/110 + # uncomment this: pkgcache::repo_resolve(sprintf("PPM@%s", as.character(as.Date(date) + 1))) + snaps <- pkgcache::ppm_snapshots() + date_snap <- as.character(head(snaps[as.Date(snaps$date) > as.Date(date), "date"], 1)) + if (length(date_snap) == 0) { + stop("No PPM snapshot found for the given date.") + } + file.path(pkgcache::ppm_repo_url(), date_snap) + gsub("latest", date_snap, pkgcache::repo_resolve("PPM@latest")) + }, + error = function(err) { + pkgcache::repo_resolve("PPM@latest") + } + ) } -#' Resolve the dependencies of package based on the release date + 1 +#' Resolve the dependencies of a package based on its release date + 1. #' #' @importFrom pkgdepends new_pkg_deps parse_pkg_ref #' @keywords internal @@ -86,7 +77,7 @@ resolve_ppm_snapshot <- function(pkg_ref_str, operator, pkg_version) { i_res } -#' Create `cli` progress bar for resolving versions. +#' Create `cli` progress bar to print status to the console. #' @importFrom cli col_blue col_yellow cli_progress_bar col_green pb_current pb_elapsed pb_eta pb_extra #' pb_spin pb_total style_bold symbol #' @keywords internal @@ -168,7 +159,7 @@ local_description <- function(pkg_list = c(pkgdepends = "Import"), #' Support function to reduce repetitive code #' #' @param x (`list`) list of lists where each internal list contain the same key -#' @param field (`character(1)`) key of field to retrieve +#' @param key (`character(1)`) key of field to retrieve #' #' @keywords internal #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 98a8849f..124a04b8 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -35,3 +35,4 @@ reference: contents: - starts_with("get_ref_") - get_release_date + - get_version diff --git a/man/cli_pb_init.Rd b/man/cli_pb_init.Rd index 62a5daa9..85fd0d9d 100644 --- a/man/cli_pb_init.Rd +++ b/man/cli_pb_init.Rd @@ -2,11 +2,11 @@ % Please edit documentation in R/utils.R \name{cli_pb_init} \alias{cli_pb_init} -\title{Create \code{cli} progress bar for resolving versions.} +\title{Create \code{cli} progress bar to print status to the console.} \usage{ cli_pb_init(type, total, ...) } \description{ -Create \code{cli} progress bar for resolving versions. +Create \code{cli} progress bar to print status to the console. } \keyword{internal} diff --git a/man/get_desc_from_gh.Rd b/man/get_desc_from_gh.Rd index 2bf134a7..2122706a 100644 --- a/man/get_desc_from_gh.Rd +++ b/man/get_desc_from_gh.Rd @@ -10,7 +10,9 @@ get_desc_from_gh(org, repo, ref = "") Get DESCRIPTION from GitHub Repository } \examples{ +\dontshow{if (gh::gh_token() != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} verdepcheck:::get_desc_from_gh("tidyverse", "dplyr") verdepcheck:::get_desc_from_gh("tidyverse", "dplyr", "v1.1.0") +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/get_ref_min.Rd b/man/get_ref_min.Rd index e81310bb..dd630224 100644 --- a/man/get_ref_min.Rd +++ b/man/get_ref_min.Rd @@ -42,15 +42,15 @@ and then \code{\link[gh:gh]{gh::gh()}} to download \code{DESCRIPTION} file and t } } \examples{ -verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) +get_ref_min(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) \dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("cran::dplyr")) +get_ref_min(pkgdepends::parse_pkg_ref("cran::dplyr")) \dontshow{\}) # examplesIf} \dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("dplyr")) +get_ref_min(pkgdepends::parse_pkg_ref("dplyr")) \dontshow{\}) # examplesIf} \dontshow{if (gh::gh_token() != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -verdepcheck:::get_ref_min(pkgdepends::parse_pkg_ref("cran/dplyr")) +get_ref_min(pkgdepends::parse_pkg_ref("cran/dplyr")) \dontshow{\}) # examplesIf} } \seealso{ diff --git a/man/get_ref_release.Rd b/man/get_ref_release.Rd index d7bcd39c..21d92028 100644 --- a/man/get_ref_release.Rd +++ b/man/get_ref_release.Rd @@ -15,3 +15,9 @@ get_ref_release(remote_ref) \description{ Get reference to the release version of the package. } +\examples{ +\dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +get_ref_release(pkgdepends::parse_pkg_ref("dplyr")) +get_ref_release(pkgdepends::parse_pkg_ref("tidyverse/dplyr")) +\dontshow{\}) # examplesIf} +} diff --git a/man/get_cran_data.Rd b/man/get_release_data.Rd similarity index 52% rename from man/get_cran_data.Rd rename to man/get_release_data.Rd index 34e6f37d..3860b7fb 100644 --- a/man/get_cran_data.Rd +++ b/man/get_release_data.Rd @@ -1,18 +1,18 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_ref.R -\name{get_cran_data} -\alias{get_cran_data} -\title{Get CRAN/Bioconductor metadata information on packages} +\name{get_release_data} +\alias{get_release_data} +\title{Get data for CRAN/Bioconductor package releases} \usage{ -get_cran_data(package) +get_release_data(package) } \description{ -Get CRAN/Bioconductor metadata information on packages +Get data for CRAN/Bioconductor package releases } \examples{ \dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -verdepcheck:::get_cran_data("dplyr") -verdepcheck:::get_cran_data("SummarizedExperiment") +verdepcheck:::get_release_data("dplyr") +verdepcheck:::get_release_data("SummarizedExperiment") \dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/get_release_date.Rd b/man/get_release_date.Rd index d36fe28f..47beab33 100644 --- a/man/get_release_date.Rd +++ b/man/get_release_date.Rd @@ -16,19 +16,16 @@ get_release_date(remote_ref) \item{remote_ref}{(\code{remote_ref}) object created with \code{\link[pkgdepends:parse_pkg_refs]{pkgdepends::parse_pkg_ref()}}} } \value{ -(\code{remote_ref}) object with the package reference +Date } \description{ Get release date. -Get release date from GitHub references - Get release date from GitHub references } \examples{ -\dontshow{if (gh::gh_token() != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -remote_ref <- pkgdepends::parse_pkg_ref("tidyverse/dplyr@v1.1.0") -get_release_date(remote_ref) +\dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "" && gh::gh_token() != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +get_release_date(pkgdepends::parse_pkg_ref("tidyverse/dplyr@v1.1.0")) \dontshow{\}) # examplesIf} \dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} remote_ref <- pkgdepends::parse_pkg_ref("dplyr@1.1.0") diff --git a/man/get_version.Rd b/man/get_version.Rd new file mode 100644 index 00000000..1a668b01 --- /dev/null +++ b/man/get_version.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_ref.R +\name{get_version} +\alias{get_version} +\alias{get_version.remote_ref} +\title{Get package version.} +\usage{ +get_version(remote_ref) + +\method{get_version}{remote_ref}(remote_ref) +} +\arguments{ +\item{remote_ref}{(\code{remote_ref}) object created with \code{\link[pkgdepends:parse_pkg_refs]{pkgdepends::parse_pkg_ref()}}} +} +\value{ +Package version created with \code{package_version}. +} +\description{ +Get package version. +} +\examples{ +\dontshow{if (Sys.getenv("R_USER_CACHE_DIR", "") != "") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +get_version(pkgdepends::parse_pkg_ref("dplyr")) +get_version(pkgdepends::parse_pkg_ref("tidyverse/dplyr")) +get_version(pkgdepends::parse_pkg_ref("bioc::MultiAssayExperiment")) +\dontshow{\}) # examplesIf} +} diff --git a/man/map_key_character.Rd b/man/map_key_character.Rd index 05e6c552..f89fd78e 100644 --- a/man/map_key_character.Rd +++ b/man/map_key_character.Rd @@ -10,7 +10,7 @@ map_key_character(x, key) \arguments{ \item{x}{(\code{list}) list of lists where each internal list contain the same key} -\item{field}{(\code{character(1)}) key of field to retrieve} +\item{key}{(\code{character(1)}) key of field to retrieve} } \description{ Support function to reduce repetitive code diff --git a/man/resolve_ppm_snapshot.Rd b/man/resolve_ppm_snapshot.Rd index 11b8613c..977c3ec5 100644 --- a/man/resolve_ppm_snapshot.Rd +++ b/man/resolve_ppm_snapshot.Rd @@ -2,11 +2,11 @@ % Please edit documentation in R/utils.R \name{resolve_ppm_snapshot} \alias{resolve_ppm_snapshot} -\title{Resolve the dependencies of package based on the release date + 1} +\title{Resolve the dependencies of a package based on its release date + 1.} \usage{ resolve_ppm_snapshot(pkg_ref_str, operator, pkg_version) } \description{ -Resolve the dependencies of package based on the release date + 1 +Resolve the dependencies of a package based on its release date + 1. } \keyword{internal} diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 30d14488..4defb0fa 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -30,8 +30,6 @@ skip_if_empty_gh_token <- function() { #' @param x (`pkg_installation_proposal` object) Valid proposal created by one #' of the available methods. #' @param pkg_name (`string`) Name of package that is being tested for version. -#' @param platform (optional `string`) Name of the platform, should be 'source' in -#' most cases. #' @param pkg_ver_target (optional `string`) version that is expected to be in the #' proposal. A `NULL` value indicates to use the latest version on CRAN or a #' GitHub repository reference @@ -45,7 +43,6 @@ skip_if_empty_gh_token <- function() { #' @keywords internal test_proposal_common <- function(x, pkg_name = "pkgdepends", - platform = "source", pkg_ver_target = NULL, pkg_gh_str = NULL, solve_ip_flag = TRUE) { @@ -60,7 +57,7 @@ test_proposal_common <- function(x, x_solution_pkg <- subset( x_solution, - package == pkg_name & platform == "source" + package == pkg_name ) expect_true(nrow(x_solution_pkg) >= 1) @@ -95,7 +92,6 @@ test_proposal_common <- function(x, #' @keywords internal test_proposal_common_bioc <- function(x, pkg_name = "pkgdepends", - platform = "source", solve_ip_flag = TRUE) { expect_s3_class(x, "pkg_installation_proposal") @@ -108,7 +104,7 @@ test_proposal_common_bioc <- function(x, x_solution_pkg <- subset( x_solution, - package == pkg_name & platform == "source" + package == pkg_name ) expect_true(nrow(x_solution_pkg) >= 1) diff --git a/tests/testthat/setup-options.R b/tests/testthat/setup-options.R new file mode 100644 index 00000000..78be1f9b --- /dev/null +++ b/tests/testthat/setup-options.R @@ -0,0 +1,20 @@ +# `opts_partial_match_old` is left for exclusions due to partial matching in dependent packages (i.e. not fixable here) +# it might happen that it is not used right now, but it is left for possible future use +# use with: `withr::with_options(opts_partial_match_old, { ... })` inside the test +opts_partial_match_old <- list( + warnPartialMatchDollar = getOption("warnPartialMatchDollar"), + warnPartialMatchArgs = getOption("warnPartialMatchArgs"), + warnPartialMatchAttr = getOption("warnPartialMatchAttr") +) +opts_partial_match_new <- list( + warnPartialMatchDollar = TRUE, + warnPartialMatchArgs = TRUE, + warnPartialMatchAttr = TRUE +) + +if (isFALSE(getFromNamespace("on_cran", "testthat")()) && requireNamespace("withr", quietly = TRUE)) { + withr::local_options( + opts_partial_match_new, + .local_envir = testthat::teardown_env() + ) +} diff --git a/tests/testthat/test-deps_installation_proposal.R b/tests/testthat/test-deps_installation_proposal.R index aa21d985..8eb903bc 100644 --- a/tests/testthat/test-deps_installation_proposal.R +++ b/tests/testthat/test-deps_installation_proposal.R @@ -6,7 +6,7 @@ test_that("new_max_deps_installation_proposal correctly handles standard referen x <- new_max_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, NULL) + test_proposal_common(x, "pkgdepends", NULL, NULL) }) test_that("new_release_deps_installation_proposal correctly handles standard reference", { @@ -17,7 +17,7 @@ test_that("new_release_deps_installation_proposal correctly handles standard ref x <- new_release_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, NULL) + test_proposal_common(x, "pkgdepends", NULL, NULL) }) test_that("new_min_isolated_installation_proposal correctly handles standard reference", { @@ -28,7 +28,7 @@ test_that("new_min_isolated_installation_proposal correctly handles standard ref x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.1.0", NULL) + test_proposal_common(x, "pkgdepends", "0.1.0", NULL) }) test_that("new_min_cohort_deps_installation_proposal correctly handles standard reference", { @@ -39,7 +39,7 @@ test_that("new_min_cohort_deps_installation_proposal correctly handles standard x <- new_min_cohort_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.1.0", NULL) + test_proposal_common(x, "pkgdepends", "0.1.0", NULL) }) # ################################################################# @@ -69,7 +69,7 @@ test_that("new_max_deps_installation_proposal correctly handles / ref x <- new_max_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, remote_str) + test_proposal_common(x, "pkgdepends", NULL, remote_str) }) test_that("new_max_deps_installation_proposal correctly handles /@*release reference", { @@ -85,7 +85,7 @@ test_that("new_max_deps_installation_proposal correctly handles /@*re x <- new_max_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, remote_str) + test_proposal_common(x, "pkgdepends", NULL, remote_str) }) test_that("new_max_deps_installation_proposal correctly handles /@ ref. (particular remote tag)", { @@ -101,7 +101,7 @@ test_that("new_max_deps_installation_proposal correctly handles /@/ ref. (without Config/Need/verdpcheck)", { @@ -113,7 +113,7 @@ test_that("new_max_deps_installation_proposal correctly handles / ref x <- new_max_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, remote_str) + test_proposal_common(x, "pkgdepends", NULL, remote_str) }) test_that("new_release_deps_installation_proposal correctly handles / reference", { @@ -125,7 +125,7 @@ test_that("new_release_deps_installation_proposal correctly handles / x <- new_release_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", NULL, NULL) + test_proposal_common(x, "pkgdepends", NULL, NULL) }) test_that("new_min_cohort_deps_installation_proposal correctly handles / reference", { @@ -137,7 +137,7 @@ test_that("new_min_cohort_deps_installation_proposal correctly handles // reference", { @@ -154,7 +154,7 @@ test_that("new_min_deps_installation_proposal correctly handles / ref x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.1.0", NULL) + test_proposal_common(x, "pkgdepends", "0.1.0", NULL) }) # ################################################################ @@ -179,7 +179,7 @@ test_that("new_min_isolated_deps_installation_proposal correctly handles \">=\" x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.2.0", NULL) + test_proposal_common(x, "pkgdepends", "0.2.0", NULL) }) test_that("new_min_isolated_deps_installation_proposal correctly handles \">=\" dependency for standard reference", { @@ -190,7 +190,7 @@ test_that("new_min_isolated_deps_installation_proposal correctly handles \">=\" x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.2.0", NULL) + test_proposal_common(x, "pkgdepends", "0.2.0", NULL) }) test_that("new_min_cohort_deps_installation_proposal correctly handles \">=\" dependency for / reference", { @@ -201,7 +201,7 @@ test_that("new_min_cohort_deps_installation_proposal correctly handles \">=\" de x <- new_min_cohort_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.2.0", NULL) + test_proposal_common(x, "pkgdepends", "0.2.0", NULL) }) test_that("new_min_cohort_deps_installation_proposal correctly handles \">=\" dependency for standard reference", { @@ -212,7 +212,7 @@ test_that("new_min_cohort_deps_installation_proposal correctly handles \">=\" de x <- new_min_cohort_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - test_proposal_common(x, "pkgdepends", "source", "0.2.0", NULL) + test_proposal_common(x, "pkgdepends", "0.2.0", NULL) }) test_that("new_min_isolated_deps_installation_proposal correctly handles tern and rtables", { @@ -234,9 +234,9 @@ test_that("new_min_isolated_deps_installation_proposal correctly handles tern an x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - x <- test_proposal_common(x, "tern", "source", "0.8.3", NULL) - x <- test_proposal_common(x, "rtables", "source", "0.6.1", NULL, solve_ip = FALSE) - test_proposal_common(x, "formatters", "source", "0.5.0", NULL, solve_ip = FALSE) + test_proposal_common(x, "tern", "0.8.3", NULL) + test_proposal_common(x, "rtables", "0.6.1", NULL, solve_ip_flag = FALSE) + test_proposal_common(x, "formatters", "0.5.0", NULL, solve_ip_flag = FALSE) }) # Test for encapsulation isssue where another dependency (primary or in the tree) @@ -258,9 +258,9 @@ test_that("new_min_isolated_deps_installation_proposal correctly resolves a diff x <- new_min_isolated_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) - x <- test_proposal_common(x, "tern", "source", "0.8.3", NULL) - x <- test_proposal_common(x, "rtables", "source", "0.6.1", NULL, solve_ip = FALSE) - test_proposal_common(x, "formatters", "source", "0.5.0", NULL, solve_ip = FALSE) + test_proposal_common(x, "tern", "0.8.3", NULL) + test_proposal_common(x, "rtables", "0.6.1", NULL, solve_ip_flag = FALSE) + test_proposal_common(x, "formatters", "0.5.0", NULL, solve_ip_flag = FALSE) }) # ################################################################# @@ -289,10 +289,7 @@ test_that("new_min_cohort_deps_installation_proposal correctly handles Bioc pack d_std_path <- local_description(list(SummarizedExperiment = "Import")) - expect_warning( - x <- new_min_cohort_deps_installation_proposal(d_std_path), - "Cannot find PPM snapshot" - ) + x <- new_min_cohort_deps_installation_proposal(d_std_path) withr::defer(unlink(x$get_config()$library)) @@ -309,10 +306,7 @@ test_that("new_min_isolated_deps_installation_proposal correctly handles Bioc pa withr::defer(unlink(x$get_config()$library)) - expect_warning( - test_proposal_common_bioc(x, "SummarizedExperiment"), - "Cannot find PPM snapshot" - ) + test_proposal_common_bioc(x, "SummarizedExperiment") }) test_that("new_release_deps_installation_proposal correctly handles Bioc package", { diff --git a/tests/testthat/test-get_ref.R b/tests/testthat/test-get_ref.R index 6c5ac605..70cd32ed 100644 --- a/tests/testthat/test-get_ref.R +++ b/tests/testthat/test-get_ref.R @@ -24,7 +24,7 @@ test_that("get_release_date.remote_ref_github will only retrieve 1 date for rlan expect_identical(as.Date(result), as.Date("2022-01-20T16:47:02Z")) }) -test_that("get_release_date.remote_ref_github will retrieve missing date (NA) for rlang@0.0.0", { +test_that("get_release_date.remote_ref_github will retrieve missing date (NA) for r-lib/rlang@v0.0.0", { skip_if_offline() skip_if_empty_gh_token() @@ -37,7 +37,7 @@ test_that("get_release_date.remote_ref_github will retrieve missing date (NA) fo expect_s3_class(result, "Date") }) -test_that("get_release_date.remote_ref_cran will retrieve missing date (NA) for rlang@0.0.0", { +test_that("get_release_date.remote_ref_cran will retrieve missing date (NA) for package.does.not.exist@1.1.0", { skip_if_offline() skip_if_empty_gh_token() @@ -62,10 +62,10 @@ test_that("get_release_date with any class other than remote_ref.{github,cran,st expect_s3_class(result, "Date") }) -test_that("get_cran_data returns date for Bioconductor", { +test_that("get_release_data returns date for Bioconductor", { skip_if_offline() - expect_false(any(is.na(get_cran_data("SummarizedExperiment")$mtime))) + expect_false(any(is.na(get_release_data("SummarizedExperiment")$mtime))) }) test_that("get_ref_release returns a CRAN remote_reference if package exists", { diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 1e30911d..6bf3a044 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -101,10 +101,7 @@ test_that("get_ppm_snapshot_by_date will accept NA", { test_that("get_ppm_snapshot_by_date will accept dates in the future", { skip_if_offline() auxiliary_fun <- function(days = 0) { - expect_warning( - expect_latest_ppm(get_ppm_snapshot_by_date(Sys.Date())), - "Cannot find PPM snapshot for date" - ) + expect_latest_ppm(get_ppm_snapshot_by_date(Sys.Date())) } auxiliary_fun(0)