-
Notifications
You must be signed in to change notification settings - Fork 1
Various enhancements to support reporting #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e87eda1
47956b2
ee8c6e7
58b1f1d
0d888f3
018f70d
cd1bd91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,11 @@ pkg <- class_pkg <- new_class( | |
| # necessary data dependencies to be evaluated. | ||
| data = class_environment, | ||
|
|
||
| # logs (not user-facing) | ||
| # A mutable environment, stores output logs captured using the `evaluate` | ||
| # package. Should contain an entry for each value in `@data`. | ||
| logs = class_environment, | ||
|
|
||
| #' @param resource [`resource`] (often a [`multi_resource`]), providing the | ||
| #' resources to be used for deriving packages data. If a | ||
| #' [`multi_resource`], the order of resources determines the precedence of | ||
|
|
@@ -62,13 +67,25 @@ pkg <- class_pkg <- new_class( | |
| new_object( | ||
| .parent = S7::S7_object(), | ||
| data = new.env(parent = emptyenv()), | ||
| logs = new.env(parent = emptyenv()), | ||
| metrics = list(), | ||
| resource = resource, | ||
| permissions = policy@permissions | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| method(convert, list(class_character, class_pkg)) <- | ||
| function(from, to, ...) { | ||
| if (endsWith(tolower(from), ".rds")) { | ||
| convert(readRDS(from), class_pkg) | ||
| } else if (grepl("\\bPackage:", from[[1L]])) { | ||
| pkg_from_dcf(from, ...) | ||
| } else { | ||
| pkg(from, ...) | ||
| } | ||
| } | ||
|
|
||
| #' Generate Random Package(s) | ||
| #' | ||
| #' Create a package object to simulate metric derivation. When generating a | ||
|
|
@@ -179,6 +196,8 @@ random_repo <- function(..., path = tempfile("repo")) { | |
| #' @param x [`pkg`] object to derive data for | ||
| #' @param name `character(1L)` field name for the data to derive | ||
| #' @param ... Additional arguments unused | ||
| #' @param logs `logical(1L)` flag indicating whether console output should be | ||
| #' captured during execution. | ||
| #' @param .raise `logical(1L)` flag indicating whether errors should be raised | ||
| #' or captured. This flag is not intended to be set directly, it is exposed | ||
| #' so that recursive calls can raise lower-level errors while capturing them | ||
|
|
@@ -189,7 +208,13 @@ random_repo <- function(..., path = tempfile("repo")) { | |
| #' | ||
| #' @keywords internal | ||
| #' @include utils_err.R | ||
| get_pkg_data <- function(x, name, ..., .raise = .state$raise) { | ||
| get_pkg_data <- function( | ||
| x, | ||
| name, | ||
| ..., | ||
| logs = opt("logs"), | ||
| .raise = .state$raise | ||
| ) { | ||
| # RStudio, when trying to produce completions,will try to evaluate our lazy | ||
| # list elements. Intercept those calls and return only the existing values. | ||
| if (is_rs_rpc_get_completions_call()) { | ||
|
|
@@ -213,7 +238,19 @@ get_pkg_data <- function(x, name, ..., .raise = .state$raise) { | |
| assert_permissions(required_permissions, x@permissions) | ||
| assert_suggests(required_suggests) | ||
|
|
||
| data <- pkg_data_derive(pkg = x, field = name, ...) | ||
| if (logs) { | ||
| capture <- capture_pkg_data_derive(pkg = x, field = name, ...) | ||
| data <- capture$data | ||
| x@logs[[name]] <- capture$logs | ||
|
|
||
| # re-throw error after storing logs if one was produced | ||
| if (inherits(data, "error")) { | ||
| stop(data) | ||
| } | ||
| } else { | ||
| data <- pkg_data_derive(pkg = x, field = name, ...) | ||
| } | ||
|
|
||
| if (!identical(info@data_class, class_any)) { | ||
| data <- convert(data, info@data_class) | ||
| } | ||
|
|
@@ -382,31 +419,59 @@ as.data.frame.list_of_pkg <- function(x, ...) { | |
| } | ||
|
|
||
| #' @include utils_dcf.R | ||
| method(from_dcf, list(class_character, class_pkg)) <- | ||
| function(x, to, ...) { | ||
| dcf <- from_dcf(x, class_any) | ||
| method(convert, list(class_list, class_pkg)) <- | ||
| function(from, to, ...) { | ||
|
Comment on lines
+422
to
+423
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly added handling for lists, which were effectively already handled inside the |
||
| resource <- unknown_resource( | ||
| package = dcf[[1, "Package"]], | ||
| version = dcf[[1, "Version"]], | ||
| md5 = if ("MD5sum" %in% colnames(dcf)) { | ||
| dcf[[1, "MD5sum"]] | ||
| } else { | ||
| NA_character_ | ||
| } | ||
| package = from$name %||% from$Package, | ||
| version = from$version %||% from$Version, | ||
| md5 = from$MD5sum %||% NA_character_ | ||
| ) | ||
|
|
||
| data <- new.env(parent = emptyenv()) | ||
| for (name in names(from)) { | ||
| # recover gracefully from unknown fieldnames | ||
| info <- tryCatch(pkg_data_info(name), error = function(e) NULL) | ||
| if (is.null(info)) { | ||
| next | ||
| } | ||
|
|
||
| data[[name]] <- metric_coerce(from[[name]], info@data_class) | ||
| } | ||
|
|
||
| pkg <- pkg(resource) | ||
| pkg@data <- data | ||
|
|
||
| pkg | ||
| } | ||
|
|
||
| #' @include utils_dcf.R | ||
| method(from_dcf, list(class_character, class_pkg)) <- | ||
| function(x, to, ...) { | ||
| dcf <- from_dcf(x, class_any) | ||
|
|
||
| data <- list() | ||
| data$name <- dcf[[1, "Package"]] | ||
| data$version <- dcf[[1, "Version"]] | ||
| data$md5 <- if ("MD5sum" %in% colnames(dcf)) { | ||
| dcf[[1, "MD5sum"]] | ||
| } else { | ||
| NA_character_ | ||
| } | ||
|
|
||
| prefix <- "Metric/" | ||
| for (name in colnames(dcf)[startsWith(colnames(dcf), prefix)]) { | ||
| field <- sub(prefix, "", name) | ||
| info <- pkg_data_info(field) | ||
|
|
||
| # recover gracefully from unknown fieldnames | ||
| info <- tryCatch(pkg_data_info(field), error = function(e) NULL) | ||
| if (is.null(info)) { | ||
| next | ||
| } | ||
|
|
||
| val <- dcf[[1, name]] | ||
| val <- metric_coerce(val, info@data_class) | ||
| data[[field]] <- val | ||
| } | ||
|
|
||
| pkg <- pkg(resource) | ||
| pkg@data <- data | ||
|
|
||
| pkg | ||
| convert(data, class_pkg) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,12 +31,11 @@ impl_data( | |
| return(0) | ||
| } | ||
|
|
||
| nodes |> | ||
| xml2::xml_attr("href") |> | ||
| basename() |> | ||
| tools::file_path_sans_ext() |> | ||
| unique() |> | ||
| length() | ||
| paths <- xml2::xml_attr(nodes, "href") | ||
| filenames <- basename(paths) | ||
| filestems <- tools::file_path_sans_ext(filenames) | ||
|
Comment on lines
-34
to
+36
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit of an unrelated fix, but noticed that the use of |
||
|
|
||
| length(unique(filestems)) | ||
| } | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few extra handlers for converting a character string into a
pkgobject. Specifically ensuring that we can handle Rds file paths and DCF strings.With these, whatever is passed to the report's
packageparameter, we can just runconvert()on it to build apkg()object and handle Rds paths, DCF strings and package names through a single interface.