From b58c1f2c68d55d4e182332347ac81ca019ee84e6 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 12 Mar 2024 16:52:11 -0400 Subject: [PATCH] Use `resolve_libpath(local_pkgs=)` for clearer intent --- R/deploy-apps.R | 6 +++--- R/install-path.R | 26 +++++++++++++++++--------- R/install.R | 2 +- R/sysinfo.R | 2 +- R/test-in-browser.R | 6 +++--- R/test-in-ide.R | 7 +------ R/test-in-local.R | 9 ++------- man/deploy_apps.Rd | 4 ++-- man/resolve_libpath.Rd | 15 +++++++++++++++ man/test_in_local.Rd | 2 +- man/write_sysinfo.Rd | 2 +- 11 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 man/resolve_libpath.Rd diff --git a/R/deploy-apps.R b/R/deploy-apps.R index e5034a74b1..7ab15380aa 100644 --- a/R/deploy-apps.R +++ b/R/deploy-apps.R @@ -7,18 +7,18 @@ #' @param apps A character vector of fully defined shiny application folders #' @param account,server args supplied to `[rsconnect::deployApp]` #' @param ... ignored -#' @param install If TRUE, will install all of shinyverse into the default libpath #' @param extra_packages A character vector of extra packages to install #' @param cores number of cores to use when deploying #' @param retry If \code{TRUE}, try failure apps again. (Only happens once.) #' @param retrying_ For internal use only +#' @inheritParams resolve_libpath #' @export deploy_apps <- function( apps = apps_deploy, account = "testing-apps", server = "shinyapps.io", ..., - install = TRUE, + local_pkgs = TRUE, extra_packages = NULL, cores = 1, retry = 2, @@ -32,7 +32,7 @@ deploy_apps <- function( apps <- resolve_app_name(apps) - libpath <- shinycoreci_libpath() + libpath <- resolve_libpath(local_pkgs = local_pkgs) if (!retrying_) { # Always make sure the app dependencies are available diff --git a/R/install-path.R b/R/install-path.R index 8b70d8525e..2a373299d1 100644 --- a/R/install-path.R +++ b/R/install-path.R @@ -2,6 +2,23 @@ on_ci <- function() { isTRUE(as.logical(Sys.getenv("CI"))) } +#' Resolve library path +#' @param local_pkgs If `TRUE`, local packages will be used instead of the isolated shinyverse installation. +#' @keywords internal +resolve_libpath <- function(..., local_pkgs = FALSE) { + stopifnot(length(list(...)) == 0) + # TODO-barret-future; Figure out if we can use the standard libpath location; My hunch is no, as some packages will already be loaded, and that is bad. + # # CI cache location + # if (on_ci()) { + # # Use standard libpath location + # return(.libPaths()[1]) + # } + + # If using local_pkgs, use the standard libpath location + libpath <- if (isTRUE(local_pkgs)) .libPaths()[1] else shinycoreci_libpath() + libpath +} + #' Shinyverse libpath #' @@ -10,11 +27,6 @@ on_ci <- function() { #' @export #' @describeIn shinycoreci_libpath Library path that will persist across installations. But will have a different path for different R versions shinycoreci_libpath <- function() { - if (on_ci()) { - # Use standard libpath location - return(.libPaths()[1]) - } - # Dir location inspration from learnr: # https://github.com/rstudio/learnr/blob/1c01ac258230cbe217eee16c77cc71924faab1d3/R/storage.R#L275 dir <- file.path( @@ -34,9 +46,5 @@ shinycoreci_libpath <- function() { #' @export #' @describeIn shinycoreci_libpath Removes the cached R library shinycoreci_clean_libpaths <- function() { - if (on_ci()) { - stop("Cannot clean libpaths on CI") - } - unlink(dirname(shinycoreci_libpath()), recursive = TRUE) } diff --git a/R/install.R b/R/install.R index 357333ef68..0bcf955998 100644 --- a/R/install.R +++ b/R/install.R @@ -36,7 +36,7 @@ shinycoreci_is_local <- function() { # dependencies = NA, # pak::pkg_install(dependencies = NA) # extra_packages = NULL, # install_apps_deps = TRUE, -# libpath = shinycoreci_libpath()) { +# libpath = resolve_libpath()) { # if (!isTRUE(install)) { # return(.libPaths()[1]) # } diff --git a/R/sysinfo.R b/R/sysinfo.R index b81ec89eda..1eeaa59cbd 100644 --- a/R/sysinfo.R +++ b/R/sysinfo.R @@ -3,7 +3,7 @@ #' @param file Name of file, or file object to write to (defaults to stdout). #' @param libpath Library path to find installed packages. #' @export -write_sysinfo <- function(file = stdout(), libpath = shinycoreci_libpath()) { +write_sysinfo <- function(file = stdout(), libpath = resolve_libpath()) { withr::local_libpaths(libpath, action = "prefix") platform_info <- sessioninfo::platform_info() diff --git a/R/test-in-browser.R b/R/test-in-browser.R index 853ecc1f5f..b0dfd1608b 100644 --- a/R/test-in-browser.R +++ b/R/test-in-browser.R @@ -7,7 +7,7 @@ #' @param port `port` for the foreground app process #' @param port_background `port` for the background app process #' @param host `host` for the foreground and background app processes -#' @param local_pkgs If `TRUE`, local packages will be used instead of the isolated shinyverse installation. +#' @inheritParams resolve_libpath #' @param ... ignored #' @export #' @examples @@ -23,7 +23,7 @@ test_in_browser <- function( host = "127.0.0.1", local_pkgs = FALSE) { should_install <- !isTRUE(local_pkgs) - libpath <- if (should_install) shinycoreci_libpath() else .libPaths()[1] + libpath <- resolve_libpath(local_pkgs = local_pkgs) app_infos <- lapply(apps, function(app_name) { app_proc <- NULL @@ -108,7 +108,7 @@ test_in_browser <- function( if (should_install) { install_missing_app_deps( app_name, - libpath = shinycoreci_libpath(), + libpath = libpath, ) } diff --git a/R/test-in-ide.R b/R/test-in-ide.R index b945726e25..f46342e386 100644 --- a/R/test-in-ide.R +++ b/R/test-in-ide.R @@ -29,12 +29,7 @@ test_in_ide <- function( apps <- resolve_app_name(apps) should_install <- !isTRUE(local_pkgs) - libpath <- - if (should_install) { - shinycoreci_libpath() - } else { - .libPaths()[1] - } + libpath <- resolve_libpath(local_pkgs = local_pkgs) withr::local_libpaths(libpath, action = "prefix") app_name <- resolve_app_name(app_name) diff --git a/R/test-in-local.R b/R/test-in-local.R index e70a8ae405..24749091a4 100644 --- a/R/test-in-local.R +++ b/R/test-in-local.R @@ -14,7 +14,7 @@ ci_status <- list( #' @param retries number of attempts to retry before declaring the test a failure #' @param repo_dir Location of local shinycoreci repo #' @param ... ignored -#' @param local_pkgs If `TRUE`, the local `.libPaths()[1]` will be used. If `FALSE`, a persistent shinycoreci libpath will be used. Only when `local_pkgs=FALSE` will app dependencies be installed. +#' @inheritParams resolve_libpath #' @export test_in_local <- function( apps = apps_with_tests(repo_dir), @@ -28,12 +28,7 @@ test_in_local <- function( repo_dir <- normalizePath(repo_dir, mustWork = TRUE) should_install <- !isTRUE(local_pkgs) - libpath <- - if (should_install) { - shinycoreci_libpath() - } else { - .libPaths()[1] - } + libpath <- resolve_libpath(local_pkgs = local_pkgs) stopifnot(length(apps_with_tests(repo_dir)) > 0) apps <- resolve_app_name(apps, known_apps = apps_with_tests(repo_dir)) diff --git a/man/deploy_apps.Rd b/man/deploy_apps.Rd index 0ab408ec26..ab06949aa0 100644 --- a/man/deploy_apps.Rd +++ b/man/deploy_apps.Rd @@ -9,7 +9,7 @@ deploy_apps( account = "testing-apps", server = "shinyapps.io", ..., - install = TRUE, + local_pkgs = TRUE, extra_packages = NULL, cores = 1, retry = 2, @@ -23,7 +23,7 @@ deploy_apps( \item{...}{ignored} -\item{install}{If TRUE, will install all of shinyverse into the default libpath} +\item{local_pkgs}{If \code{TRUE}, local packages will be used instead of the isolated shinyverse installation.} \item{extra_packages}{A character vector of extra packages to install} diff --git a/man/resolve_libpath.Rd b/man/resolve_libpath.Rd new file mode 100644 index 0000000000..dc87193662 --- /dev/null +++ b/man/resolve_libpath.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/install-path.R +\name{resolve_libpath} +\alias{resolve_libpath} +\title{Resolve library path} +\usage{ +resolve_libpath(..., local_pkgs = FALSE) +} +\arguments{ +\item{local_pkgs}{If \code{TRUE}, local packages will be used instead of the isolated shinyverse installation.} +} +\description{ +Resolve library path +} +\keyword{internal} diff --git a/man/test_in_local.Rd b/man/test_in_local.Rd index 9d4f77b1be..d2d663a15e 100644 --- a/man/test_in_local.Rd +++ b/man/test_in_local.Rd @@ -27,7 +27,7 @@ test_in_local( \item{repo_dir}{Location of local shinycoreci repo} -\item{local_pkgs}{If \code{TRUE}, the local \code{.libPaths()[1]} will be used. If \code{FALSE}, a persistent shinycoreci libpath will be used. Only when \code{local_pkgs=FALSE} will app dependencies be installed.} +\item{local_pkgs}{If \code{TRUE}, local packages will be used instead of the isolated shinyverse installation.} } \description{ Test apps using \code{shiny::runTests()} using local libpath diff --git a/man/write_sysinfo.Rd b/man/write_sysinfo.Rd index 521c6c7603..f5e5aa6a40 100644 --- a/man/write_sysinfo.Rd +++ b/man/write_sysinfo.Rd @@ -4,7 +4,7 @@ \alias{write_sysinfo} \title{Write system information to a file} \usage{ -write_sysinfo(file = stdout(), libpath = shinycoreci_libpath()) +write_sysinfo(file = stdout(), libpath = resolve_libpath()) } \arguments{ \item{file}{Name of file, or file object to write to (defaults to stdout).}