Skip to content

Commit

Permalink
feat: removed usethis hard dep
Browse files Browse the repository at this point in the history
closing #834
  • Loading branch information
pachadotdev authored Oct 6, 2022
1 parent cc2ba3d commit 3d3d951
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Imports:
rlang,
rstudioapi,
shiny (>= 1.5.0),
usethis (>= 1.6.0),
utils,
yaml
Suggests:
Expand All @@ -81,6 +80,7 @@ Suggests:
stringr,
testthat,
tools,
usethis (>= 1.6.0),
withr,
attachment (>= 0.2.5)
VignetteBuilder:
Expand Down
7 changes: 0 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ importFrom(shiny,addResourcePath)
importFrom(shiny,getShinyOption)
importFrom(shiny,includeScript)
importFrom(shiny,tags)
importFrom(usethis,create_project)
importFrom(usethis,proj_set)
importFrom(usethis,use_build_ignore)
importFrom(usethis,use_latest_dependencies)
importFrom(usethis,use_package)
importFrom(usethis,use_spell_check)
importFrom(usethis,use_testthat)
importFrom(utils,capture.output)
importFrom(utils,file.edit)
importFrom(utils,getFromNamespace)
Expand Down
18 changes: 17 additions & 1 deletion R/add_dockerfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ talk_once <- function(.f, msg = "") {
#' @export
#' @rdname dockerfiles
#'
#' @importFrom usethis use_build_ignore
#' @importFrom desc desc_get_deps
#' @importFrom rstudioapi navigateToFile isAvailable hasFun
#' @importFrom fs path path_file
Expand Down Expand Up @@ -149,6 +148,11 @@ add_dockerfile_ <- talk_once(
version = "0.2.0",
reason = "to build a Dockerfile."
)

rlang::check_installed(
"usethis",
reason = "to ignore files in the build."
)

where <- path(pkg, output)

Expand Down Expand Up @@ -260,6 +264,12 @@ add_dockerfile_shinyproxy_ <- talk_once(
version = "0.2.0",
reason = "to build a Dockerfile."
)

rlang::check_installed(
"usethis",
reason = "to ignore files in the build."
)

where <- path(pkg, output)

usethis::use_build_ignore(output)
Expand Down Expand Up @@ -364,6 +374,12 @@ add_dockerfile_heroku_ <- talk_once(
version = "0.2.0",
reason = "to build a Dockerfile."
)

rlang::check_installed(
"usethis",
reason = "to ignore files in the build."
)

where <- path(pkg, output)

usethis::use_build_ignore(output)
Expand Down
4 changes: 4 additions & 0 deletions R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ add_dockerfile_with_renv_ <- function(
version = "0.2.5",
reason = "to build a Dockerfile."
)
rlang::check_installed(
"usethis",
reason = "to ignore files in the build."
)

# Small hack to prevent warning from rlang::lang() in tests
# This should be managed in {attempt} later on
Expand Down
11 changes: 7 additions & 4 deletions R/add_rstudio_files.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' @importFrom utils capture.output
#' @importFrom cli cat_bullet
#' @importFrom usethis use_build_ignore use_package
#' @importFrom fs path file_create path_file
add_rstudio_files <- function(
pkg,
Expand All @@ -19,7 +18,10 @@ add_rstudio_files <- function(
reason = "to deploy on RStudio products."
)

rlang::check_installed("usethis")
rlang::check_installed(
"usethis",
reason = "to add dependencies to DESCRIPTION and ignore files in the build."
)

disable_autoload(
pkg = pkg
Expand All @@ -32,8 +34,9 @@ add_rstudio_files <- function(
write(..., here, append = TRUE)
}

use_build_ignore(path_file(where))
use_build_ignore("rsconnect")
usethis::use_build_ignore(path_file(where))
usethis::use_build_ignore("rsconnect")

write_there("# Launch the ShinyApp (Do not remove this comment)")
write_there("# To deploy, run: rsconnect::deployApp()")
write_there("# Or use the blue button on top of this file")
Expand Down
8 changes: 6 additions & 2 deletions R/create_golem.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#' @importFrom cli cat_rule cat_line
#' @importFrom utils getFromNamespace
#' @importFrom rstudioapi isAvailable openProject hasFun
#' @importFrom usethis use_latest_dependencies create_project
#' @importFrom fs dir_copy
#' @importFrom yaml write_yaml
#'
Expand All @@ -42,6 +41,11 @@ create_golem <- function(
with_git = FALSE,
...
) {
rlang::check_installed(
"usethis",
reason = "to create projects and use the last version for the dependencies."
)

path <- normalizePath(path, mustWork = FALSE)

if (check_name) {
Expand Down Expand Up @@ -177,7 +181,7 @@ create_golem <- function(


old <- setwd(path)
use_latest_dependencies()
usethis::use_latest_dependencies()

# No .Rprofile for now
# cat_rule("Appending .Rprofile")
Expand Down
8 changes: 6 additions & 2 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#' @export
#' @importFrom attempt stop_if_not
#' @importFrom yaml read_yaml write_yaml
#' @importFrom usethis proj_set
#'
#' @return Used for side-effects for the setters, and values from the
#' config in the getters.
Expand All @@ -43,6 +42,11 @@ set_golem_options <- function(
app_prod = FALSE,
talkative = TRUE
) {
rlang::check_installed(
"usethis",
reason = "to set project path."
)

change_app_config_name(
name = golem_name,
path = golem_wd
Expand Down Expand Up @@ -130,7 +134,7 @@ set_golem_options <- function(
"Setting {usethis} project as `golem_wd`",
fun = cli::cat_rule
)
proj_set(golem_wd)
usethis::proj_set(golem_wd)
}

#' @importFrom yaml read_yaml write_yaml
Expand Down
19 changes: 13 additions & 6 deletions R/use_recommended.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#' @param recommended A vector of recommended packages.
#' @param spellcheck Whether or not to use a spellcheck test.
#'
#' @importFrom usethis use_testthat use_package
#' @importFrom fs path_abs
#' @rdname use_recommended
#'
Expand All @@ -26,12 +25,17 @@ use_recommended_deps <- function(
"golem::use_recommended_deps",
msg <- "use_recommended_deps() is soft deprecated and will be removed in future versions of {golem}."
)

rlang::check_installed(
"usethis",
reason = "to add dependencies to DESCRIPTION."
)

old <- setwd(path_abs(pkg))
on.exit(setwd(old))

for (i in sort(recommended)) {
try(use_package(i))
try(usethis::use_package(i))
}

cat_green_tick("Dependencies added")
Expand All @@ -40,7 +44,6 @@ use_recommended_deps <- function(

#' @rdname use_recommended
#' @export
#' @importFrom usethis use_testthat use_package use_spell_check
#' @importFrom utils capture.output
#' @importFrom attempt without_warning stop_if
#' @importFrom fs path_abs path file_exists
Expand All @@ -51,14 +54,19 @@ use_recommended_tests <- function(
lang = "en-US",
error = FALSE
) {
rlang::check_installed(
"usethis",
reason = "to use unit tests and check spelling."
)

old <- setwd(path_abs(pkg))

on.exit(setwd(old))

if (!dir.exists(
path(path_abs(pkg), "tests")
)) {
without_warning(use_testthat)()
without_warning(usethis::use_testthat)()
}
if (!requireNamespace("processx")) {
stop("Please install the {processx} package to add the recommended tests.")
Expand All @@ -77,13 +85,12 @@ use_recommended_tests <- function(
)

if (spellcheck) {
use_spell_check(
usethis::use_spell_check(
vignettes = vignettes,
lang = lang,
error = error
)
}


cat_green_tick("Tests added")
}
10 changes: 7 additions & 3 deletions R/use_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
#'
#' @importFrom cli cat_bullet
#' @importFrom utils capture.output
#' @importFrom usethis use_testthat
#'
#' @return Used for side-effects.
use_utils_ui <- function(
pkg = get_golem_wd(),
with_test = FALSE
) {
rlang::check_installed(
"usethis",
reason = "to use unit tests."
)

added <- use_utils(
file_name = "golem_utils_ui.R",
folder_name = "R",
Expand All @@ -30,7 +34,7 @@ use_utils_ui <- function(

if (with_test) {
if (!isTRUE(dir.exists("tests"))) {
use_testthat()
usethis::use_testthat()
}
pth <- path(
pkg,
Expand Down Expand Up @@ -82,7 +86,7 @@ use_utils_server <- function(

if (with_test) {
if (!isTRUE(dir.exists("tests"))) {
use_testthat()
usethis::use_testthat()
}
pth <- path(
pkg,
Expand Down

0 comments on commit 3d3d951

Please sign in to comment.