Skip to content

Commit

Permalink
Use resolve_libpath(local_pkgs=) for clearer intent
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Mar 12, 2024
1 parent 7509a52 commit b58c1f2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 34 deletions.
6 changes: 3 additions & 3 deletions R/deploy-apps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
26 changes: 17 additions & 9 deletions R/install-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand All @@ -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(
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
# }
Expand Down
2 changes: 1 addition & 1 deletion R/sysinfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions R/test-in-browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -108,7 +108,7 @@ test_in_browser <- function(
if (should_install) {
install_missing_app_deps(
app_name,
libpath = shinycoreci_libpath(),
libpath = libpath,
)
}

Expand Down
7 changes: 1 addition & 6 deletions R/test-in-ide.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions R/test-in-local.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions man/deploy_apps.Rd

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

15 changes: 15 additions & 0 deletions man/resolve_libpath.Rd

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

2 changes: 1 addition & 1 deletion man/test_in_local.Rd

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

2 changes: 1 addition & 1 deletion man/write_sysinfo.Rd

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

0 comments on commit b58c1f2

Please sign in to comment.