Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ importFrom(remotes,update_packages)
importFrom(sessioninfo,package_info)
importFrom(sessioninfo,session_info)
importFrom(stats,update)
importFrom(usethis,ui_code)
importFrom(usethis,ui_done)
importFrom(usethis,ui_field)
importFrom(usethis,ui_path)
importFrom(usethis,ui_todo)
importFrom(usethis,ui_value)
importFrom(usethis,use_test)
importFrom(utils,available.packages)
importFrom(utils,contrib.url)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* `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).
* `build_site()` now just calls `pkgdown::build_site()`, meaning that you will get more (informative) output by default (#2578).
* New `check_mac_devel()` function to check a package using the macOS builder at https://mac.r-project.org/macbuilder/submit.html (@nfrerebeau, #2507)
* `dev_sitrep()` now uses cli for user-facing messages instead of deprecated usethis UI functions.
* `dev_sitrep()` now works correctly in Positron (#2618).
* `is_loading()` is now re-exported from pkgload (#2556).
* `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617).
Expand Down
128 changes: 68 additions & 60 deletions R/sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ check_for_rstudio_updates <- function(
sprintf(
"%s.\nDownload at: %s",
result[["update-message"]],
ui_field(result[["update-url"]])
result[["update-url"]]
)
)
}
Expand All @@ -93,7 +93,6 @@ r_release <- memoise::memoise(.r_release)
#' everything should be ready for package development.
#'
#' @return A named list, with S3 class `dev_sitrep` (for printing purposes).
#' @importFrom usethis ui_code ui_field ui_todo ui_value ui_done ui_path
#' @export
#' @examples
#' \dontrun{
Expand All @@ -104,21 +103,49 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) {

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

new_dev_sitrep(
Copy link
Member Author

Choose a reason for hiding this comment

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

Minimal surgery to make this testable since I didn't want to accidentally break it all.

pkg = pkg,
r_version = getRversion(),
r_path = path_real(R.home()),
r_release_version = r_release(),
has_build_tools = has_build_tools,
rtools_path = if (has_build_tools) pkgbuild::rtools_path(),
devtools_version = packageVersion("devtools"),
devtools_deps = remotes::package_deps("devtools", dependencies = NA),
pkg_deps = if (!is.null(pkg)) {
remotes::dev_package_deps(pkg$path, dependencies = TRUE)
},
rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(),
rstudio_msg = if (!is_positron()) check_for_rstudio_updates()
)
}

new_dev_sitrep <- function(
pkg = NULL,
r_version = getRversion(),
r_path = path_real(R.home()),
r_release_version = r_version,
has_build_tools = TRUE,
rtools_path = NULL,
devtools_version = packageVersion("devtools"),
devtools_deps = data.frame(package = character(), diff = numeric()),
pkg_deps = NULL,
rstudio_version = NULL,
rstudio_msg = NULL
) {
structure(
list(
pkg = pkg,
r_version = getRversion(),
r_path = path_real(R.home()),
r_release_version = r_release(),
r_version = r_version,
r_path = r_path,
r_release_version = r_release_version,
has_build_tools = has_build_tools,
rtools_path = if (has_build_tools) pkgbuild::rtools_path(),
devtools_version = packageVersion("devtools"),
devtools_deps = remotes::package_deps("devtools", dependencies = NA),
pkg_deps = if (!is.null(pkg)) {
remotes::dev_package_deps(pkg$path, dependencies = TRUE)
},
rstudio_version = if (is_rstudio_running()) rstudioapi::getVersion(),
rstudio_msg = if (!is_positron()) check_for_rstudio_updates()
rtools_path = rtools_path,
devtools_version = devtools_version,
devtools_deps = devtools_deps,
pkg_deps = pkg_deps,
rstudio_version = rstudio_version,
rstudio_msg = rstudio_msg
),
class = "dev_sitrep"
)
Expand All @@ -128,80 +155,68 @@ dev_sitrep <- function(pkg = ".", debug = FALSE) {
print.dev_sitrep <- function(x, ...) {
all_ok <- TRUE

hd_line("R")
cli::cli_rule("R")
kv_line("version", x$r_version)
kv_line("path", x$r_path, path = TRUE)
if (x$r_version < x$r_release_version) {
ui_todo(
'
{ui_field("R")} is out of date ({ui_value(x$r_version)} vs {ui_value(x$r_release_version)})
'
)
cli::cli_bullets(c(
"!" = "{.field R} is out of date ({.val {x$r_version}} vs {.val {x$r_release_version}})"
))
all_ok <- FALSE
}

if (is_windows) {
hd_line("Rtools")
cli::cli_rule("Rtools")
if (x$has_build_tools) {
kv_line("path", x$rtools_path, path = TRUE)
} else {
ui_todo(
'
{ui_field("RTools")} is not installed:
Download and install it from: {ui_field("https://cloud.r-project.org/bin/windows/Rtools/")}
'
)
cli::cli_bullets(c(
"!" = "{.field RTools} is not installed.",
" " = "Download and install it from: {.url https://cloud.r-project.org/bin/windows/Rtools/}"
))
}
all_ok <- FALSE
}

if (!is.null(x$rstudio_version)) {
hd_line(if (is_positron()) "Positron" else "RStudio")
cli::cli_rule(if (is_positron()) "Positron" else "RStudio")
kv_line("version", x$rstudio_version)

if (!is.null(x$rstudio_msg)) {
ui_todo(x$rstudio_msg)
cli::cli_bullets(c("!" = "{x$rstudio_msg}"))
all_ok <- FALSE
}
}

hd_line("devtools")
cli::cli_rule("devtools")
kv_line("version", x$devtools_version)

devtools_deps_old <- x$devtools_deps$diff < 0
if (any(devtools_deps_old)) {
ui_todo(
'
{ui_field("devtools")} or its dependencies out of date:
{paste(ui_value(x$devtools_deps$package[devtools_deps_old]), collapse = ", ")}
Update them with {ui_code("devtools::update_packages(\\"devtools\\")")}
'
)
cli::cli_bullets(c(
"!" = "{.field devtools} or its dependencies out of date:",
" " = "{.val {x$devtools_deps$package[devtools_deps_old]}}",
" " = "Update them with {.code devtools::update_packages(\"devtools\")}"
))
all_ok <- FALSE
}

hd_line("dev package")
cli::cli_rule("dev package")
kv_line("package", x$pkg$package)
kv_line("path", x$pkg$path, path = TRUE)

pkg_deps_old <- x$pkg_deps$diff < 0
if (any(pkg_deps_old)) {
ui_todo(
'
{ui_field(x$pkg$package)} dependencies out of date:
{paste(ui_value(x$pkg_deps$package[pkg_deps_old]), collapse = ", ")}
Update them with {ui_code("devtools::install_dev_deps()")}
'
)
cli::cli_bullets(c(
"!" = "{.field {x$pkg$package}} dependencies out of date:",
" " = "{.val {x$pkg_deps$package[pkg_deps_old]}}",
" " = "Update them with {.code devtools::install_dev_deps()}"
))
all_ok <- FALSE
}

if (all_ok) {
ui_done(
"
All checks passed
"
)
cli::cli_bullets(c("v" = "All checks passed"))
}

invisible(x)
Expand All @@ -210,19 +225,12 @@ print.dev_sitrep <- function(x, ...) {

# Helpers -----------------------------------------------------------------

hd_line <- function(name) {
cat_rule(cli::style_bold(name))
}

kv_line <- function(key, value, path = FALSE) {
if (is.null(value)) {
value <- cli::col_silver("<unset>")
cli::cli_inform(c("*" = "{key}: {.silver <unset>}"))
Copy link
Member Author

Choose a reason for hiding this comment

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

Also changed this to ensure that all of the output is now "message", not "output".

} else if (path) {
cli::cli_inform(c("*" = "{key}: {.path {value}}"))
} else {
if (path) {
value <- ui_path(value, base = NA)
} else {
value <- ui_value(value)
}
cli::cli_inform(c("*" = "{key}: {.val {value}}"))
}
cli::cat_line(cli::symbol$bullet, " ", key, ": ", value)
}
4 changes: 3 additions & 1 deletion R/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ test <- function(
if (!uses_testthat(pkg)) {
cli::cli_inform(c(i = "No testing infrastructure found."))
if (!interactive()) {
ui_todo('Setup testing with {ui_code("usethis::use_testthat()")}.')
cli::cli_bullets(c(
"!" = 'Setup testing with {.code usethis::use_testthat()}.'
))
return(invisible())
}
if (yesno("Create it?")) {
Expand Down
84 changes: 84 additions & 0 deletions tests/testthat/_snaps/sitrep.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
# print shows all checks passed

Code
print(x)
Message
-- R -----------------------------------
* version: 4.4.0
* path: '/usr/lib/R'
-- devtools ----------------------------
* version: 2.4.6
-- dev package -------------------------
* package: <unset>
* path: <unset>
v All checks passed

# print warns when R is out of date

Code
print(x)
Message
-- R -----------------------------------
* version: 4.3.0
* path: '/usr/lib/R'
! R is out of date (4.3.0 vs 4.4.0)
-- devtools ----------------------------
* version: 2.4.6
-- dev package -------------------------
* package: <unset>
* path: <unset>

# print warns about outdated devtools deps

Code
print(x)
Message
-- R -----------------------------------
* version: 4.4.0
* path: '/usr/lib/R'
-- devtools ----------------------------
* version: 2.4.6
! devtools or its dependencies out of
date:
"cli"
Update them with
`devtools::update_packages("devtools")`
-- dev package -------------------------
* package: <unset>
* path: <unset>

# print warns about outdated package deps

Code
print(x)
Message
-- R -----------------------------------
* version: 4.4.0
* path: '/usr/lib/R'
-- devtools ----------------------------
* version: 2.4.6
-- dev package -------------------------
* package: "mypkg"
* path: '/tmp/mypkg'
! mypkg dependencies out of date:
"dplyr" and "tidyr"
Update them with
`devtools::install_dev_deps()`

# print shows RStudio update message

Code
print(x)
Message
-- R -----------------------------------
* version: 4.4.0
* path: '/usr/lib/R'
-- RStudio -----------------------------
* version: "2024.04.0"
! RStudio is out of date.
-- devtools ----------------------------
* version: 2.4.6
-- dev package -------------------------
* package: <unset>
* path: <unset>

# check_for_rstudio_updates

Code
Expand Down
57 changes: 57 additions & 0 deletions tests/testthat/test-sitrep.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
test_that("print shows all checks passed", {
local_reproducible_output(width = 40)
x <- new_dev_sitrep(
r_version = R_system_version("4.4.0"),
r_path = "/usr/lib/R",
devtools_version = package_version("2.4.6")
)
expect_snapshot(print(x))
})

test_that("print warns when R is out of date", {
local_reproducible_output(width = 40)
x <- new_dev_sitrep(
r_version = R_system_version("4.3.0"),
r_path = "/usr/lib/R",
r_release_version = R_system_version("4.4.0"),
devtools_version = package_version("2.4.6")
)
expect_snapshot(print(x))
})

test_that("print warns about outdated devtools deps", {
local_reproducible_output(width = 40)
x <- new_dev_sitrep(
r_version = R_system_version("4.4.0"),
r_path = "/usr/lib/R",
devtools_version = package_version("2.4.6"),
devtools_deps = data.frame(package = c("rlang", "cli"), diff = c(0, -1))
)
expect_snapshot(print(x))
})

test_that("print warns about outdated package deps", {
local_reproducible_output(width = 40)
x <- new_dev_sitrep(
r_version = R_system_version("4.4.0"),
r_path = "/usr/lib/R",
devtools_version = package_version("2.4.6"),
pkg = list(package = "mypkg", path = "/tmp/mypkg"),
pkg_deps = data.frame(package = c("dplyr", "tidyr"), diff = c(-1, -1))
)
expect_snapshot(print(x))
})

test_that("print shows RStudio update message", {
local_reproducible_output(width = 40)
withr::local_envvar(POSITRON = "")
x <- new_dev_sitrep(
r_version = R_system_version("4.4.0"),
r_path = "/usr/lib/R",
devtools_version = package_version("2.4.6"),
rstudio_version = "2024.04.0",
rstudio_msg = "RStudio is out of date."
)
expect_snapshot(print(x))
})

test_that("check_for_rstudio_updates", {
skip_if_offline()
skip_on_cran()
Expand Down
Loading