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

disable lockfile generation in callr, testthat::tests and R CMD CHECK #1346

Merged
merged 8 commits into from
Sep 19, 2024
18 changes: 17 additions & 1 deletion R/module_teal_lockfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")

Expand Down Expand Up @@ -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
)
}
}
2 changes: 1 addition & 1 deletion R/zzz.R
pawelru marked this conversation as resolved.
Show resolved Hide resolved
pawelru marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
)

Expand Down
6 changes: 0 additions & 6 deletions tests/testthat/setup-options.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading