From 7a5d9bcbfc5d75afc08b17cf61cddefd6a01f16a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 30 Sep 2021 18:00:53 -0500 Subject: [PATCH 01/14] Use bs4 with dev pkgdown Fixes https://github.com/r- lib/pkgdown/issues/1580 --- NEWS.md | 3 +++ R/pkgdown.R | 33 +++++++++++++++++++-------------- tests/testthat/test-pkgdown.R | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index ee0769379..8b06f0141 100644 --- a/NEWS.md +++ b/NEWS.md @@ -58,6 +58,9 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_lifecycle()` now imports `lifecycle::deprecated()` (#1419). +* `use_pkgdown()` automatically uses bs4 if you have the devel version + of pkgdown installed. + * `use_code_of_conduct()` now requires a `contact` argument to supply contact details for reporting CoC violations (#1269). diff --git a/R/pkgdown.R b/R/pkgdown.R index 31fff22f2..def5be28c 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -4,9 +4,8 @@ #' [pkgdown](https://pkgdown.r-lib.org) makes it easy to turn your package into #' a beautiful website. usethis provides two functions to help you use pkgdown: #' -#' * `use_pkgdown()`: creates a pkgdown config file, adds relevant files or -#' directories to `.Rbuildignore` and `.gitignore`, and builds favicons if -#' your package has a logo. +#' * `use_pkgdown()`: creates a pkgdown config file and adds relevant files or +#' directories to `.Rbuildignore` and `.gitignore`. #' #' * `use_pkgdown_github_pages()`: implements the GitHub setup needed to #' automatically publish your pkgdown site to GitHub pages: @@ -31,25 +30,31 @@ use_pkgdown <- function(config_file = "_pkgdown.yml", destdir = "docs") { check_is_package("use_pkgdown()") check_installed("pkgdown") - use_build_ignore(c(config_file, destdir)) - use_build_ignore("pkgdown") + use_build_ignore(c(config_file, destdir, "pkgdown")) use_git_ignore(destdir) - ui_todo(" - Record your site's {ui_field('url')} in the pkgdown config file \\ - (optional, but recommended)") + config <- pkgdown_config(destdir) + config_path <- proj_path(config_file) + write_over(config_path, yaml::as.yaml(config)) + edit_file(config_path) - if (has_logo()) { - pkgdown_build_favicons(proj_get(), overwrite = TRUE) + invisible(TRUE) +} + +pkgdown_config <- function(destdir) { + config <- list( + url = NULL + ) + + if (packageVersion("pkgdown") >= "1.9000") { + config$template <- list(bootstrap = 4L) } - config <- proj_path(config_file) if (!identical(destdir, "docs")) { - write_over(config, paste("destination:", destdir)) + config$destination <- destdir } - edit_file(config) - invisible(TRUE) + config } # tidyverse pkgdown setup ------------------------------------------------------ diff --git a/tests/testthat/test-pkgdown.R b/tests/testthat/test-pkgdown.R index 3b94bcea5..264066131 100644 --- a/tests/testthat/test-pkgdown.R +++ b/tests/testthat/test-pkgdown.R @@ -31,7 +31,7 @@ test_that("pkgdown_config_meta() returns a list", { check_installed = function(pkg) TRUE, use_pkgdown() ) - expect_equal(pkgdown_config_meta(), list()) + expect_equal(pkgdown_config_meta(), list(url = NULL)) writeLines(c("home:", " strip_header: true"), pkgdown_config_path()) expect_equal( pkgdown_config_meta(), From a874b1ec9d1fa95e06acd6ff0e5aa588256708ab Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 1 Oct 2021 08:15:33 -0500 Subject: [PATCH 02/14] Tweak news bullet --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8b06f0141..7cedd59b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -58,8 +58,8 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_lifecycle()` now imports `lifecycle::deprecated()` (#1419). -* `use_pkgdown()` automatically uses bs4 if you have the devel version - of pkgdown installed. +* `use_pkgdown()` automatically uses bs4 if you have devel pkgdown (which + will become 2.0.0) installed. * `use_code_of_conduct()` now requires a `contact` argument to supply contact details for reporting CoC violations (#1269). From 106fd063dd3669b53907b19972e1b777025aca75 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 1 Oct 2021 08:29:29 -0500 Subject: [PATCH 03/14] Now need pkgdown installed --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 551859e66..f4de4e4a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,6 +56,7 @@ Suggests: knitr, magick, mockr, + pkgdown, pkgload, rmarkdown, roxygen2, From 2a7d5dfa4ff3a15236b622eb980cf6f8423a91dc Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 1 Oct 2021 08:31:07 -0500 Subject: [PATCH 04/14] Add missing namespace --- R/pkgdown.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pkgdown.R b/R/pkgdown.R index def5be28c..1c289a309 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -46,7 +46,7 @@ pkgdown_config <- function(destdir) { url = NULL ) - if (packageVersion("pkgdown") >= "1.9000") { + if (utils::packageVersion("pkgdown") >= "1.9000") { config$template <- list(bootstrap = 4L) } From 49d454f69fb293131fde0b0245d4e529c098ac04 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 1 Oct 2021 08:34:04 -0500 Subject: [PATCH 05/14] Relax test --- tests/testthat/test-pkgdown.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-pkgdown.R b/tests/testthat/test-pkgdown.R index 264066131..9b048e01b 100644 --- a/tests/testthat/test-pkgdown.R +++ b/tests/testthat/test-pkgdown.R @@ -31,7 +31,8 @@ test_that("pkgdown_config_meta() returns a list", { check_installed = function(pkg) TRUE, use_pkgdown() ) - expect_equal(pkgdown_config_meta(), list(url = NULL)) + expect_type(pkgdown_config_meta(), "list") + writeLines(c("home:", " strip_header: true"), pkgdown_config_path()) expect_equal( pkgdown_config_meta(), From b155ce7aa07863e87c09becf682ce8774833a8f2 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 1 Oct 2021 08:37:30 -0500 Subject: [PATCH 06/14] Tweak news bullet --- NEWS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7cedd59b8..76cb5b085 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,6 +34,9 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_release_issue()` also takes bullets from `release_questions()`, for compatibility with `devtools::release()`. +* `use_pkgdown()` automatically uses bootstrap4 if you have devel pkgdown (which + will become 2.0.0) installed. + * `git_vaccinate()`, `edit_git_ignore()`, and `git_sitrep()` are more careful to consult, reveal, and set the `core.excludesFile` in user's Git configuration (#1461). @@ -58,9 +61,6 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_lifecycle()` now imports `lifecycle::deprecated()` (#1419). -* `use_pkgdown()` automatically uses bs4 if you have devel pkgdown (which - will become 2.0.0) installed. - * `use_code_of_conduct()` now requires a `contact` argument to supply contact details for reporting CoC violations (#1269). From 0044185d1756db6900d446bcc93fe76438d81269 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 1 Oct 2021 12:10:29 -0700 Subject: [PATCH 07/14] Delete pkgdown_build_favicons() and has_logo() --- R/logo.R | 5 ----- R/pkgdown.R | 13 +------------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/R/logo.R b/R/logo.R index cfc3eac00..c1d09b12b 100644 --- a/R/logo.R +++ b/R/logo.R @@ -56,8 +56,3 @@ use_logo <- function(img, geometry = "240x278", retina = TRUE) { ui_code_block("# {pkg} ") } } - -has_logo <- function() { - file_exists(proj_path("man", "figures", "logo.png")) || - file_exists(proj_path("man", "figures", "logo.svg")) -} diff --git a/R/pkgdown.R b/R/pkgdown.R index 1c289a309..4d4c0b084 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -220,16 +220,11 @@ use_pkgdown_travis <- function() { tr <- target_repo(github_get = TRUE) - use_build_ignore("docs/") + use_build_ignore(c("docs/", "pkgdown")) use_git_ignore("docs/") # TODO: suggest git rm -r --cache docs/ # Can't currently detect if git known files in that directory - if (has_logo()) { - pkgdown_build_favicons(proj_get(), overwrite = TRUE) - use_build_ignore("pkgdown") - } - ui_todo(" Set up deploy keys by running {ui_code('travis::use_travis_deploy()')}") ui_todo("Insert the following code in {ui_path('.travis.yml')}") @@ -247,9 +242,3 @@ use_pkgdown_travis <- function() { invisible() } - -# usethis itself should not depend on pkgdown -# all usage of this wrapper is guarded by `check_installed("pkgdown")` -pkgdown_build_favicons <- function(...) { - get("build_favicons", asNamespace("pkgdown"), mode = "function")(...) -} From f1ff785ffe3cb55dba48883649f2f5d4cfb4a6b4 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 1 Oct 2021 12:14:05 -0700 Subject: [PATCH 08/14] usethis does not and should not depend on pkgdown --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f4de4e4a2..551859e66 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,7 +56,6 @@ Suggests: knitr, magick, mockr, - pkgdown, pkgload, rmarkdown, roxygen2, From f0e8933349f374795f81bf862c02c4b925871122 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 1 Oct 2021 12:18:28 -0700 Subject: [PATCH 09/14] Reword --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 76cb5b085..2b85a8ed2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,8 +34,8 @@ usethis has a more sophisticated understanding of the default branch and gains s * `use_release_issue()` also takes bullets from `release_questions()`, for compatibility with `devtools::release()`. -* `use_pkgdown()` automatically uses bootstrap4 if you have devel pkgdown (which - will become 2.0.0) installed. +* `use_pkgdown()` automatically uses bootstrap4 if the pkgdown version supports + it (anticipated for pkgdown 2.0.0). * `git_vaccinate()`, `edit_git_ignore()`, and `git_sitrep()` are more careful to consult, reveal, and set the `core.excludesFile` in user's Git configuration From d5eea2d2edc1efc52e6dee74093a0276da5043e8 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Oct 2021 08:06:05 -0700 Subject: [PATCH 10/14] Move comment --- R/pkgdown.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/pkgdown.R b/R/pkgdown.R index 4d4c0b084..3248cd398 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -57,8 +57,6 @@ pkgdown_config <- function(destdir) { config } -# tidyverse pkgdown setup ------------------------------------------------------ - #' @rdname use_pkgdown #' @export use_pkgdown_github_pages <- function() { @@ -80,6 +78,8 @@ use_pkgdown_github_pages <- function() { } } +# tidyverse pkgdown setup ------------------------------------------------------ + #' @details #' * `use_tidy_pkgdown_github_pages()` is basically #' [use_pkgdown_github_pages()], so does full pkgdown set up. Note that there From 2352d1270a04c830c079bc91543933f75bf00bd9 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Oct 2021 08:31:55 -0700 Subject: [PATCH 11/14] Use YAML-parsing/writing approach here too --- R/pkgdown.R | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/R/pkgdown.R b/R/pkgdown.R index 3248cd398..74a41c8e0 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -99,20 +99,17 @@ use_tidy_pkgdown_github_pages <- function() { use_pkgdown_url <- function(url, tr = NULL) { tr <- tr %||% target_repo(github_get = TRUE) - config <- pkgdown_config_path() - config_lines <- read_utf8(config) - url_line <- paste0("url: ", url) - if (!any(grepl(url_line, config_lines))) { - ui_done(" - Recording {ui_value(url)} as site's {ui_field('url')} in \\ - {ui_path(config)}") - config_lines <- config_lines[!grepl("^url:", config_lines)] - write_utf8(config, c( - url_line, - if (length(config_lines) && nzchar(config_lines[[1]])) "", - config_lines - )) + config_path <- pkgdown_config_path() + ui_done(" + Recording {ui_value(url)} as site's {ui_field('url')} in \\ + {ui_path(config_path)}") + config <- pkgdown_config_meta() + if (has_name(config, "url")) { + config$url <- url + } else { + config <- c(url = url, config) } + write_utf8(config_path, yaml::as.yaml(config)) urls <- desc::desc_get_urls() if (!url %in% urls) { From 0a7ac0ec352b92455b219f01d14a5398c85908d0 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Oct 2021 08:36:51 -0700 Subject: [PATCH 12/14] desc has a function for this (adding URLs) --- R/pkgdown.R | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/R/pkgdown.R b/R/pkgdown.R index 74a41c8e0..cf5b9d0d3 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -111,17 +111,10 @@ use_pkgdown_url <- function(url, tr = NULL) { } write_utf8(config_path, yaml::as.yaml(config)) - urls <- desc::desc_get_urls() - if (!url %in% urls) { - ui_done("Adding {ui_value(url)} to {ui_field('URL')} field in DESCRIPTION") - ui_silence( - use_description_field( - "URL", - glue_collapse(c(url, urls), ", "), - overwrite = TRUE - ) - ) - } + ui_done("Adding {ui_value(url)} to {ui_field('URL')} field in DESCRIPTION") + desc <- desc::desc(file = proj_get()) + desc$add_urls(url) + desc$write() gh <- gh_tr(tr) homepage <- gh("GET /repos/{owner}/{repo}")[["homepage"]] From 9397a1cd4bbeb014a608d3ab6189559bf178b516 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Oct 2021 08:38:56 -0700 Subject: [PATCH 13/14] Re-document() --- man/use_pkgdown.Rd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/man/use_pkgdown.Rd b/man/use_pkgdown.Rd index cce253192..d11a5903e 100644 --- a/man/use_pkgdown.Rd +++ b/man/use_pkgdown.Rd @@ -21,9 +21,8 @@ use_pkgdown_travis() \href{https://pkgdown.r-lib.org}{pkgdown} makes it easy to turn your package into a beautiful website. usethis provides two functions to help you use pkgdown: \itemize{ -\item \code{use_pkgdown()}: creates a pkgdown config file, adds relevant files or -directories to \code{.Rbuildignore} and \code{.gitignore}, and builds favicons if -your package has a logo. +\item \code{use_pkgdown()}: creates a pkgdown config file and adds relevant files or +directories to \code{.Rbuildignore} and \code{.gitignore}. \item \code{use_pkgdown_github_pages()}: implements the GitHub setup needed to automatically publish your pkgdown site to GitHub pages: \itemize{ From 5020006cdab2027977f853262f77135b77ec4eaa Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 13 Oct 2021 10:07:59 -0700 Subject: [PATCH 14/14] Fix some tests --- R/pkgdown.R | 7 ++++++- tests/testthat/test-pkgdown.R | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/pkgdown.R b/R/pkgdown.R index cf5b9d0d3..6b9fdca72 100644 --- a/R/pkgdown.R +++ b/R/pkgdown.R @@ -46,7 +46,7 @@ pkgdown_config <- function(destdir) { url = NULL ) - if (utils::packageVersion("pkgdown") >= "1.9000") { + if (pkgdown_version() >= "1.9000") { config$template <- list(bootstrap = 4L) } @@ -57,6 +57,11 @@ pkgdown_config <- function(destdir) { config } +# wrapping because I need to be able to mock this in tests +pkgdown_version <- function() { + utils::packageVersion("pkgdown") +} + #' @rdname use_pkgdown #' @export use_pkgdown_github_pages <- function() { diff --git a/tests/testthat/test-pkgdown.R b/tests/testthat/test-pkgdown.R index 9b048e01b..11c4bd62d 100644 --- a/tests/testthat/test-pkgdown.R +++ b/tests/testthat/test-pkgdown.R @@ -8,6 +8,7 @@ test_that("use_pkgdown() creates and ignores the promised file/dir", { local_interactive(FALSE) with_mock( check_installed = function(pkg) TRUE, + pkgdown_version = function() "1.9000", use_pkgdown() ) expect_true(uses_pkgdown()) @@ -29,6 +30,7 @@ test_that("pkgdown_config_meta() returns a list", { local_interactive(FALSE) with_mock( check_installed = function(pkg) TRUE, + pkgdown_version = function() "1.9000", use_pkgdown() ) expect_type(pkgdown_config_meta(), "list") @@ -45,6 +47,7 @@ test_that("pkgdown_url() returns correct data, warns if pedantic", { local_interactive(FALSE) with_mock( check_installed = function(pkg) TRUE, + pkgdown_version = function() "1.9000", use_pkgdown() )