Skip to content

Commit

Permalink
Refactor options usage
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymiuks committed Sep 25, 2024
1 parent 37ac4f0 commit c5d3439
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 96 deletions.
18 changes: 9 additions & 9 deletions R/checks_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ rev_dep_check_tasks_specs <- function(packages, repos, aliases, revdep, ...) {
function(
p,
a,
env = NULL,
args = NULL,
build_args = NULL
env = options::opt("check_envvars"),
args = options::opt("check_args"),
build_args = options::opt("check_build_args")
) {
revdep_check_task_spec(
alias = a,
Expand Down Expand Up @@ -187,9 +187,9 @@ rev_dep_check_tasks_specs_development <- function(
function(
p,
a,
env = NULL,
args = NULL,
build_args = NULL
env = options::opt("check_envvars"),
args = options::opt("check_args"),
build_args = options::opt("check_build_args")
) {
check_task_spec(
alias = a,
Expand Down Expand Up @@ -254,9 +254,9 @@ source_check_tasks_specs <- function(packages, path, aliases, ...) {
p,
path,
a,
env = NULL,
args = NULL,
build_args = NULL) {
env = options::opt("check_envvars"),
args = options::opt("check_args"),
build_args = options::opt("check_build_args")) {

check_task_spec(
alias = a,
Expand Down
25 changes: 18 additions & 7 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ options::define_options(
progress from the same `output`",
restore = NA,

"`logical` indicating whether default R CMD check related enviromental
variables should be appended.",
default_check_env_variables = TRUE,
"named `character` vector of environment variables to use during R CMD check.",
check_envvars = c(
"_R_CHECK_FORCE_SUGGESTS_" = FALSE,
"_R_CHECK_RD_XREFS_" = FALSE,
"_R_CHECK_SYSTEM_CLOCK_" = FALSE,
"_R_CHECK_SUGGESTS_ONLY_" = TRUE
),

"`logical` indicating whether default R CMD check build args should be appended.",
default_check_build_args = TRUE,
"`character` vector of args passed to the R CMD build.",
check_build_args = c(
"--no-build-vignettes",
"--no-manual"
),

"`logical` indicating whether default R CMD check args should be appended.",
default_check_args = TRUE
"`character` vector of args passed to the R CMD check.",
check_args = c(
"--timings",
"--ignore-vignettes",
"--no-manual"
)
)

#' @eval options::as_roxygen_docs()
Expand Down
27 changes: 12 additions & 15 deletions R/task_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#'
#' @family tasks
#' @export
task_spec <- function(alias = NULL, package_spec = NULL, env = NULL) {
task_spec <- function(
alias = NULL,
package_spec = NULL,
env = options::opt("check_envvars")) {
structure(
list(
alias = alias,
package_spec = package_spec,
env = merge_default_configuration(
env,
DEFAULT_CHECK_ENV_VARIABLES,
"default_check_env_variables"
)
env = env
),
class = "task_spec"
)
Expand Down Expand Up @@ -85,17 +84,15 @@ custom_install_task_spec <- function(...) {
#'
#' @family tasks
#' @export
check_task_spec <- function(args = NULL, build_args = NULL, ...) {
check_task_spec <- function(
args = options::opt("check_args"),
build_args = options::opt("check_build_args"),
...) {

task_spec <- task_spec(...)
check_spec <- list(
args = merge_default_configuration(
args,
DEFAULT_CHECK_ARGS,
"default_check_args"),
build_args = merge_default_configuration(
build_args,
DEFAULT_CHECK_BUILD_ARGS,
"default_check_build_args")
args = args,
build_args = build_args
)

structure(
Expand Down
13 changes: 0 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
#' @import cli
NULL

merge_default_configuration <- function(conf, default_conf, option) {
if (options::opt(option)) {
merged <- c(conf, default_conf)
if (!is.null(names(merged))) {
merged[!duplicated(names(merged))]
} else {
merged
}
} else {
conf
}
}

base_pkgs <- function() {
c("R", utils::installed.packages(priority = "base")[, "Package"])
}
Expand Down
6 changes: 5 additions & 1 deletion man/check_task_spec.Rd

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

26 changes: 13 additions & 13 deletions man/options.Rd

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

11 changes: 5 additions & 6 deletions man/options_params.Rd

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

6 changes: 5 additions & 1 deletion man/task_spec.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-check-reverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ test_that("check_rev_deps works for a package without release version", {
withr::with_options(list(pkgType = "source"), {
expect_warning(design <- check_rev_deps(
file.path(sources_new, "pkg.suggests"),
n = 2L, repos = repo, env = c("NOT_CRAN" = "false")))
n = 2L, repos = repo, env = c("NOT_CRAN" = "false", options::opt("check_envvars"))))
})

expect_identical(
design$input$package[[1]]$env,
c("NOT_CRAN" = "false", DEFAULT_CHECK_ENV_VARIABLES)
c("NOT_CRAN" = "false", options::opt("check_envvars"))
)

r <- results(design)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ test_that("check_pkgs works as expected", {
file.path(examples_path, "exampleGood"),
file.path(examples_path, "exampleBad")
), n = 2L, repos = "https://cran.r-project.org/",
env = c(NOT_CRAN = "false")))
env = c(NOT_CRAN = "false", options::opt("check_envvars"))))

expect_identical(
design$input$package[[1]]$env,
c("NOT_CRAN" = "false", DEFAULT_CHECK_ENV_VARIABLES)
c(NOT_CRAN = "false", options::opt("check_envvars"))
)
})

Expand Down
47 changes: 20 additions & 27 deletions tests/testthat/test-checks_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,33 @@ test_that("task_df functions can specify subprocesses configuration", {
df <- rev_dep_check_tasks_df(
test_path("testing_pkgs", "DALEXtra"),
repos = "https://cran.r-project.org/",
env = c("NOT_CRAN" = "false"),
args = c("--some-option", "--other-option"),
build_args = c("--yet-another-option")
env = c("NOT_CRAN" = "false", options::opt("check_envvars")),
args = c("--some-option", "--other-option", options::opt("check_args")),
build_args = c("--yet-another-option", options::opt("check_build_args"))
)
)

expect_identical(
df$package[[1]]$env,
c("NOT_CRAN" = "false", DEFAULT_CHECK_ENV_VARIABLES)
c("NOT_CRAN" = "false", options::opt("check_envvars"))
)
expect_identical(
df$package[[1]]$args,
c("--some-option", "--other-option", DEFAULT_CHECK_ARGS)
c("--some-option", "--other-option", options::opt("check_args"))
)
expect_identical(
df$package[[1]]$build_args,
c("--yet-another-option", DEFAULT_CHECK_BUILD_ARGS)
c("--yet-another-option", options::opt("check_build_args"))
)

withr::with_envvar(
c(R_CHECKED_DEFAULT_CHECK_ENV_VARIABLES = "FALSE",
R_CHECKED_DEFAULT_CHECK_ARGS = "FALSE",
R_CHECKED_DEFAULT_CHECK_BUILD_ARGS = "FALSE"), {
expect_silent(
df <- rev_dep_check_tasks_df(
test_path("testing_pkgs", "DALEXtra"),
repos = "https://cran.r-project.org/",
env = c("NOT_CRAN" = "false"),
args = c("--some-option", "--other-option"),
build_args = c("--yet-another-option")
)
)
}
expect_silent(
df <- rev_dep_check_tasks_df(
test_path("testing_pkgs", "DALEXtra"),
repos = "https://cran.r-project.org/",
env = c("NOT_CRAN" = "false"),
args = c("--some-option", "--other-option"),
build_args = c("--yet-another-option")
)
)

expect_identical(
Expand All @@ -91,29 +85,28 @@ test_that("task_df functions can specify subprocesses configuration", {
)

withr::with_envvar(
c(R_CHECKED_DEFAULT_CHECK_BUILD_ARGS = "FALSE"), {
c(R_CHECKED_CHECK_ARGS = "c('--some-option', '--other-option')",
R_CHECKED_CHECK_BUILD_ARGS = "c('--yet-another-option')"), {
expect_silent(
df <- source_check_tasks_df(
path,
env = c("NOT_CRAN" = "false"),
args = c("--some-option", "--other-option"),
build_args = c("--yet-another-option")
build_args = c("--another-option", options::opt("check_build_args"))
)
)
}
)

expect_identical(
df$package[[1]]$env,
c("NOT_CRAN" = "false", DEFAULT_CHECK_ENV_VARIABLES)
options::opt("check_envvars")
)
expect_identical(
df$package[[1]]$args,
c("--some-option", "--other-option", DEFAULT_CHECK_ARGS)
c("--some-option", "--other-option")
)
expect_identical(
df$package[[1]]$build_args,
"--yet-another-option"
c("--another-option", "--yet-another-option")
)

})
Expand Down

0 comments on commit c5d3439

Please sign in to comment.