Skip to content

Commit

Permalink
Dev 1028 (#1088)
Browse files Browse the repository at this point in the history
* 942 install sass if missing (#1028)

* refactor: install_dev_deps can now install specific packages
* fix: fix the bug at "sass::" line of dev/run_dev.R

* refactor : `run_dev` use `attachment::att_from_script` to detect dev/run_dev.R dependencies 

* fix add httpuv in dev_deps


---------

Co-authored-by: Ilya Zarubin <[email protected]>
  • Loading branch information
VincentGuyader and ilyaZar authored Aug 9, 2023
1 parent 9456fd5 commit 1971f72
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Suggests:
devtools,
dockerfiler (>= 0.2.0),
fs,
httpuv,
knitr,
mockery,
pkgbuild,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

+ `use_{internal,external}_XXX_file()` function family works with default missing `name` argument (#1060, @ilyaZar)

+ `run_dev()` now install needed dependencies to source dev/run_dev.R if needed (#942, @ilyaZar, @vincentGuyader)

+ `use_readme_rmd()` does not pop up when argument `open=FALSE` is set (#1044, @ilyaZar)

+ Docker commands now take the `-it` flag so it can be killed with `^C` (#1002, @ivokwee)
Expand Down
15 changes: 12 additions & 3 deletions R/install_dev_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#' + {testthat}
#' + {rstudioapi}
#'
#' @param force_install If force_install is installed,
#' @param force_install If force_install is TRUE,
#' then the user is not interactively asked
#' to install them.
#' @param ... further arguments passed to the install function.
#' @param dev_deps optional character vector of packages to install
#'
#' @export
#'
Expand All @@ -31,6 +32,7 @@
#'
#' @return Used for side-effects
install_dev_deps <- function(
dev_deps,
force_install = FALSE,
...) {
if (!force_install) {
Expand All @@ -47,7 +49,7 @@ install_dev_deps <- function(
# want to install, which is what they want
f <- rlang::check_installed
} else {
# Case 2, the user runs this function with force_install to FALSE
# Case 2, the user runs this function with force_install to TRUE
# At that point, the user probably has pak installed
# If yes, the installation function
# will be pak::pkg_install, otherwise
Expand All @@ -60,6 +62,11 @@ install_dev_deps <- function(
}
}

if (missing(dev_deps)){
dev_deps <- getFromNamespace("dev_deps", "golem")
}


for (
pak in dev_deps
) {
Expand All @@ -69,6 +76,7 @@ install_dev_deps <- function(
}
}


dev_deps <- unique(
c(
"attachment",
Expand All @@ -79,11 +87,12 @@ dev_deps <- unique(
"dockerfiler",
"fs",
"here",
"httpuv",
"pkgbuild",
"pkgload",
"processx",
"roxygen2",
"renv",
"roxygen2",
"rsconnect",
"rstudioapi",
"testthat",
Expand Down
11 changes: 10 additions & 1 deletion R/run_dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' reloading the package in a clean `R` environment before running the app etc.
#'
#' @param file String with (relative) file path to a `run_dev.R`-file
#' @param install_required_packages Boolean; if `TRUE` install the packages
#' used in `run_dev.R`-file
#' @param save_all Boolean; if `TRUE` saves all open files before sourcing
#' `file`
#' @inheritParams add_module
Expand All @@ -23,7 +25,8 @@
run_dev <- function(
file = "dev/run_dev.R",
pkg = get_golem_wd(),
save_all = TRUE
save_all = TRUE,
install_required_packages = TRUE
) {
if (save_all) {
if (
Expand Down Expand Up @@ -51,6 +54,12 @@ run_dev <- function(
)
}

if (install_required_packages) {
install_dev_deps("attachment", force_install = install_required_packages)
to_install <- attachment::att_from_rscript(path = try_dev)
install_dev_deps(dev_deps = to_install, force_install = install_required_packages)
}

eval(
parse(
text = run_dev_lines
Expand Down
6 changes: 4 additions & 2 deletions man/install_dev_deps.Rd

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

12 changes: 10 additions & 2 deletions man/run_dev.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-run_dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ test_that("run_dev() works for different files and fails if missing", {
run_dev_update <- readLines("dev/run_dev.R")
# suppress other behavior of run_dev that is not meant for testing
run_dev_update[2] <- "# options(golem.app.prod = FALSE)"
run_dev_update[6] <- "# options(shiny.port = httpuv::randomPort())"
run_dev_update[5] <- "# options(shiny.port = httpuv::randomPort())"
run_dev_update[8] <- "# golem::detach_all_attached()"
run_dev_update[12] <- "# golem::document_and_reload()"
run_dev_update[15] <- "print('DEFAULT run_dev')"
# write new run_dev.R file for testing
run_dev_update <- writeLines(run_dev_update, "dev/run_dev.R")
writeLines(run_dev_update, "dev/run_dev.R")
# Make a copy of run_dev and move it elsewhere (but inside golem)
file.copy(
from = "dev/run_dev.R",
Expand All @@ -25,7 +25,7 @@ test_that("run_dev() works for different files and fails if missing", {
# Adjust copy for testing run_dev() with user supplied file="run_dev2.R"
run_dev_update <- readLines("run_dev2.R")
run_dev_update[15] <- "print('NEW run_dev2')"
run_dev_update <- writeLines(run_dev_update, "run_dev2.R")
writeLines(run_dev_update, "run_dev2.R")
# The default run_dev works
expect_output(
run_dev(),
Expand Down

0 comments on commit 1971f72

Please sign in to comment.