Skip to content

Commit af999e2

Browse files
hadleyjennybc
andauthored
Actually drop superseded usethis functions (#2662)
* Actually drop superseded usethis functions Fixes #2585 * Fix windows variation * Increase width * Tweaks * Namespace these --------- Co-authored-by: Jenny Bryan <jenny.f.bryan@gmail.com>
1 parent f71ed22 commit af999e2

7 files changed

Lines changed: 215 additions & 68 deletions

File tree

NAMESPACE

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,4 @@ importFrom(pkgload,unload)
9797
importFrom(sessioninfo,package_info)
9898
importFrom(sessioninfo,session_info)
9999
importFrom(stats,update)
100-
importFrom(usethis,ui_code)
101-
importFrom(usethis,ui_done)
102-
importFrom(usethis,ui_field)
103-
importFrom(usethis,ui_path)
104-
importFrom(usethis,ui_todo)
105-
importFrom(usethis,ui_value)
106100
importFrom(usethis,use_test)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* `build_vignettes()` and `clean_vignettes()` are now deprecated. We no longer recommend building vignettes in this way; instead use `pkgdown::build_article()` to render articles locally (#2488).
77
* `build_site()` now just calls `pkgdown::build_site()`, meaning that you will get more (informative) output by default (#2578).
88
* New `check_mac_devel()` function to check a package using the macOS builder at https://mac.r-project.org/macbuilder/submit.html (@nfrerebeau, #2507)
9+
* `dev_sitrep()` now uses cli for user-facing messages instead of deprecated usethis UI functions.
910
* `dev_sitrep()` now works correctly in Positron (#2618).
1011
* `is_loading()` is now re-exported from pkgload (#2556).
1112
* Package installation functions are now deprecated: `install_bioc()`, `install_bitbucket()`, `install_cran()`, `install_deps()`, `install_dev()`, `install_dev_deps()`, `install_git()`, `install_github()`, `install_gitlab()`, `install_local()`, `install_svn()`, `install_url()`, `install_version()`, `update_packages()`, `dev_package_deps()`, `github_pull()`, and `github_release()`. We now recommend pak (<https://pak.r-lib.org/>) for general package installation. See `?install-deprecated` for migration guidance.

R/sitrep.R

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ check_for_rstudio_updates <- function(
6666
sprintf(
6767
"%s.\nDownload at: %s",
6868
result[["update-message"]],
69-
ui_field(result[["update-url"]])
69+
result[["update-url"]]
7070
)
7171
)
7272
}
@@ -93,7 +93,6 @@ r_release <- memoise::memoise(.r_release)
9393
#' everything should be ready for package development.
9494
#'
9595
#' @return A named list, with S3 class `dev_sitrep` (for printing purposes).
96-
#' @importFrom usethis ui_code ui_field ui_todo ui_value ui_done ui_path
9796
#' @export
9897
#' @examples
9998
#' \dontrun{
@@ -104,21 +103,52 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) {
104103

105104
has_build_tools <- !is_windows || pkgbuild::has_build_tools(debug = debug)
106105

106+
new_dev_sitrep(
107+
pkg = pkg,
108+
r_version = getRversion(),
109+
r_path = path_real(R.home()),
110+
r_release_version = r_release(),
111+
is_windows = is_windows,
112+
has_build_tools = has_build_tools,
113+
rtools_path = if (has_build_tools) pkgbuild::rtools_path(),
114+
devtools_version = utils::packageVersion("devtools"),
115+
devtools_deps = remotes::package_deps("devtools", dependencies = NA),
116+
pkg_deps = if (!is.null(pkg)) {
117+
remotes::dev_package_deps(pkg$path, dependencies = TRUE)
118+
},
119+
rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(),
120+
rstudio_msg = if (!is_positron()) check_for_rstudio_updates()
121+
)
122+
}
123+
124+
new_dev_sitrep <- function(
125+
pkg = NULL,
126+
r_version = getRversion(),
127+
r_path = path_real(R.home()),
128+
r_release_version = r_version,
129+
is_windows = FALSE,
130+
has_build_tools = TRUE,
131+
rtools_path = NULL,
132+
devtools_version = utils::packageVersion("devtools"),
133+
devtools_deps = data.frame(package = character(), diff = numeric()),
134+
pkg_deps = NULL,
135+
rstudio_version = NULL,
136+
rstudio_msg = NULL
137+
) {
107138
structure(
108139
list(
109140
pkg = pkg,
110-
r_version = getRversion(),
111-
r_path = path_real(R.home()),
112-
r_release_version = r_release(),
141+
r_version = r_version,
142+
r_path = r_path,
143+
r_release_version = r_release_version,
144+
is_windows = is_windows,
113145
has_build_tools = has_build_tools,
114-
rtools_path = if (has_build_tools) pkgbuild::rtools_path(),
115-
devtools_version = utils::packageVersion("devtools"),
116-
devtools_deps = remotes::package_deps("devtools", dependencies = NA),
117-
pkg_deps = if (!is.null(pkg)) {
118-
remotes::dev_package_deps(pkg$path, dependencies = TRUE)
119-
},
120-
rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(),
121-
rstudio_msg = if (!is_positron()) check_for_rstudio_updates()
146+
rtools_path = rtools_path,
147+
devtools_version = devtools_version,
148+
devtools_deps = devtools_deps,
149+
pkg_deps = pkg_deps,
150+
rstudio_version = rstudio_version,
151+
rstudio_msg = rstudio_msg
122152
),
123153
class = "dev_sitrep"
124154
)
@@ -128,80 +158,68 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) {
128158
print.dev_sitrep <- function(x, ...) {
129159
all_ok <- TRUE
130160

131-
hd_line("R")
161+
cli::cli_rule("R")
132162
kv_line("version", x$r_version)
133163
kv_line("path", x$r_path, path = TRUE)
134164
if (x$r_version < x$r_release_version) {
135-
ui_todo(
136-
'
137-
{ui_field("R")} is out of date ({ui_value(x$r_version)} vs {ui_value(x$r_release_version)})
138-
'
139-
)
165+
cli::cli_bullets(c(
166+
"!" = "{.field R} is out of date ({.val {x$r_version}} vs {.val {x$r_release_version}})"
167+
))
140168
all_ok <- FALSE
141169
}
142170

143-
if (is_windows) {
144-
hd_line("Rtools")
171+
if (x$is_windows) {
172+
cli::cli_rule("Rtools")
145173
if (x$has_build_tools) {
146174
kv_line("path", x$rtools_path, path = TRUE)
147175
} else {
148-
ui_todo(
149-
'
150-
{ui_field("RTools")} is not installed:
151-
Download and install it from: {ui_field("https://cloud.r-project.org/bin/windows/Rtools/")}
152-
'
153-
)
176+
cli::cli_bullets(c(
177+
"!" = "{.field Rtools} is not installed.",
178+
" " = "Download and install it from: {.url https://cloud.r-project.org/bin/windows/Rtools/}"
179+
))
154180
}
155181
all_ok <- FALSE
156182
}
157183

158184
if (!is.null(x$rstudio_version)) {
159-
hd_line(if (is_positron()) "Positron" else "RStudio")
185+
cli::cli_rule(if (is_positron()) "Positron" else "RStudio")
160186
kv_line("version", x$rstudio_version)
161187

162188
if (!is.null(x$rstudio_msg)) {
163-
ui_todo(x$rstudio_msg)
189+
cli::cli_bullets(c("!" = "{x$rstudio_msg}"))
164190
all_ok <- FALSE
165191
}
166192
}
167193

168-
hd_line("devtools")
194+
cli::cli_rule("devtools")
169195
kv_line("version", x$devtools_version)
170196

171197
devtools_deps_old <- x$devtools_deps$diff < 0
172198
if (any(devtools_deps_old)) {
173-
ui_todo(
174-
'
175-
{ui_field("devtools")} or its dependencies out of date:
176-
{paste(ui_value(x$devtools_deps$package[devtools_deps_old]), collapse = ", ")}
177-
Update them with {ui_code("devtools::update_packages(\\"devtools\\")")}
178-
'
179-
)
199+
cli::cli_bullets(c(
200+
"!" = "{.pkg devtools} or its dependencies out of date:",
201+
" " = "{.val {x$devtools_deps$package[devtools_deps_old]}}",
202+
" " = "Update them with {.code devtools::update_packages(\"devtools\")}"
203+
))
180204
all_ok <- FALSE
181205
}
182206

183-
hd_line("dev package")
207+
cli::cli_rule("dev package")
184208
kv_line("package", x$pkg$package)
185209
kv_line("path", x$pkg$path, path = TRUE)
186210

187211
pkg_deps_old <- x$pkg_deps$diff < 0
188212
if (any(pkg_deps_old)) {
189-
ui_todo(
190-
'
191-
{ui_field(x$pkg$package)} dependencies out of date:
192-
{paste(ui_value(x$pkg_deps$package[pkg_deps_old]), collapse = ", ")}
193-
Update them with {ui_code("devtools::install_dev_deps()")}
194-
'
195-
)
213+
cli::cli_bullets(c(
214+
"!" = "{.field {x$pkg$package}} dependencies out of date:",
215+
" " = "{.val {x$pkg_deps$package[pkg_deps_old]}}",
216+
" " = "Update them with {.code devtools::install_dev_deps()}"
217+
))
196218
all_ok <- FALSE
197219
}
198220

199221
if (all_ok) {
200-
ui_done(
201-
"
202-
All checks passed
203-
"
204-
)
222+
cli::cli_bullets(c("v" = "All checks passed"))
205223
}
206224

207225
invisible(x)
@@ -210,19 +228,12 @@ print.dev_sitrep <- function(x, ...) {
210228

211229
# Helpers -----------------------------------------------------------------
212230

213-
hd_line <- function(name) {
214-
cli::cat_rule(cli::style_bold(name))
215-
}
216-
217231
kv_line <- function(key, value, path = FALSE) {
218232
if (is.null(value)) {
219-
value <- cli::col_silver("<unset>")
233+
cli::cli_inform(c("*" = "{key}: {.silver <unset>}"))
234+
} else if (path) {
235+
cli::cli_inform(c("*" = "{key}: {.path {value}}"))
220236
} else {
221-
if (path) {
222-
value <- ui_path(value, base = NA)
223-
} else {
224-
value <- ui_value(value)
225-
}
237+
cli::cli_inform(c("*" = "{key}: {.val {value}}"))
226238
}
227-
cli::cat_line(cli::symbol$bullet, " ", key, ": ", value)
228239
}

R/test.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ test <- function(
3131
if (!uses_testthat(pkg)) {
3232
cli::cli_inform(c(i = "No testing infrastructure found."))
3333
if (!interactive()) {
34-
ui_todo('Setup testing with {ui_code("usethis::use_testthat()")}.')
34+
cli::cli_bullets(c(
35+
"!" = 'Setup testing with {.code usethis::use_testthat()}.'
36+
))
3537
return(invisible())
3638
}
3739
if (yesno("Create it?")) {

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ SHA
5353
Studer
5454
Takahashi
5555
Titov
56+
UI
5657
UNC
5758
VignetteBuilder
5859
WARNINGs

tests/testthat/_snaps/sitrep.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,84 @@
1+
# print shows all checks passed
2+
3+
Code
4+
print(x)
5+
Message
6+
-- R -------------------------------------------------------
7+
* version: 4.4.0
8+
* path: '/usr/lib/R'
9+
-- devtools ------------------------------------------------
10+
* version: 2.4.6
11+
-- dev package ---------------------------------------------
12+
* package: <unset>
13+
* path: <unset>
14+
v All checks passed
15+
16+
# print warns when R is out of date
17+
18+
Code
19+
print(x)
20+
Message
21+
-- R -------------------------------------------------------
22+
* version: 4.3.0
23+
* path: '/usr/lib/R'
24+
! R is out of date (4.3.0 vs 4.4.0)
25+
-- devtools ------------------------------------------------
26+
* version: 2.4.6
27+
-- dev package ---------------------------------------------
28+
* package: <unset>
29+
* path: <unset>
30+
31+
# print warns about outdated devtools deps
32+
33+
Code
34+
print(x)
35+
Message
36+
-- R -------------------------------------------------------
37+
* version: 4.4.0
38+
* path: '/usr/lib/R'
39+
-- devtools ------------------------------------------------
40+
* version: 2.4.6
41+
! devtools or its dependencies out of date:
42+
"cli"
43+
Update them with `devtools::update_packages("devtools")`
44+
-- dev package ---------------------------------------------
45+
* package: <unset>
46+
* path: <unset>
47+
48+
# print warns about outdated package deps
49+
50+
Code
51+
print(x)
52+
Message
53+
-- R -------------------------------------------------------
54+
* version: 4.4.0
55+
* path: '/usr/lib/R'
56+
-- devtools ------------------------------------------------
57+
* version: 2.4.6
58+
-- dev package ---------------------------------------------
59+
* package: "mypkg"
60+
* path: '/tmp/mypkg'
61+
! mypkg dependencies out of date:
62+
"dplyr" and "tidyr"
63+
Update them with `devtools::install_dev_deps()`
64+
65+
# print shows RStudio update message
66+
67+
Code
68+
print(x)
69+
Message
70+
-- R -------------------------------------------------------
71+
* version: 4.4.0
72+
* path: '/usr/lib/R'
73+
-- RStudio -------------------------------------------------
74+
* version: "2024.04.0"
75+
! RStudio is out of date.
76+
-- devtools ------------------------------------------------
77+
* version: 2.4.6
78+
-- dev package ---------------------------------------------
79+
* package: <unset>
80+
* path: <unset>
81+
182
# check_for_rstudio_updates
283

384
Code

tests/testthat/test-sitrep.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
1+
test_that("print shows all checks passed", {
2+
local_reproducible_output(width = 60)
3+
x <- new_dev_sitrep(
4+
r_version = R_system_version("4.4.0"),
5+
r_path = "/usr/lib/R",
6+
devtools_version = package_version("2.4.6")
7+
)
8+
expect_snapshot(print(x))
9+
})
10+
11+
test_that("print warns when R is out of date", {
12+
local_reproducible_output(width = 60)
13+
x <- new_dev_sitrep(
14+
r_version = R_system_version("4.3.0"),
15+
r_path = "/usr/lib/R",
16+
r_release_version = R_system_version("4.4.0"),
17+
devtools_version = package_version("2.4.6")
18+
)
19+
expect_snapshot(print(x))
20+
})
21+
22+
test_that("print warns about outdated devtools deps", {
23+
local_reproducible_output(width = 60)
24+
x <- new_dev_sitrep(
25+
r_version = R_system_version("4.4.0"),
26+
r_path = "/usr/lib/R",
27+
devtools_version = package_version("2.4.6"),
28+
devtools_deps = data.frame(package = c("rlang", "cli"), diff = c(0, -1))
29+
)
30+
expect_snapshot(print(x))
31+
})
32+
33+
test_that("print warns about outdated package deps", {
34+
local_reproducible_output(width = 60)
35+
x <- new_dev_sitrep(
36+
r_version = R_system_version("4.4.0"),
37+
r_path = "/usr/lib/R",
38+
devtools_version = package_version("2.4.6"),
39+
pkg = list(package = "mypkg", path = "/tmp/mypkg"),
40+
pkg_deps = data.frame(package = c("dplyr", "tidyr"), diff = c(-1, -1))
41+
)
42+
expect_snapshot(print(x))
43+
})
44+
45+
test_that("print shows RStudio update message", {
46+
local_reproducible_output(width = 60)
47+
withr::local_envvar(POSITRON = "")
48+
x <- new_dev_sitrep(
49+
r_version = R_system_version("4.4.0"),
50+
r_path = "/usr/lib/R",
51+
devtools_version = package_version("2.4.6"),
52+
rstudio_version = "2024.04.0",
53+
rstudio_msg = "RStudio is out of date."
54+
)
55+
expect_snapshot(print(x))
56+
})
57+
158
test_that("check_for_rstudio_updates", {
259
skip_if_offline()
360
skip_on_cran()

0 commit comments

Comments
 (0)