Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion R/aaa-shared_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#' @param endpoint (`character(1)`) The operation endpoint.
#' @param endpoints (`character`) Endpoint paths paired with operations.
#' @param filter_in (`character(1)`) The parameter location to keep.
#' @param include_stbl (`logical(1)`) Whether to add `stbl` to Imports.
#' @param methods (`character`) HTTP methods paired with endpoints.
#' @param operation (`character(1)`) The HTTP method.
#' @param operation_description (`character(1)`) The operation description.
Expand Down
53 changes: 42 additions & 11 deletions R/generate_pkg-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,47 @@
#' @inheritParams .shared-params
#' @returns (`NULL`, invisibly) Called for setup side effects.
#' @keywords internal
.setup_r <- function(pkg_dir, include_stbl = FALSE) {
if (as.character(pkg_dir) != ".") {
usethis::local_project(pkg_dir, quiet = TRUE) # nocov
}
usethis::use_directory("R")
usethis::use_testthat()
purrr::quietly(httptest2::use_httptest2)()
usethis::use_package("nectar")
if (include_stbl) {
usethis::use_package("stbl")
.setup_r <- function(pkg_dir) {
usethis::with_project(
pkg_dir,
{
usethis::use_directory("R")
withr::with_options(list(usethis.quiet = TRUE), usethis::use_testthat())
purrr::quietly(httptest2::use_httptest2)()
},
quiet = TRUE
)
.use_package("nectar", "Imports", pkg_dir)
.use_package("beekeeper", "Suggests", pkg_dir)
}

#' Add a package dependency to the DESCRIPTION file
#'
#' @param pkg (`character(1)`) The package name.
#' @param type (`character(1)`) The dependency type, one of "Imports",
#' "Suggests", or "Depends".
#' @inheritParams .shared-params
#' @returns (`character(1)`, invisibly) The package name.
#' @keywords internal
.use_package <- function(pkg, type = "Imports", pkg_dir = ".") {
usethis::with_project(
pkg_dir,
{
usethis::use_package(pkg, type = type)
},
quiet = TRUE
)
invisible(pkg)
}

#' Add stbl to dependencies if needed
#'
#' @inheritParams .shared-params
#' @returns (`character(1)` or `NULL`, invisibly) "stbl" if stbl is used, `NULL`
#' otherwise.
#' @keywords internal
.maybe_use_stbl <- function(pkg_dir, paths, security_arg_names) {
if (.paths_need_stbl(paths, security_arg_names)) {
.use_package("stbl", "Imports", pkg_dir)
}
usethis::use_package("beekeeper", type = "Suggests")
}
6 changes: 2 additions & 4 deletions R/generate_pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ generate_pkg <- function(
api_definition@components@security_schemes
)
security_arg_names <- security_data$security_arg_names %|0|% character()
.setup_r(
pkg_dir,
include_stbl = .paths_need_stbl(api_definition@paths, security_arg_names)
)
.setup_r(pkg_dir)
.maybe_use_stbl(pkg_dir, api_definition@paths, security_arg_names)
touched_files <- .generate_pkg_impl(config, api_definition, security_data)
return(invisible(touched_files))
}
Expand Down
26 changes: 26 additions & 0 deletions man/dot-maybe_use_stbl.Rd

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

4 changes: 1 addition & 3 deletions man/dot-setup_r.Rd

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

2 changes: 0 additions & 2 deletions man/dot-shared-params.Rd

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

24 changes: 24 additions & 0 deletions man/dot-use_package.Rd

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

31 changes: 21 additions & 10 deletions tests/testthat/test-generate_pkg-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,25 @@ test_that(".setup_r() sets up dependencies (#16)", {
)
})

test_that(".setup_r() can include stbl in imports (#69)", {
skip_on_cran()

create_local_package()
.setup_r(".", include_stbl = TRUE)

dependencies <- desc::desc()$get_deps()
imports <- dependencies$package[dependencies$type == "Imports"]
expect_contains(imports, "nectar")
expect_contains(imports, "stbl")
test_that(".maybe_use_stbl() can add stbl to imports (#69)", {
local_mocked_bindings(
.use_package = function(pkg, type, pkg_dir) {
if (pkg == "stbl") {
expect_equal(type, "Imports")
expect_equal(pkg_dir, "DIR")
}
return(pkg)
},
.paths_need_stbl = function(paths, security_arg_names) {
expect_equal(security_arg_names, "SECURITY_ARG_NAMES")
return(paths == "INSTALL")
}
)
expect_equal(
.maybe_use_stbl("DIR", "INSTALL", "SECURITY_ARG_NAMES"),
"stbl"
)
expect_null(
.maybe_use_stbl("DIR", "DONOTINSTALL", "SECURITY_ARG_NAMES")
)
})
Loading