Skip to content

Commit

Permalink
Add pkg_sitrep() to diagnose common dev setup issues
Browse files Browse the repository at this point in the history
Fixes #1970
  • Loading branch information
jimhester committed Sep 4, 2019
1 parent c52ea0a commit f0a72c8
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 82 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports:
digest,
DT,
ellipsis,
glue,
git2r (>= 0.23.0),
httr (>= 0.4),
jsonlite,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ S3method(format,check_results)
S3method(print,check_results)
S3method(print,doctor)
S3method(print,maintainers)
S3method(print,pkg_sitrep)
export(as.package)
export(bash)
export(build)
Expand Down Expand Up @@ -59,6 +60,7 @@ export(missing_s3)
export(package_file)
export(package_info)
export(parse_deps)
export(pkg_sitrep)
export(r_env_vars)
export(release)
export(release_checks)
Expand Down Expand Up @@ -116,6 +118,10 @@ importFrom(sessioninfo,package_info)
importFrom(sessioninfo,session_info)
importFrom(stats,update)
importFrom(usethis,create_package)
importFrom(usethis,ui_code)
importFrom(usethis,ui_field)
importFrom(usethis,ui_todo)
importFrom(usethis,ui_value)
importFrom(usethis,use_test)
importFrom(utils,available.packages)
importFrom(utils,contrib.url)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# devtools (development version)

* New `pkg_sitrep()` function to return information about your development
environment and diagnose common problems. The former functions
`dr_devtools()` and `dr_github()` have been deprecated. (#1970)

* All `install_*()` functions now attach build tools to the PATH, which makes them work on
Windows when RTools is not on the default PATH (#2093).

Expand Down
113 changes: 80 additions & 33 deletions R/doctor.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]), ver
}

nms <- vcapply(result, `[[`, 1)
values <- vcapply(result, function(x) URLdecode(x[[2]]))
values <- vcapply(result, function(x) utils::URLdecode(x[[2]]))

result <- stats::setNames(values, nms)

if (!nzchar(result[["update-version"]])) {
return()
}

sprintf("* RStudio is out of date, %s. Download at: %s", result[["update-message"]], result[["update-url"]])
return(glue::glue('
{result[["update-message"]]}.
Download at: {ui_field(result[["update-url"]])}
')
)
}

.r_release <- function() {
Expand All @@ -43,53 +47,96 @@ check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]), ver

r_release <- memoise::memoise(.r_release)


#' Diagnose potential devtools issues
#' Report package development situation
#'
#' @template devtools
#' @inheritParams pkgbuild::has_build_tools
#' @description `pkg_sitrep()` reports
#' * If R is up to date
#' * If RStudio is up to date
#' * If compiler build tools are installed and available for use
#' * If devtools and its dependencies are up to date
#' * If the package's dependencies are up to date
#'
#' This checks to make sure you're using the latest release of R,
#' the released version of RStudio (if you're using it as your gui),
#' and the latest version of devtools and its dependencies.
#' @description Call this function if things seem weird and you're not sure
#' what's wrong or how to fix it. If this function returns no output
#' everything should be ready for package development.
#'
#' @family doctors
#' @return A named list, with S3 class `pkg_sitrep` (for printing purposes).
#' @importFrom usethis ui_code ui_field ui_todo ui_value
#' @export
#' @examples
#' \dontrun{
#' dr_devtools()
#' pkg_sitrep()
#' }
dr_devtools <- function() {
msg <- character()
pkg_sitrep <- function(pkg = ".", debug = FALSE) {
pkg <- as.package(pkg)

if (getRversion() < r_release()) {
msg[["R"]] <- paste0(
"* R is out of date (", getRversion(), " vs ", r_release(), ")"
)
structure(
list(
pkg = pkg,
r_version = getRversion(),
r_release_version = r_release(),
has_build_tools = !is_windows || pkgbuild::has_build_tools(debug = debug),
devtools_deps = remotes::package_deps("devtools", dependencies = NA),
pkg_deps = remotes::dev_package_deps(pkg$path, dependencies = TRUE),
rstudio_msg = check_for_rstudio_updates()
),
class = "pkg_sitrep"
)
}

#' @export
print.pkg_sitrep <- function(x, ...) {
if (x$r_version < x$r_release_version) {
ui_todo('
{ui_field("R")} is out of date ({ui_value(getRversion())} vs {ui_value(r_release())})
')
}

deps <- remotes::package_deps("devtools", dependencies = NA)
old <- deps$diff < 0
if (any(old)) {
msg[["devtools"]] <- paste0(
"* Devtools or dependencies out of date: \n",
paste(deps$package[old], collapse = ", ")
)
if (!is.null(x$rstudio_msg)) {
ui_todo(x$rstudio_msg)
}

msg[["rstudio"]] <- check_for_rstudio_updates("mac", "1.0.0", TRUE)
if (!x$has_build_tools) {
ui_todo('
{ui_field("RTools")} is not installed:
Download and install it from: {ui_field("https://cloud.r-project.org/bin/windows/Rtools/")}
')
}

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\\")")}
')
}

doctor("devtools", msg)
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()")}
')
}

invisible(x)
}

#' Diagnose potential GitHub issues
#'
#' @param path Path to repository to check. Defaults to current working
#' directory
#' @family doctors
#' @export
#' @examples
#' \donttest{
#' dr_github()
#' }
#' @rdname devtools-deprecated
dr_devtools <- function() {
.Deprecated("pkg_sitrep()", package = "devtools")
pkg_sitrep()
}

#' @export
#' @rdname devtools-deprecated
dr_github <- function(path = ".") {
.Deprecated(package = "devtools")
if (!uses_git(path)) {
return(doctor("github", "Path is not a git repository"))
}
Expand Down
2 changes: 1 addition & 1 deletion R/remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ update_packages <- with_pkgbuild_build_tools(with_ellipsis(remotes::update_packa
#' @importFrom remotes dev_package_deps
#' @rdname remote-reexports
#' @export
dev_package_deps <- with_pkgbuild_build_tools(with_ellipsis(remotes::dev_package_deps))
dev_package_deps <- with_pkgbuild_build_tools(remotes::dev_package_deps)
11 changes: 9 additions & 2 deletions man/devtools-deprecated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions man/dr_devtools.Rd

This file was deleted.

24 changes: 0 additions & 24 deletions man/dr_github.Rd

This file was deleted.

37 changes: 37 additions & 0 deletions man/pkg_sitrep.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0a72c8

Please sign in to comment.