Skip to content
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

Add development revdep check #47

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: checked
Title: Systematically Run R CMD Checks
Version: 0.2.4
Version: 0.2.5
Authors@R:
c(
person(
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# checked 0.2.5

* Refine reverse suggested dependecy strategy.

# checked 0.2.4

* Fix check processes hanging forever in some system configurations.
Expand Down
1 change: 1 addition & 0 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ check_rev_deps <- function(
checks <- rev_dep_check_tasks_df(
path = path,
repos = reverse_repos,
lib.loc = lib.loc,
...
)

Expand Down
55 changes: 32 additions & 23 deletions R/checks_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ NULL
#' mostly when checking whether adding new package would break tests of
#' packages already in the repository and take the package as suggests
#' dependency.
#' @param lib.loc vector of libraries used to check whether reverse dependency
#' check can return accurate results.
#'
#' @family tasks
#' @export
rev_dep_check_tasks_df <- function(
path,
repos = getOption("repos"),
versions = c("dev", "release"),
lib.loc = .libPaths(),
...
) {
stopifnot(
Expand Down Expand Up @@ -92,26 +95,28 @@ rev_dep_check_tasks_df <- function(
version = version
)

if (!package %in% ap[, "Package"] && "release" %in% versions) {
warning(
sprintf(
"Package `%s` not found in repositories `%s`. Skipping 'release' in 'versions'",
package,
paste0(repos, collapse = ", ")
),
immediate. = TRUE
)
if ("dev" %in% versions) {
versions <- "dev"
} else {
return(empty_checks_df)
}
reverse_suggests <- if (!package %in% ap[, "Package"] && "release" %in% versions) {
if (is_package_installed(package, lib.loc)) {
stop(
sprintf(
"Package `%s` not found in repositories `%s` and identified in lib.loc.
checked cannot provide accurate reverse dependency check results.
Remove the package from lib.loc and try again.",
package,
paste0(repos, collapse = ", ")
)
)

}
TRUE
} else {
FALSE
}

task_specs_function <- if (all(c("dev", "release") %in% versions)) {
rev_dep_check_tasks_specs
} else {
rev_dep_check_tasks_specs_development
check_tasks_specs
}

if ("dev" %in% versions) {
Expand All @@ -125,15 +130,19 @@ rev_dep_check_tasks_df <- function(
}

if ("release" %in% versions) {
package_v <- ap[package, "Version"]
package_v <- if (reverse_suggests) "missing" else ap[package, "Version"]
df_rel$alias <- paste0(df_rel$alias, " (v", package_v, ")")
df_rel$package <- task_specs_function(revdeps, repos, df_rel$alias, "old", ...)
df_rel$custom <- rep(list(custom_install_task_spec(
alias = paste0(package, " (release)"),
package_spec = package_spec(name = package, repos = repos),
# make sure to use the release version built against the same system
type = "source"
)), times = NROW(df_dev))
df_rel$custom <- if (reverse_suggests) {
rep(list(custom_install_task_spec()), times = NROW(df_dev))
} else {
rep(list(custom_install_task_spec(
alias = paste0(package, " (release)"),
package_spec = package_spec(name = package, repos = repos),
# make sure to use the release version built against the same system
type = "source"
)), times = NROW(df_dev))
}
}

if (identical(versions, "dev")) {
Expand Down Expand Up @@ -176,7 +185,7 @@ rev_dep_check_tasks_specs <- function(packages, repos, aliases, revdep, ...) {
))
}

rev_dep_check_tasks_specs_development <- function(
check_tasks_specs <- function(
packages,
repos,
aliases,
Expand Down
4 changes: 2 additions & 2 deletions R/task_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ task_graph_set_task_process <- function(g, v, process) {

task_graph_update_done <- function(g, lib.loc) {
v <- igraph::V(g)[igraph::V(g)$type == "install"]
which_done <- which(vlapply(v$name, is_package_done, lib.loc = lib.loc))
which_done <- which(vlapply(v$name, is_package_installed, lib.loc = lib.loc))
task_graph_set_package_status(g, v[which_done], STATUS$done)
}

is_package_done <- function(pkg, lib.loc) { # nolint object_name_linter
is_package_installed <- function(pkg, lib.loc) { # nolint object_name_linter
path <- find.package(pkg, lib.loc = lib.loc, quiet = TRUE)
length(path) > 0
}
Expand Down
4 changes: 4 additions & 0 deletions man/rev_dep_check_tasks_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 49 additions & 16 deletions tests/testthat/test-check-reverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test_that("check_rev_deps works for a package without release version", {

# Ensure source installation to make sure test works also on mac and windows
withr::with_options(list(pkgType = "source"), {
expect_warning(design <- check_rev_deps(
expect_no_warning(design <- check_rev_deps(
file.path(sources_new, "pkg.suggests"),
n = 2L, repos = repo, env = c("NOT_CRAN" = "false", options::opt("check_envvars"))))
})
Expand All @@ -101,26 +101,59 @@ test_that("check_rev_deps works for a package without release version", {
expect_true(is.list(r))
expect_named(r)
expect_length(r, 1L)
expect_length(r$check_task_spec, 1L)

expect_length(r$check_task_spec$`pkg.none (dev)`$notes$issues, 0L)
expect_length(r$check_task_spec$`pkg.none (dev)`$notes$potential_issues$new, 0L)
expect_length(r$check_task_spec$`pkg.none (dev)`$notes$potential_issues$old, 0L)

expect_length(r$check_task_spec$`pkg.none (dev)`$warnings$issues, 0L)
expect_length(r$check_task_spec$`pkg.none (dev)`$warnings$potential_issues$new, 0L)
expect_length(r$check_task_spec$`pkg.none (dev)`$warnings$potential_issues$old, 0L)

expect_length(r$revdep_check_task_spec, 2L)

expect_length(r$check_task_spec$`pkg.none (dev)`$errors$issues, 1L)
# pkg.none
expect_length(r$revdep_check_task_spec$pkg.none$notes$issues, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$notes$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$notes$potential_issues$old, 0L)

expect_length(r$revdep_check_task_spec$pkg.none$warnings$issues, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$warnings$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$warnings$potential_issues$old, 0L)


expect_length(r$revdep_check_task_spec$pkg.none$errors$issues, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$errors$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none$errors$potential_issues$old, 0L)


# pkg.none.broken
expect_length(r$revdep_check_task_spec$pkg.none.broken$notes$issues, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$notes$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$notes$potential_issues$old, 0L)

expect_length(r$revdep_check_task_spec$pkg.none.broken$warnings$issues, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$warnings$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$warnings$potential_issues$old, 0L)


expect_length(r$revdep_check_task_spec$pkg.none.broken$errors$issues, 1L)
expect_true(
grepl("Running the tests in",
r$check_task_spec$`pkg.none (dev)`$errors$issues),
r$revdep_check_task_spec$pkg.none.broken$errors$issues),
grepl("\"hello world\" is not TRUE",
r$check_task_spec$`pkg.none (dev)`$errors$issues)
r$revdep_check_task_spec$pkg.none.broken$errors$issues)
)
expect_length(r$check_task_spec$`pkg.none (dev)`$errors$potential_issues$new, 0L)
expect_length(r$check_task_spec$`pkg.none (dev)`$errors$potential_issues$old, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$errors$potential_issues$new, 0L)
expect_length(r$revdep_check_task_spec$pkg.none.broken$errors$potential_issues$old, 0L)

# Error testing
dir.create(temp_lib <- tempfile("testing_lib"))
install.packages(
file.path(sources_new, "pkg.suggests"),
lib = temp_lib,
type = "source",
repos = NULL
)

withr::with_options(list(pkgType = "source"), {
expect_error(design <- check_rev_deps(
file.path(sources_new, "pkg.suggests"),
lib.loc = temp_lib,
n = 2L, repos = repo, env = c("NOT_CRAN" = "false", options::opt("check_envvars"))),
"cannot provide accurate reverse dependency check results")
})
})

test_that("check_dev_rev_deps works as expected", {
Expand Down
Binary file not shown.
Loading