diff --git a/NAMESPACE b/NAMESPACE index b9b6527f3..fb68041eb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,6 +47,7 @@ export(install_svn) export(install_url) export(install_version) export(is.package) +export(is_loading) export(lint) export(load_all) export(loaded_packages) @@ -90,6 +91,7 @@ importFrom(pkgbuild,find_rtools) importFrom(pkgbuild,has_devel) importFrom(pkgbuild,with_debug) importFrom(pkgload,check_dep_version) +importFrom(pkgload,is_loading) importFrom(pkgload,parse_deps) importFrom(pkgload,unload) importFrom(remotes,dev_package_deps) diff --git a/NEWS.md b/NEWS.md index 8810e8904..698c98a8d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # devtools (development version) +* `is_loading()` is now re-exported from pkgload (#2556). +* `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617). + # devtools 2.4.6 * Functions that use httr now explicitly check that it is installed diff --git a/R/pkgload.R b/R/pkgload.R index 7cf9da1e7..ac6b960e2 100644 --- a/R/pkgload.R +++ b/R/pkgload.R @@ -14,6 +14,13 @@ load_all <- function( path <- path$path } + if (is_loading()) { + cli::cli_abort(c( + "Recursive loading detected.", + i = "Did you accidentally include {.fn load_all} in an R source file?" + )) + } + save_all() check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn)) @@ -29,6 +36,10 @@ load_all <- function( ) } +#' @importFrom pkgload is_loading +#' @export +pkgload::is_loading + #' @importFrom pkgload unload #' @export pkgload::unload diff --git a/man/reexports.Rd b/man/reexports.Rd index e001a381d..8393d78bf 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -10,6 +10,7 @@ \alias{clean_dll} \alias{has_devel} \alias{find_rtools} +\alias{is_loading} \alias{unload} \alias{github_pull} \alias{github_release} @@ -29,7 +30,7 @@ below to see their documentation. \describe{ \item{pkgbuild}{\code{\link[pkgbuild]{clean_dll}}, \code{\link[pkgbuild:has_rtools]{find_rtools}}, \code{\link[pkgbuild:has_compiler]{has_devel}}, \code{\link[pkgbuild]{with_debug}}} - \item{pkgload}{\code{\link[pkgload]{check_dep_version}}, \code{\link[pkgload]{parse_deps}}, \code{\link[pkgload]{unload}}} + \item{pkgload}{\code{\link[pkgload]{check_dep_version}}, \code{\link[pkgload:load_all]{is_loading}}, \code{\link[pkgload]{parse_deps}}, \code{\link[pkgload]{unload}}} \item{sessioninfo}{\code{\link[sessioninfo]{package_info}}, \code{\link[sessioninfo]{session_info}}} }} diff --git a/man/remote-reexports.Rd b/man/remote-reexports.Rd index 6a9bcc3fb..bef6a1c16 100644 --- a/man/remote-reexports.Rd +++ b/man/remote-reexports.Rd @@ -213,7 +213,9 @@ dev_package_deps( pkgdir = ".", dependencies = NA, repos = getOption("repos"), - type = getOption("pkgType") + type = getOption("pkgType"), + remote_precedence = TRUE, + additional_repositories = TRUE ) } \description{ diff --git a/tests/testthat/_snaps/pkgload.md b/tests/testthat/_snaps/pkgload.md new file mode 100644 index 000000000..87996a004 --- /dev/null +++ b/tests/testthat/_snaps/pkgload.md @@ -0,0 +1,9 @@ +# load_all() errors if called recursively + + Code + load_all() + Condition + Error in `load_all()`: + ! Recursive loading detected. + i Did you accidentally include `load_all()` in an R source file? + diff --git a/tests/testthat/test-pkgload.R b/tests/testthat/test-pkgload.R new file mode 100644 index 000000000..e871848e4 --- /dev/null +++ b/tests/testthat/test-pkgload.R @@ -0,0 +1,4 @@ +test_that("load_all() errors if called recursively", { + local_mocked_bindings(is_loading = function() TRUE) + expect_snapshot(load_all(), error = TRUE) +})