Skip to content

Commit dae1253

Browse files
committed
More tidyverse-specific pkgdown setup
Closes #1408 Also added 'tidymodels' to the list of orgs for which we do some special URL set up, as they seem to have the same scheme as 'tidyverse' and 'r-lib'
1 parent d854ad4 commit dae1253

File tree

11 files changed

+147
-42
lines changed

11 files changed

+147
-42
lines changed

β€ŽDESCRIPTIONβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Imports:
3434
crayon,
3535
curl (>= 2.7),
3636
ellipsis,
37-
desc (>= 1.3.0),
37+
desc (>= 1.4.0),
3838
fs (>= 1.3.0),
3939
gert (>= 1.4.1),
4040
gh (>= 1.2.1),

β€ŽNAMESPACEβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export(use_tidy_github_actions)
189189
export(use_tidy_github_labels)
190190
export(use_tidy_issue_template)
191191
export(use_tidy_labels)
192+
export(use_tidy_pkgdown_github_pages)
192193
export(use_tidy_style)
193194
export(use_tidy_support)
194195
export(use_tidy_thanks)

β€ŽR/description.Rβ€Ž

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#'
33
#' @description
44
#'
5+
56
#' `use_description()` creates a `DESCRIPTION` file. Although mostly associated
67
#' with R packages, a `DESCRIPTION` file can also be used to declare
7-
#' dependencies for a non-package projects. Within such a project,
8+
#' dependencies for a non-package project. Within such a project,
89
#' `devtools::install_deps()` can then be used to install all the required
910
#' packages. Note that, by default, `use_decription()` checks for a
1011
#' CRAN-compliant package name. You can turn this off with `check_name = FALSE`.
1112
#'
13+
1214
#' usethis consults the following sources, in this order, to set `DESCRIPTION`
1315
#' fields:
1416
#' * `fields` argument of [create_package()] or [use_description()]
@@ -40,9 +42,9 @@
4042
#'
4143
#' @param fields A named list of fields to add to `DESCRIPTION`, potentially
4244
#' overriding default values. See [use_description()] for how you can set
43-
#' personalized defaults using package options
45+
#' personalized defaults using package options.
4446
#' @param check_name Whether to check if the name is valid for CRAN and throw an
45-
#' error if not
47+
#' error if not.
4648
#' @param roxygen If `TRUE`, sets `RoxygenNote` to current roxygen2 version
4749
#' @seealso The [description chapter](https://r-pkgs.org/description.html)
4850
#' of [R Packages](https://r-pkgs.org)
@@ -161,3 +163,63 @@ tidy_desc <- function(desc) {
161163
# Wrap in a try() so it always succeeds, even if user options are malformed
162164
try(desc$normalize(), silent = TRUE)
163165
}
166+
167+
# 2021-10-10, while adding use_description_list(), I moved this helper here
168+
#
169+
# this helper feels out-of-sync with current usethis practices around active
170+
# project and how overwrite is handled
171+
#
172+
# I won't change use_description_field() now, but use_description_list() is
173+
# implemented differently, more in keeping with our current style
174+
use_description_field <- function(name,
175+
value,
176+
base_path = proj_get(),
177+
overwrite = FALSE) {
178+
# account for `value`s produced via `glue::glue()`
179+
value <- as.character(value)
180+
curr <- desc::desc_get(name, file = base_path)[[1]]
181+
curr <- gsub("^\\s*|\\s*$", "", curr)
182+
183+
if (identical(curr, value)) {
184+
return(invisible())
185+
}
186+
187+
if (!is.na(curr) && !overwrite) {
188+
ui_stop(
189+
"{ui_field(name)} has a different value in DESCRIPTION. \\
190+
Use {ui_code('overwrite = TRUE')} to overwrite."
191+
)
192+
}
193+
194+
ui_done("Setting {ui_field(name)} field in DESCRIPTION to {ui_value(value)}")
195+
desc::desc_set(name, value, file = base_path)
196+
invisible()
197+
}
198+
199+
use_description_list <- function(key,
200+
values,
201+
append = TRUE,
202+
desc = NULL) {
203+
desc_provided <- !is.null(desc)
204+
desc <- desc %||% desc::desc(file = proj_get())
205+
check_string(key)
206+
stopifnot(is.character(values))
207+
208+
if (append) {
209+
values <- unique(c(desc$get_list(key, default = ""), values))
210+
}
211+
# formatting needs some improvements
212+
# https://github.com/r-lib/desc/issues/117
213+
desc$set_list(key, values, sep = ",\n")
214+
215+
if (desc_provided) {
216+
return(invisible())
217+
}
218+
219+
tf <- withr::local_tempfile(
220+
pattern = glue("use_description_list-{project_name()}-{path_sanitize(key, '-')}")
221+
)
222+
desc$write(file = tf)
223+
tf_contents <- read_utf8(tf)
224+
write_over(proj_path("DESCRIPTION"), tf_contents)
225+
}

β€ŽR/github-actions.Rβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ use_github_action_pr_commands <- function(save_as = "pr-commands.yaml",
213213
#' `roxygen2::roxygenise()` and update the PR, and `/style` to run
214214
#' `styler::style_pkg()` and update the PR.
215215
#'
216-
#' This is how the tidyverse team checks its packages, but it is overkill for
217-
#' less widely used packages. Consider using the more streamlined workflows set
218-
#' up by [use_github_actions()] or [use_github_action_check_standard()].
216+
#' This is how the tidyverse team checks its packages, but it is overkill
217+
#' for less widely used packages. Consider using the more streamlined
218+
#' workflows set up by [use_github_actions()] or
219+
#' [use_github_action_check_standard()].
219220
#' @export
220221
#' @rdname tidyverse
221222
use_tidy_github_actions <- function() {

β€ŽR/helpers.Rβ€Ž

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
use_description_field <- function(name,
2-
value,
3-
base_path = proj_get(),
4-
overwrite = FALSE) {
5-
# account for `value`s produced via `glue::glue()`
6-
value <- as.character(value)
7-
curr <- desc::desc_get(name, file = base_path)[[1]]
8-
curr <- gsub("^\\s*|\\s*$", "", curr)
9-
10-
if (identical(curr, value)) {
11-
return(invisible())
12-
}
13-
14-
if (!is.na(curr) && !overwrite) {
15-
ui_stop(
16-
"{ui_field(name)} has a different value in DESCRIPTION. \\
17-
Use {ui_code('overwrite = TRUE')} to overwrite."
18-
)
19-
}
20-
21-
ui_done("Setting {ui_field(name)} field in DESCRIPTION to {ui_value(value)}")
22-
desc::desc_set(name, value, file = base_path)
23-
invisible()
24-
}
25-
261
use_dependency <- function(package, type, min_version = NULL) {
272
stopifnot(is_string(package))
283
stopifnot(is_string(type))

β€ŽR/pkgdown.Rβ€Ž

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' * `use_pkgdown_github_pages()`: implements the GitHub setup needed to
1212
#' automatically publish your pkgdown site to GitHub pages:
1313
#'
14+
#' - (first, it calls `use_pkgdown()`)
1415
#' - [use_github_pages()] prepares to publish the pkgdown site from the
1516
#' `github-pages` branch
1617
#' - [`use_github_action("pkgdown")`][use_github_action()] configures a
@@ -65,6 +66,28 @@ use_pkgdown_github_pages <- function() {
6566
site_url <- sub("/$", "", site$html_url)
6667
site_url <- tidyverse_url(url = site_url, tr = tr)
6768
use_pkgdown_url(url = site_url, tr = tr)
69+
70+
if (tr$repo_owner %in% c("tidyverse", "tidymodels")) {
71+
ui_done("
72+
Adding {ui_value('tidyverse/tidytemplate')} to \\
73+
{ui_field('Config/Needs/website')}")
74+
use_description_list("Config/Needs/website", "tidyverse/tidytemplate")
75+
}
76+
}
77+
78+
#' @details
79+
#' * `use_tidy_pkgdown_github_pages()` is basically
80+
#' [use_pkgdown_github_pages()], so does full pkgdown set up. Note that there
81+
#' is special handling for packages owned by certain GitHub organizations, in
82+
#' terms of anticipating the (eventual) site URL and the use of a pkgdown
83+
#' template.
84+
#' @export
85+
#' @rdname tidyverse
86+
use_tidy_pkgdown_github_pages <- function() {
87+
# the code that's conditional on the owning org is already in this function
88+
# this "tidy" version exists because it feels right and is a good place to
89+
# put docs
90+
use_pkgdown_github_pages()
6891
}
6992

7093
# helpers ----------------------------------------------------------------------
@@ -111,7 +134,8 @@ use_pkgdown_url <- function(url, tr = NULL) {
111134

112135
tidyverse_url <- function(url, tr = NULL) {
113136
tr <- tr %||% target_repo(github_get = TRUE)
114-
if (!is_interactive() || !tr$repo_owner %in% c("tidyverse", "r-lib")) {
137+
if (!is_interactive() ||
138+
!tr$repo_owner %in% c("tidyverse", "r-lib", "tidymodels")) {
115139
return(url)
116140
}
117141
custom_url <- glue("https://{tr$repo_name}.{tr$repo_owner}.org")

β€Žman/create_package.Rdβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žman/tidyverse.Rdβ€Ž

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žman/use_description.Rdβ€Ž

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žman/use_pkgdown.Rdβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)