diff --git a/R/roxygen2.R b/R/roxygen2.R index f08818e0a..4f15c8b56 100644 --- a/R/roxygen2.R +++ b/R/roxygen2.R @@ -58,7 +58,21 @@ extract_diff_root <- function(root = here::here()) { #' @export diff_requires_run_roxygenize <- function(root = here::here()) { if (rlang::with_handlers(withr::with_namespace("git2r", FALSE), error = function(...) TRUE)) { - rlang::warn("You need to install the R package git2r (and the required system dependency if you are on Linux) to benefit from caching of this hook.") + generic <- paste0( + " Please add the package as a dependency to ", + "`.pre-commit-config.yaml` -> `id: roxygenize` -> ", + "`additional_dependencies` and try again. The package must be ", + "specified so `renv::install()` understands it, e.g. like this:\n\n", + " - id: roxygenize", + " + additional_dependencies: + - r-lib/git2r\n\n" + ) + msg <- paste0( + "The R package {git2r} must be available to benefit from caching of this hook.", + generic + ) + rlang::warn(msg) return(TRUE) } changed_lines_content <- extract_diff_root(root) @@ -89,7 +103,7 @@ roxygen_assert_additional_dependencies <- function() { e } ) - if (inherits(out, "packageNotFoundError")) { + if (inherits(out, "packageNotFoundError") || ("message" %in% names(out) && grepl("Dependency package(\\(s\\))? .* not available", out$message))) { # case used in package but not installed rlang::abort(paste0( "The roxygenize hook requires all* dependencies of your package to be listed in ", @@ -143,8 +157,7 @@ roxygenize_with_cache <- function(key, dirs) { " - id: roxygenize", " additional_dependencies: - - r-lib/pkgapi - - dplyr@1.0.0\n\n" + - r-lib/pkgapi\n\n" )) } else if (inherits(out, "error")) { rlang::abort(conditionMessage(out)) diff --git a/R/setup.R b/R/setup.R index e24bf31c4..ca55bc3cb 100644 --- a/R/setup.R +++ b/R/setup.R @@ -113,12 +113,7 @@ snippet_generate <- function(snippet = "", root = here::here()) { ) deps <- desc::desc_get_deps() deps <- deps[order(deps$package), ] - paste0( - " - ", deps$package, "@", - purrr::map_chr(deps$package, ~ as.character(packageVersion(.x))), "\n", - collapse = "" - ) %>% - sort() %>% + snippet_generate_impl_additional_deps_roxygenize(deps$package) %>% cat(sep = "") remote_deps <- rlang::with_handlers( desc::desc_get_field("Remotes"), @@ -144,3 +139,12 @@ You need in your `.pre-commit-config.yaml` } } } + +snippet_generate_impl_additional_deps_roxygenize <- function(packages) { + paste0( + " - ", packages, "@", + purrr::map_chr(packages, ~ as.character(packageVersion(.x))), "\n", + collapse = "" + ) %>% + sort() +} diff --git a/inst/WORDLIST b/inst/WORDLIST index 308117c14..b4ee61336 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -4,7 +4,9 @@ CMD Ctrl EOF Ei +Eic Homebrew +KernSmooth Lifecycle MERCHANTABILITY RData @@ -25,10 +27,12 @@ SHA Sublicensing Sys Uninstallation +Unstaged Upvote VignetteBuilder WIPO Walthert +Za ae api appveyor @@ -36,13 +40,18 @@ arg args artific autoupdate +bd beaefa behaviour bliblablupp +cfe ci cli cmd codemeta +codemetar +codetools +commandArgs comparator conda conditionMessage @@ -73,10 +82,13 @@ fs fsf fsssile getOption +getParseData getwd gh github gitignore +grDevices +grepl gsub href http @@ -87,10 +99,12 @@ impl init io isAvailable +isTRUE jpeg json knitr lang +lapply lgpl licensors lintr @@ -102,6 +116,7 @@ macOS magrittr maxkb md +mgcv miniconda mis modef @@ -109,9 +124,12 @@ msg mtime navbar netlify +nlme +nnet noncommercially nrow nt +num oneliner os overscope @@ -150,23 +168,32 @@ ropenscilabs roxygen roxygenise roxygenize +rpart rprojroot rstudio rstudioapi saveCache seealso +sep +setdiff stderr stdout sterr stopifnot styler sublicenses +tcltk +tempfile testthat tibble tidyverse +trailingOnly travis tryCatch ubuntu +uninitialised +unlist +unname usethis usr walthert diff --git a/inst/hooks/exported/readme-rmd-rendered b/inst/hooks/exported/readme-rmd-rendered deleted file mode 100755 index 359417c08..000000000 --- a/inst/hooks/exported/readme-rmd-rendered +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# adapted from https://github.com/r-lib/usethis/blob/master/inst/templates/readme-rmd-pre-commit.sh -# No rmd readme means nothing to check -if [[ ! -f "README.Rmd" ]] -then - exit 0 -fi - -if [[ README.Rmd -nt README.md ]] -then - echo >&2 "README.md is out of date; please re-knit README.Rmd." - exit 1 -fi - -num_readmes=$(git diff --cached --name-only | grep -Eic '^README\.[R]?md$') - -if [[ "$num_readmes" -lt 2 ]] -then - echo >&2 "README.Rmd and README.md should be both staged." - exit 1 -fi diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index 96cf941b0..f1255150c 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -53,7 +53,7 @@ test_that("CLI API works for roxygenize", { suffix = "-cache-success.R", env = paste0("R_CACHE_ROOTPATH=", R.cache_root), msg = "You can silent this", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf")), file_transformer = function(x) { git2r::init() x diff --git a/tests/testthat/test-conda.R b/tests/testthat/test-conda.R index 364c5c522..15cf79528 100644 --- a/tests/testthat/test-conda.R +++ b/tests/testthat/test-conda.R @@ -6,29 +6,29 @@ if (!on_cran()) { }) test_that("can use pre-commit", { - tempdir <- local_test_setup(quiet = FALSE) + tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE) expect_message( - use_precommit(open = FALSE, force = TRUE, root = tempdir), + use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir), "to get the latest" ) expect_message( - use_precommit(open = FALSE, force = FALSE, root = tempdir), + use_precommit(open = FALSE, force = FALSE, install_hooks = FALSE, root = tempdir), "There is already " ) }) test_that("fails early if repo is not a git repo ", { - tempdir <- local_test_setup(git = FALSE, quiet = FALSE) + tempdir <- local_test_setup(git = FALSE, quiet = FALSE, install_hooks = FALSE) expect_error( - use_precommit(open = FALSE, root = tempdir), + use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir), "is not a git repo" ) }) test_that("can use custom config file ", { - tempdir1 <- local_test_setup() - tempdir2 <- local_test_setup() + tempdir1 <- local_test_setup(install_hooks = FALSE) + tempdir2 <- local_test_setup(install_hooks = FALSE) path_custom <- fs::path(tempdir2, "some-precommit.yaml") new_text <- "# 4js93" @@ -36,7 +36,7 @@ if (!on_cran()) { c(new_text) %>% writeLines(path_custom) git2r::init(tempdir1) - use_precommit(config_source = path_custom, open = FALSE, force = TRUE, root = tempdir1) + use_precommit(config_source = path_custom, open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir1) config <- readLines(fs::path(tempdir1, ".pre-commit-config.yaml")) expect_equal( config[length(config)], @@ -45,7 +45,7 @@ if (!on_cran()) { }) test_that("existing hooks are recognized", { - tempdir <- local_test_setup(quiet = FALSE) + tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE) withr::with_dir(tempdir, { git2r::init() usethis::proj_set(".") @@ -53,25 +53,25 @@ if (!on_cran()) { # usethis hook is removed without error expect_message( - use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."), + use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."), "Removed the render-README hook," ) writeLines(letters, ".git/hooks/pre-commit") expect_error( - use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."), + use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."), "existing hooks installed" ) # tolerate other hook scripts in migration mode expect_message( - use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, root = "."), + use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."), "Running in migration" ) # can also remove other hooks writeLines(letters, ".git/hooks/pre-commit") expect_message( - use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, root = "."), + use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."), "Sucessfully installed" ) }) @@ -80,7 +80,7 @@ if (!on_cran()) { test_that("Can uninstall pre-commit (repo scope)", { # with all files there - tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE) + tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE) expect_message( uninstall_precommit(scope = "repo", root = tempdir), "Uninstalled pre-commit from repo scope.*" @@ -94,7 +94,7 @@ if (!on_cran()) { ) # when there is no pre-commit.yaml anymore - suppressMessages(use_precommit(open = FALSE, force = TRUE, root = tempdir)) + suppressMessages(use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir)) fs::file_delete(fs::path(tempdir, ".pre-commit-config.yaml")) expect_message( uninstall_precommit(scope = "repo", root = tempdir), @@ -104,13 +104,13 @@ if (!on_cran()) { test_that("Can uninstall (userly)", { if (not_conda()) { - tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE) + tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE) expect_error( uninstall_precommit(scope = "user", ask = "none", root = tempdir), "installed with conda" ) } else { - tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE) + tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE) expect_message( uninstall_precommit(scope = "user", ask = "none", root = tempdir), "Removed pre-commit from" @@ -124,18 +124,18 @@ if (!on_cran()) { test_that("use_precommit fails when no user installation is found", { skip_if(not_conda()) - expect_error(use_precommit(open = FALSE, root = tempdir), "installed on your system") + expect_error(use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir), "installed on your system") }) test_that("can install pre-commit with remote config", { if (!not_conda()) { expect_error(install_precommit(), NA) } - tempdir <- local_test_setup(quiet = FALSE) + tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE) expect_message( use_precommit( example_remote_config(), - open = FALSE, force = TRUE, root = tempdir + open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir ), "to get the latest" ) @@ -145,14 +145,14 @@ if (!on_cran()) { if (!not_conda()) { expect_message(install_precommit(), "already installed") } - tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE) + tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE) withr::with_dir( tempdir, { withr::defer(call_and_capture("git", "config --unset-all core.hooksPath")) call_and_capture("git", "config core.hooksPath .githooks") expect_error( - use_precommit(open = FALSE, force = TRUE, root = tempdir), + use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir), "stdout: [ERROR] Cowardly refusing to install hooks with `core.hooksPath` set.", fixed = TRUE ) diff --git a/tests/testthat/test-hook-roxygenize.R b/tests/testthat/test-hook-roxygenize.R index 954f75e68..1546803f8 100644 --- a/tests/testthat/test-hook-roxygenize.R +++ b/tests/testthat/test-hook-roxygenize.R @@ -138,7 +138,9 @@ test_that("fails gratefully when not installed package is required according to ) mockery::stub(roxygenize_with_cache, "diff_requires_run_roxygenize", TRUE) expect_error( - roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize")), + suppressWarnings( + roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize")) + ), "Please add the package" ) }) diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index 3b0b34309..ecc0dd09f 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -270,8 +270,14 @@ run_test("readme-rmd-rendered", error_msg = NULL, msg = NULL, file_transformer = function(files) { - git2r::init() - git2r::add(path = files) + if (length(files) > 1) { + # transformer is called once on all files and once per file + content_2 <- readLines(files[2]) + Sys.sleep(2) + writeLines(content_2, files[2]) + git2r::init() + git2r::add(path = files) + } files } ) @@ -287,9 +293,9 @@ run_test("readme-rmd-rendered", content_2 <- readLines(files[2]) Sys.sleep(2) writeLines(content_2, files[2]) + git2r::init() + git2r::add(path = files) } - git2r::init() - git2r::add(path = files) files } ) @@ -302,8 +308,14 @@ run_test("readme-rmd-rendered", error_msg = "should be both staged", msg = NULL, file_transformer = function(files) { - git2r::init() - git2r::add(path = files[1]) + if (length(files) > 1) { + # transformer is called once on all files and once per file + content_2 <- readLines(files[2]) + Sys.sleep(2) + writeLines(content_2, files[2]) + git2r::init() + git2r::add(path = files[1]) + } files } ) diff --git a/tests/testthat/test-setup.R b/tests/testthat/test-setup.R index b6f0bbdd9..d832d870c 100644 --- a/tests/testthat/test-setup.R +++ b/tests/testthat/test-setup.R @@ -1,5 +1,5 @@ test_that("snippet generation works", { - local_test_setup(git = FALSE, use_precommit = FALSE, package = TRUE) + local_test_setup(git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE) usethis::use_package("styler") expect_warning( out <- capture_output(snippet_generate("additional-deps-roxygenize")), diff --git a/tic.R b/tic.R deleted file mode 100644 index 45298211f..000000000 --- a/tic.R +++ /dev/null @@ -1,8 +0,0 @@ -Sys.setenv(LINTR_COMMENT_BOT = "false") -do_package_checks( - error_on = ifelse(tic::ci_has_env("EXTERNAL_INSTALLATION"), "warning", "note") -) - -if (ci_has_env("BUILD_PKGDOWN")) { - do_pkgdown() -}