Skip to content

Commit

Permalink
Improve names and infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed May 24, 2024
1 parent 1e0250d commit 50be3cd
Show file tree
Hide file tree
Showing 29 changed files with 385 additions and 305 deletions.
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export(aggregate_contributions)
export(assert_cran_url)
export(assert_package)
export(assert_release_exists)
export(check_checks)
export(check_descriptions)
export(check_versions)
export(get_current_versions)
export(issues_checks)
export(issues_descriptions)
export(issues_versions)
export(meta_checks)
export(meta_packages)
export(record_issues)
export(record_versions)
export(review_pull_request)
Expand Down
45 changes: 0 additions & 45 deletions R/check_checks.R

This file was deleted.

43 changes: 0 additions & 43 deletions R/check_descriptions.R

This file was deleted.

40 changes: 40 additions & 0 deletions R/issues_checks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' @title Report issues from R-universe package check results.
#' @export
#' @family issues
#' @description Check R-universe package check results.
#' @details [issues_checks()] function scrapes the R-universe check API
#' to scan all R-multiverse packages for issues that may have
#' happened during building and testing.
#' @inheritSection record_issues Package issues
#' @return A named list of information about packages which do not comply
#' with `DESCRPTION` checks. Each name is a package name,
#' and each element contains specific information about
#' non-compliance.
#' @param meta A data frame with R-universe package check results
#' returned by [meta_checks()].
#' @examples
#' meta <- meta_checks(repo = "https://wlandau.r-universe.dev")
#' issues <- issues_checks(meta = meta)
#' str(issues)
issues_checks <- function(meta) {
fields_check <- c(
"_linuxdevel",
"_macbinary",
"_wasmbinary",
"_winbinary",
"_status"
)
fields_info <- c(
"_buildurl"
)
fields <- c(fields_check, fields_info)
for (field in fields) {
meta[[field]][is.na(meta[[field]])] <- "src-failure"
}
success <- rep(TRUE, nrow(meta))
for (field in fields_check) {
success <- success & (meta[[field]] %in% c("success", "skipped"))
}
meta <- meta[!success,, drop = FALSE] # nolint
issues_list(meta[, c("package", fields)])
}
33 changes: 33 additions & 0 deletions R/issues_descriptions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' @title Check package `DESCRIPTION` files.
#' @export
#' @family issues
#' @description Check the `DESCRIPTION` files of packages for specific
#' issues.
#' @details This function scrapes the `src/contrib/PACKAGES.json` file
#' of the universe to check the data in the `DESCRIPTION` files of packages
#' for compliance. Right now, the only field checked is `Remotes:`.
#' A packages with a `Remotes:` field in the `DESCRIPTION` file may
#' depend on development versions of other packages and so are
#' excluded from the production universe.
#' @inheritSection record_issues Package issues
#' @return A named list of information about packages which do not comply
#' with `DESCRPTION` checks. Each name is a package name,
#' and each element contains specific information about
#' non-compliance.
#' @param meta A data frame of package metadata returned by [meta_packages()].
#' @examples
#' meta <- meta_packages(repo = "https://wlandau.r-universe.dev")
#' issues <- issues_descriptions(meta = meta)
#' str(issues)
issues_descriptions <- function(meta) {
meta <- issues_descriptions_remotes(meta)
fields <- "remotes"
meta <- meta[, c("package", fields)]
issues_list(meta)
}

issues_descriptions_remotes <- function(meta) {
meta$remotes <- meta$remotes %|||% replicate(nrow(meta), NULL)
meta$remotes <- lapply(meta$remotes, function(x) x[nzchar(x)])
meta[vapply(meta$remotes, length, integer(1L)) > 0L, ]
}
10 changes: 5 additions & 5 deletions R/check_versions.R → R/issues_versions.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' @title Check package versions.
#' @export
#' @family package checks for production
#' @family issues
#' @description Check package version number history for compliance.
#' @details This function checks the version number history of packages
#' in R-multiverse and reports any packages with issues. The current
#' released version of a given package must be unique, and it must be
#' greater than all the versions of all the previous package releases.
#' @inheritSection record_issues Package checks for production
#' @inheritSection record_issues Package issues
#' @return A named list of information about packages which do not comply
#' with version number history checks. Each name is a package name,
#' and each element contains specific information about version
Expand Down Expand Up @@ -51,13 +51,13 @@
#' )
#' versions <- tempfile()
#' writeLines(lines, versions)
#' out <- check_versions(versions)
#' out <- issues_versions(versions)
#' str(out)
check_versions <- function(versions) {
issues_versions <- function(versions) {
history <- jsonlite::read_json(path = versions, simplifyVector = TRUE)
aligned <- (history$version_current == history$version_highest) &
(history$hash_current == history$hash_highest)
aligned[is.na(aligned)] <- TRUE
out <- history[!aligned,, drop = FALSE] # nolint
check_list(out)
issues_list(out)
}
35 changes: 35 additions & 0 deletions R/meta_checks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' @title List metadata about R-universe package checks
#' @export
#' @family list
#' @description List package checks results reported by the
#' R-universe package API.
#' @return A data frame with one row per package and columns with
#' package check results.
#' @param repo Character of length 1, URL of the package repository.
#' R-multiverse uses `"https://multiverse.r-multiverse.org"`.
#' @examples
#' meta_checks(repo = "https://wlandau.r-universe.dev")
meta_checks <- function(repo = "https://multiverse.r-multiverse.org") {
fields <- c(
"_buildurl",
"_linuxdevel",
"_macbinary",
"_wasmbinary",
"_winbinary",
"_status"
)
listing <- file.path(
repo,
"api",
paste0("packages?stream=true&fields=", paste(fields, collapse = ","))
)
out <- jsonlite::stream_in(
con = gzcon(url(listing)),
verbose = FALSE,
simplifyVector = TRUE,
simplifyDataFrame = TRUE,
simplifyMatrix = TRUE
)
colnames(out) <- tolower(colnames(out))
out
}
25 changes: 25 additions & 0 deletions R/meta_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' @title List package metadata
#' @export
#' @family meta
#' @description List package metadata in an R universe.
#' @return A data frame with one row per package and columns with package
#' metadata.
#' @inheritParams meta_checks
#' @examples
#' meta_packages(repo = "https://wlandau.r-universe.dev")
meta_packages <- function(repo = "https://multiverse.r-multiverse.org") {
fields <- c("Version", "Remotes", "RemoteSha")
listing <- file.path(
contrib.url(repos = repo, type = "source"),
paste0("PACKAGES.json?fields=", paste(fields, collapse = ","))
)
out <- jsonlite::stream_in(
con = gzcon(url(listing)),
verbose = FALSE,
simplifyVector = TRUE,
simplifyDataFrame = TRUE,
simplifyMatrix = TRUE
)
colnames(out) <- tolower(colnames(out))
out
}
28 changes: 15 additions & 13 deletions R/record_issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#' @keywords package check data management
#' @description Record R-multiverse package issues in
#' package-specific JSON files.
#' @section Package checks for production:
#' Functions like [check_versions()] and [check_descriptions()]
#' @section Package issues:
#' Functions like [issues_versions()] and [issues_descriptions()]
#' perform health checks for all packages in R-multiverse.
#' Only packages that pass these checks go to the production repository at
#' <https://production.r-multiverse.org>. For a complete list of checks, see
#' the `check_*()` functions listed at
#' the `issues_*()` functions listed at
#' <https://r-multiverse.org/multiverse.internals/reference.html>.
#' [record_versions()] updates the version number history
#' of releases in R-multiverse, and [record_issues()] gathers
Expand All @@ -24,16 +24,16 @@
#' an issue was first noticed. It automatically resets the next time
#' all package are resolved.
#' @return `NULL` (invisibly).
#' @inheritParams check_checks
#' @inheritParams check_versions
#' @inheritParams meta_checks
#' @inheritParams issues_checks
#' @inheritParams issues_versions
#' @param output Character of length 1, file path to the folder to record
#' new package issues. Each call to `record_issues()` overwrites the
#' contents of the repo.
#' @param mock For testing purposes only, a named list of data frames
#' for the `mock` argument of each type of check.
#' for inputs to various intermediate functions.
#' @examples
#' # R-multiverse uses https://multiverse.r-multiverse.org as the repo.
#' repo <- "https://wlandau.r-universe.dev" # just for testing and examples
#' repo <- "https://wlandau.r-universe.dev"
#' output <- tempfile()
#' versions <- tempfile()
#' record_versions(
Expand Down Expand Up @@ -61,15 +61,17 @@ record_issues <- function(
mock = NULL
) {
today <- mock$today %|||% format(Sys.Date(), fmt = "yyyy-mm-dd")
list() |>
issues(check_checks(repo, mock$checks), "checks") |>
issues(check_descriptions(repo, mock$descriptions), "descriptions") |>
issues(check_versions(versions = versions), "versions") |>
checks <- mock$checks %|||% meta_checks(repo = repo)
packages <- mock$packages %|||% meta_packages(repo = repo)
issues <- list() |>
add_issues(issues_checks(meta = checks), "checks") |>
add_issues(issues_descriptions(meta = packages), "descriptions") |>
add_issues(issues_versions(versions = versions), "versions") |>
overwrite_issues(output = output, today = today)
invisible()
}

issues <- function(total, subset, category) {
add_issues <- function(total, subset, category) {
for (package in names(subset)) {
total[[package]][[category]] <- subset[[package]]
}
Expand Down
14 changes: 7 additions & 7 deletions R/record_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#' @details This function tracks a manifest containing the current version,
#' the current hash, the highest version ever released, and
#' the hash of the highest version ever released.
#' [check_versions()] uses this information
#' [issues_versions()] uses this information
#' to determine whether the package complies with best
#' practices for version numbers.
#' @inheritSection record_issues Package checks for production
#' @inheritSection record_issues Package issues
#' @return `NULL` (invisibly). Writes a package version manifest
#' and a manifest of version issues as JSON files.
#' @param versions Character of length 1, file path to a JSON manifest
Expand Down Expand Up @@ -61,11 +61,11 @@ record_versions <- function(
get_current_versions <- function(
repo = "https://multiverse.r-multiverse.org"
) {
index <- get_package_index(repo = repo, fields = "RemoteSha")
index <- index[, c("Package", "Version", "RemoteSha")]
colnames(index) <- c("package", "version_current", "hash_current")
rownames(index) <- NULL
index
meta <- meta_packages(repo = repo)
meta <- meta[, c("package", "version", "remotesha")]
colnames(meta) <- c("package", "version_current", "hash_current")
rownames(meta) <- NULL
meta
}

read_versions_previous <- function(versions) {
Expand Down
Loading

0 comments on commit 50be3cd

Please sign in to comment.