Skip to content

Commit

Permalink
Don't prompt user to install template package from CRAN
Browse files Browse the repository at this point in the history
Fixes #2076
  • Loading branch information
hadley committed Apr 24, 2024
1 parent 502c886 commit a0605fc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* `as.pkgdown()` will no longer prompt you to install a missing template package from CRAN, since these are almost always found in GitHub (#2076).
* `init_site()` once again describes one copy per line, and now uses a better prefix when copying assets from pkgdown itself (#2445).
* Very wide words are now automatically broken across lines and hyphenated (when possible) when they'd otherwise create a horizontal scrollbar on mobile (#1888).
* The `repo.source.url` field no longer requires a trailing slash (#2017).
Expand Down
11 changes: 9 additions & 2 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,19 @@ package_vignettes <- function(path = ".") {
out[order(basename(out$file_out)), ]
}

find_template_config <- function(package, bs_version = NULL) {
find_template_config <- function(package,
bs_version = NULL,
error_call = caller_env()) {
if (is.null(package)) {
return(list())
}

config <- path_package_pkgdown("_pkgdown.yml", package, bs_version)
config <- path_package_pkgdown(
"_pkgdown.yml",
package,
bs_version,
error_call = error_call
)
if (!file_exists(config)) {
return(list())
}
Expand Down
17 changes: 15 additions & 2 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,21 @@ path_first_existing <- function(...) {
NULL
}

path_package_pkgdown <- function(path, package, bs_version) {
check_installed(package)
path_package_pkgdown <- function(path,
package,
bs_version,
error_call = caller_env()) {
# package will usually be a github package, and check_installed()
# tries to install from CRAN, which is highly likely to fail.
if (!is_installed(package)) {
cli::cli_abort(
c(
"Template package {.val {package}} is not installed.",
i = "Please install before continuing"
),
call = error_call
)
}
base <- system_file("pkgdown", package = package)

# If bs_version supplied, first try for versioned template
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/utils-fs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# missing template package yields custom error

Code
path_package_pkgdown("x", "missing", 3)
Condition
Error:
! Template package "missing" is not installed.
i Please install before continuing

3 changes: 3 additions & 0 deletions tests/testthat/test-utils-fs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("missing template package yields custom error", {
expect_snapshot(path_package_pkgdown("x", "missing", 3), error = TRUE)
})

0 comments on commit a0605fc

Please sign in to comment.