From 761dd68e10426c451ba9eb1c0b8d2f40b0ead583 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:04:38 +0200 Subject: [PATCH] disable lockfile generation in `callr`, `testthat::tests` and `R CMD CHECK` (#1346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of https://github.com/insightsengineering/teal/pull/1263 and closes https://github.com/insightsengineering/teal/issues/1276 Local results of `shinytest2` tests ```r ══ Results ══════════════════════════════════════════════════════════════════════════ Duration: 540.8 s ── Skipped tests (6) ──────────────────────────────────────────────────────────────── • need a fix in a .slicesGlobal (1): test-module_teal.R:1139:11 • todo (5): test-module_teal.R:1404:7, test-module_teal.R:1411:5, test-module_teal.R:1414:5, test-module_teal.R:1673:5, test-module_teal.R:1731:5 [ FAIL 0 | WARN 0 | SKIP 6 | PASS 515 ] ``` --- R/module_teal_lockfile.R | 18 +++++++++++++++++- R/zzz.R | 2 +- tests/testthat/setup-options.R | 6 ------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/R/module_teal_lockfile.R b/R/module_teal_lockfile.R index 8ff8b087d5..43c9816dd1 100644 --- a/R/module_teal_lockfile.R +++ b/R/module_teal_lockfile.R @@ -74,7 +74,7 @@ srv_teal_lockfile <- function(id) { }) lockfile_path <- "teal_app.lock" - is_lockfile_enabled <- isTRUE(getOption("teal.lockfile.enable")) + is_lockfile_enabled <- .is_lockfile_enabled() user_lockfile_path <- getOption("teal.lockfile.path", default = "") is_user_lockfile_set <- !identical(user_lockfile_path, "") @@ -194,3 +194,19 @@ utils::globalVariables(c("opts", "sysenv", "libpaths", "wd", "lockfilepath", "ru .is_lockfile_deps_installed <- function() { requireNamespace("mirai", quietly = TRUE) && requireNamespace("renv", quietly = TRUE) } + +#' @rdname module_teal_lockfile +.is_lockfile_enabled <- function() { + if (isTRUE(getOption("teal.lockfile.enable"))) { + return(TRUE) + } else { + !( + identical(Sys.getenv("CALLR_IS_RUNNING"), "true") || # inside callr process + identical(Sys.getenv("TESTTHAT"), "true") || # inside devtools::test + !identical(Sys.getenv("QUARTO_PROJECT_ROOT"), "") || # inside Quarto process + ( + ("CheckExEnv" %in% search()) || any(c("_R_CHECK_TIMINGS_", "_R_CHECK_LICENSE_") %in% names(Sys.getenv())) + ) # inside R CMD CHECK + ) + } +} diff --git a/R/zzz.R b/R/zzz.R index 9b324ff5ff..fcab860a8a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,8 +1,8 @@ .onLoad <- function(libname, pkgname) { # adapted from https://github.com/r-lib/devtools/blob/master/R/zzz.R + teal_default_options <- list( teal.show_js_log = FALSE, - teal.lockfile.enable = TRUE, shiny.sanitize.errors = FALSE ) diff --git a/tests/testthat/setup-options.R b/tests/testthat/setup-options.R index e923a60c7f..40d3949a8c 100644 --- a/tests/testthat/setup-options.R +++ b/tests/testthat/setup-options.R @@ -1,9 +1,3 @@ -withr::local_options( - # we should't run lockfile process multiple times in tests as it starts background process which is not - # possible to kill once run. It means that background R sessions are being cumulated - list(teal.lockfile.enable = FALSE), - .local_envir = testthat::teardown_env() -) # `opts_partial_match_old` is left for exclusions due to partial matching in dependent packages (i.e. not fixable here) # it might happen that it is not used right now, but it is left for possible future use