Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't prompt user to install template package from CRAN #2495

Merged
merged 4 commits into from
Apr 24, 2024
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: 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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called from as_pkgdown(), so will be triggered early in all the build_* functions, and the call will point to a user facing function

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)
})
Loading