-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
e87eda1
47956b2
ee8c6e7
58b1f1d
0d888f3
018f70d
cd1bd91
bc14bbb
c61f27e
ede9e84
ab0951a
0dfa4ee
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()) { | ||
|
Comment on lines
218
to
220
Contributor
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. Couldn't stop myself, to point out that maybe we need to check if the code is run by RStudio and perhaps check if with Positron or VSCode something similar happens (I doubt it). Another related approach would be to provide a
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. Ah, good call on the other IDEs. I haven't tested in Positron/VSCode. We do provide
Contributor
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. Sorry, I didn't check if it was available already. That method looks weird why do it use
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.
Yeah, I agree with you there! I think there are a few weird things going on.
This is because
I can try it again. I think I had some issues with it picking up the generic name because it starts with a period. |
||
|
|
@@ -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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,8 +9,10 @@ impl_data( | |||||
| impl_data( | ||||||
| "covr_coverage", | ||||||
| for_resource = local_source_resource, | ||||||
| function(pkg, resource, field, ..., quiet = opt("quiet")) { | ||||||
| covr::package_coverage(resource@path, type = "tests", quiet = quiet) | ||||||
| function(pkg, resource, field, ...) { | ||||||
| # package installs use `system2()` whose output cannot be captured by sink() | ||||||
| # so we just execute quietly | ||||||
| covr::package_coverage(resource@path, type = "tests", quiet = TRUE) | ||||||
|
Contributor
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. Again not the point of the PR but should code coverage cover all? Or at least we should provide a way to change that.
Suggested change
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. Yeah, good call. I'd say we should break these off the other types into other metrics. |
||||||
| } | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -23,7 +25,7 @@ impl_data( | |||||
| "The fraction of expressions of package code that are evaluated by any ", | ||||||
| "test" | ||||||
| ), | ||||||
| function(pkg, resource, field, ..., quiet = opt("quiet")) { | ||||||
| function(pkg, resource, field, ...) { | ||||||
| tally <- covr::tally_coverage(pkg$covr_coverage, by = "expression") | ||||||
| mean(tally$value > 0) | ||||||
| } | ||||||
|
|
@@ -45,7 +47,7 @@ impl_data( | |||||
| description = paste0( | ||||||
| "The fraction of lines of package code that are evaluated by any test" | ||||||
| ), | ||||||
| function(pkg, resource, field, ..., quiet = opt("quiet")) { | ||||||
| function(pkg, resource, field, ...) { | ||||||
| tally <- covr::tally_coverage(pkg$covr_coverage, by = "line") | ||||||
| mean(tally$value > 0) | ||||||
| } | ||||||
|
|
||||||
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.