Skip to content

Commit 7cc2bdf

Browse files
authored
Use cli for messaging (#2429)
* Update active.R + test * Update build-readme.R and tests * Update find_active_file(). Includes wrapper around rstudioapi::isAvailable() that returns FALSE when testing. * Update change_maintainer_email() + tests. Refactoring Maintainer check to make it more consistent * use_lifecycle() * Update package.R and tests. I realised that there was no way for `create` to work because `package_file()` will always error if it doesn't find a `DESCRIPTION`. So I deprecated it and removed the unused code * Re-document * Update release.R. I removed `email()` and `email_browser()` since as far as I can tell they are not used anywhere, and represent a very old style of CRAN submission. I don't know how to unit test this code so I did my best to carefully execute each change by hand. * Improve package_file() error * Fix R CMD check failure * Simplify local_package_create(). And give it a name consistent with latest standards * Update run-source.R + tests * Fix remaining simple stop() calls * Convert cli_alert_* to cli_inform() (except for vignette.R, which I'll do in #2425) Closes #2364
1 parent c2637bd commit 7cc2bdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+455
-326
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Imports:
2222
DT (>= 0.21),
2323
ellipsis (>= 0.3.2),
2424
fs (>= 1.5.2),
25+
lifecycle (>= 1.0.1),
2526
memoise (>= 2.0.1),
2627
miniUI (>= 0.1.1.1),
2728
pkgbuild (>= 1.3.1),
@@ -51,7 +52,6 @@ Suggests:
5152
gmailr (>= 1.0.1),
5253
httr (>= 1.4.2),
5354
knitr (>= 1.37),
54-
lifecycle (>= 1.0.1),
5555
lintr (>= 2.0.1),
5656
MASS,
5757
mockery (>= 0.4.3),

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import(fs)
8383
importFrom(cli,cat_bullet)
8484
importFrom(cli,cat_rule)
8585
importFrom(ellipsis,check_dots_used)
86+
importFrom(lifecycle,deprecated)
8687
importFrom(memoise,memoise)
8788
importFrom(pkgbuild,clean_dll)
8889
importFrom(pkgbuild,find_rtools)

R/active.R

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
find_active_file <- function(arg = "file") {
2-
if (!rstudioapi::isAvailable()) {
3-
stop("Argument `", arg, "` is missing, with no default", call. = FALSE)
1+
find_active_file <- function(arg = "file", call = parent.frame()) {
2+
if (!is_rstudio_running()) {
3+
cli::cli_abort("Argument {.arg {arg}} is missing, with no default", call = call)
44
}
55
normalizePath(rstudioapi::getSourceEditorContext()$path)
66
}
77

8-
find_test_file <- function(path) {
8+
find_test_file <- function(path, call = parent.frame()) {
99
type <- test_file_type(path)
1010
if (any(is.na(type))) {
11-
rlang::abort(c(
12-
"Don't know how to find tests associated with the active file:",
13-
path[is.na(type)]
14-
))
11+
file <- path_file(path[is.na(type)])
12+
cli::cli_abort(
13+
"Don't know how to find tests associated with the active file {.file {file}}",
14+
call = call
15+
)
1516
}
1617

1718
is_test <- type == "test"
1819
path[!is_test] <- paste0("tests/testthat/test-", name_source(path[!is_test]), ".R")
1920
path <- unique(path[file_exists(path)])
2021

2122
if (length(path) == 0) {
22-
rlang::abort("No test files found")
23+
cli::cli_abort("No test files found", call = call)
2324
}
2425
path
2526
}

R/build-manual.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build_manual <- function(pkg = ".", path = NULL) {
1717
), fail_on_status = TRUE, stderr = "2>&1", spinner = FALSE),
1818
error = function(e) {
1919
cat(e$stdout)
20-
stop("Failed to build manual", call. = FALSE)
20+
cli::cli_abort("Failed to build manual")
2121
})
2222

2323
cat(msg$stdout)

R/build-readme.R

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = T
2828
cli::cli_abort("Can't find file{?s}: {.path {files[!ok]}}.")
2929
}
3030

31-
cli::cli_alert_info("Installing {.pkg {pkg$package}} in temporary library")
31+
cli::cli_inform(c(i = "Installing {.pkg {pkg$package}} in temporary library"))
3232
withr::local_temp_libpaths()
3333
install(pkg, upgrade = "never", reload = FALSE, quick = TRUE, quiet = quiet)
3434

@@ -37,7 +37,7 @@ build_rmd <- function(files, path = ".", output_options = list(), ..., quiet = T
3737

3838

3939
for (path in paths) {
40-
cli::cli_alert_info("Building {.path {path}}")
40+
cli::cli_inform(c(i = "Building {.path {path}}"))
4141
callr::r_safe(
4242
function(...) rmarkdown::render(...),
4343
args = list(input = path, ..., output_options = output_options, quiet = quiet),
@@ -58,11 +58,10 @@ build_readme <- function(path = ".", quiet = TRUE, ...) {
5858
readme_path <- path_abs(dir_ls(pkg$path, ignore.case = TRUE, regexp = "(inst/)?readme[.]rmd", recurse = 1, type = "file"))
5959

6060
if (length(readme_path) == 0) {
61-
rlang::abort("Can't find a 'README.Rmd' or 'inst/README.Rmd' file.")
61+
cli::cli_abort("Can't find {.file README.Rmd} or {.file inst/README.Rmd}.")
6262
}
63-
6463
if (length(readme_path) > 1) {
65-
rlang::abort("Can't have both a 'README.Rmd' and 'inst/README.Rmd' file.")
64+
cli::cli_abort("Can't have both {.file README.Rmd} and {.file inst/README.Rmd}.")
6665
}
6766

6867
build_rmd(readme_path, path = path, quiet = quiet, ...)

R/check-devtools.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ check_status <- function(status, name, warning) {
131131
cat(" OK\n")
132132
} else {
133133
cat("\n")
134-
cli::cli_alert_danger("WARNING: {warning}")
134+
cli::cli_inform(c(x = "WARNING: {warning}"))
135135
},
136136
error = function(e) {
137137
cat("\n")
138-
cli::cli_alert_danger("ERROR: {conditionMessage(e)}")
138+
cli::cli_inform(c(x = "ERROR: {conditionMessage(e)}"))
139139
FALSE
140140
}
141141
)

R/check-doc.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ check_man <- function(pkg = ".") {
2020
old <- options(warn = -1)
2121
on.exit(options(old))
2222

23-
cli::cli_alert_info("Checking documentation...")
23+
cli::cli_inform(c(i = "Checking documentation..."))
2424

2525
check_Rd_contents <- if (getRversion() < "4.1") {
2626
asNamespace("tools")$.check_Rd_contents
@@ -42,7 +42,7 @@ check_man <- function(pkg = ".") {
4242
)
4343

4444
if (ok) {
45-
cli::cli_alert_success("No issues detected")
45+
cli::cli_inform(c(v = "No issues detected"))
4646
}
4747

4848
invisible()

R/check-mac.R

+7-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ check_mac_release <- function(pkg = ".", dep_pkgs = character(), args = NULL, ma
1616
pkg <- as.package(pkg)
1717

1818
if (!quiet) {
19-
cli::cli_alert_info(
19+
cli::cli_inform(c(
2020
"Building macOS version of {.pkg {pkg$package}} ({pkg$version})",
21-
"with https://mac.r-project.org/macbuilder/submit.html."
22-
)
21+
i = "Using https://mac.r-project.org/macbuilder/submit.html."
22+
))
2323
}
2424

2525
built_path <- pkgbuild::build(pkg$path, tempdir(),
@@ -62,9 +62,10 @@ check_mac_release <- function(pkg = ".", dep_pkgs = character(), args = NULL, ma
6262
if (!quiet) {
6363
time <- strftime(Sys.time() + 10 * 60, "%I:%M %p")
6464

65-
cli::cli_alert_success(
66-
"[{Sys.Date()}] Check {.url {response_url}} for the results in 5-10 mins (~{time})."
67-
)
65+
cli::cat_rule(col = "cyan")
66+
cli::cli_inform(c(
67+
i = "Check {.url {response_url}} the results in 5-10 mins (~{time})."
68+
))
6869
}
6970

7071
invisible(response_url)

R/check-win.R

+26-18
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
6161
file_copy(desc_file, backup)
6262
on.exit(file_move(backup, desc_file), add = TRUE)
6363

64-
change_maintainer_email(desc_file, email)
64+
change_maintainer_email(desc_file, email, call = parent.frame())
6565

6666
pkg <- as.package(pkg$path)
6767
}
6868

6969
version <- match.arg(version, several.ok = TRUE)
7070

7171
if (!quiet) {
72-
cli::cli_alert_info(
72+
cli::cli_inform(c(
7373
"Building windows version of {.pkg {pkg$package}} ({pkg$version})",
74-
" for {paste(version, collapse = ', ')} with win-builder.r-project.org."
75-
)
74+
i = "Using {paste(version, collapse = ', ')} with win-builder.r-project.org."
75+
))
7676

77-
email <- cli::style_bold(maintainer(pkg)$email)
78-
if (interactive() && yesno("Email results to ", email, "?")) {
77+
email <- maintainer(pkg)$email
78+
if (interactive() && yesno("Email results to {.strong {email}}?")) {
7979
return(invisible())
8080
}
8181
}
@@ -96,32 +96,40 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
9696
time <- strftime(Sys.time() + 30 * 60, "%I:%M %p")
9797
email <- maintainer(pkg)$email
9898

99-
cli::cli_alert_success(
100-
"[{Sys.Date()}] Check <{.email {email}}> for a link to results in 15-30 mins (~{time})."
101-
)
99+
cli::cat_rule(col = "cyan")
100+
cli::cli_inform(c(
101+
i = "Check <{.email {email}}> for the results in 15-30 mins (~{time})."
102+
))
102103
}
103104

104105
invisible()
105106
}
106107

107-
change_maintainer_email <- function(desc, email) {
108-
desc <- desc::desc(file = desc)
108+
change_maintainer_email <- function(path, email, call = parent.frame()) {
109+
desc <- desc::desc(file = path)
109110

110111
if (!desc$has_fields("Authors@R")) {
111-
stop("DESCRIPTION must use `Authors@R` field to change the maintainer email", call. = FALSE)
112+
cli::cli_abort(
113+
"DESCRIPTION must use {.field Authors@R} field when changing {.arg email}",
114+
call = call
115+
)
116+
}
117+
if (desc$has_fields("Maintainer")) {
118+
cli::cli_abort(
119+
"DESCRIPTION can't use {.field Maintainer} field when changing {.arg email}",
120+
call = call
121+
)
112122
}
123+
113124
aut <- desc$get_authors()
114125
roles <- aut$role
115126
## Broken person() API, vector for 1 author, list otherwise...
116-
if (!is.list(roles)) roles <- list(roles)
127+
if (!is.list(roles)) {
128+
roles <- list(roles)
129+
}
117130
is_maintainer <- vapply(roles, function(r) all("cre" %in% r), logical(1))
118131
aut[is_maintainer]$email <- email
119-
120132
desc$set_authors(aut)
121-
## Check if the email is actually changed before we actually send the email
122-
if(!grepl(email, desc$get_maintainer())){
123-
stop("Changing maintainer email failed. Possible reason is using both Authors@R and Maintainer fields in the DESCRIPTION file.", call. = FALSE)
124-
}
125133

126134
desc$write()
127135
}

R/check.R

+6-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ check <- function(pkg = ".",
7676
save_all()
7777

7878
if (!missing(cleanup)) {
79-
warning("`cleanup` is deprecated", call. = FALSE)
79+
lifecycle::deprecate_stop("1.11.0", "lifecycle::check(cleanup = )")
8080
}
8181

8282
if (missing(error_on) && !interactive()) {
@@ -145,12 +145,11 @@ can_document <- function(pkg) {
145145
installed <- packageVersion("roxygen2")
146146
if (required != installed) {
147147
cli::cli_rule()
148-
cli::cli_alert_info(
149-
"Installed roxygen2 version ({installed}) doesn't match required version ({required})"
150-
)
151-
cli::cli_alert_danger("check() will not re-document this package")
148+
cli::cli_inform(c(
149+
i = "Installed roxygen2 version ({installed}) doesn't match required ({required})",
150+
x = "{.fun check} will not re-document this package"
151+
))
152152
cli::cli_rule()
153-
154153
FALSE
155154
} else {
156155
TRUE
@@ -199,7 +198,7 @@ check_built <- function(path = NULL, cran = TRUE,
199198
}
200199

201200
if (manual && !pkgbuild::has_latex()) {
202-
cli::cli_alert_danger("pdflatex not found! Not building PDF manual or vignettes")
201+
cli::cli_inform(c(x = "pdflatex not found! Not building PDF manual"))
203202
manual <- FALSE
204203
}
205204

R/dev-mode.R

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ dev_mode <- local({
3232
dir_create(path)
3333
}
3434
if (!file_exists(path)) {
35-
stop("Failed to create ", path, call. = FALSE)
35+
cli::cli_abort("Failed to create {.path {path}}")
3636
}
3737

3838
if (!is_library(path)) {
39-
warning(path, " does not appear to be a library. ",
40-
"Are sure you specified the correct directory?",
41-
call. = FALSE
42-
)
39+
cli::cli_warn(c(
40+
"{.path {path}} does not appear to be a library.",
41+
"Are sure you specified the correct directory?"
42+
))
4343
}
4444

45-
cli::cli_alert_success("Dev mode: ON")
45+
cli::cli_inform(c(v = "Dev mode: ON"))
4646
options(dev_path = path)
4747

4848
if (is.null(.prompt)) .prompt <<- getOption("prompt")
4949
options(prompt = paste("d> "))
5050

5151
.libPaths(c(path, lib_paths))
5252
} else {
53-
cli::cli_alert_success("Dev mode: OFF")
53+
cli::cli_inform(c(v = "Dev mode: OFF"))
5454
options(dev_path = NULL)
5555

5656
if (!is.null(.prompt)) options(prompt = .prompt)

R/devtools-package.R

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#' @section Package options:
2+
#'
3+
#' Devtools uses the following [options()] to configure behaviour:
4+
#'
5+
#' \itemize{
6+
#' \item `devtools.path`: path to use for [dev_mode()]
7+
#'
8+
#' \item `devtools.name`: your name, used when signing draft
9+
#' emails.
10+
#'
11+
#' \item `devtools.install.args`: a string giving extra arguments passed
12+
#' to `R CMD install` by [install()].
13+
#'
14+
#' \item `devtools.desc.author`: a string providing a default Authors@@R
15+
#' string to be used in new \file{DESCRIPTION}s. Should be a R code, and
16+
#' look like `"Hadley Wickham <h.wickham@@gmail.com> [aut, cre]"`. See
17+
#' [utils::as.person()] for more details.
18+
#'
19+
#' \item `devtools.desc.license`: a default license string to use for
20+
#' new packages.
21+
#'
22+
#' \item `devtools.desc.suggests`: a character vector listing packages to
23+
#' to add to suggests by defaults for new packages.
24+
#
25+
#' \item `devtools.desc`: a named list listing any other
26+
#' extra options to add to \file{DESCRIPTION}
27+
#'
28+
#' }
29+
#' @docType package
30+
#' @keywords internal
31+
"_PACKAGE"
32+
33+
## usethis namespace: start
34+
#' @importFrom lifecycle deprecated
35+
## usethis namespace: end
36+
NULL

R/document.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
document <- function(pkg = ".", roclets = NULL, quiet = FALSE) {
1414
pkg <- as.package(pkg)
1515
if (!isTRUE(quiet)) {
16-
cli::cli_alert_info("Updating {.pkg {pkg$package}} documentation")
16+
cli::cli_inform(c(i = "Updating {.pkg {pkg$package}} documentation"))
1717
}
1818

1919
save_all()

R/lint.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ lint <- function(pkg = ".", cache = TRUE, ...) {
1515
rlang::check_installed("lintr")
1616
pkg <- as.package(pkg)
1717

18-
cli::cli_alert_info("Linting {.pkg {pkg$package}}")
18+
cli::cli_inform(c(i = "Linting {.pkg {pkg$package}}"))
1919

2020
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
2121

0 commit comments

Comments
 (0)