diff --git a/.github/workflows/hook-dependencies-upate.yml b/.github/workflows/hook-dependencies-upate.yml index 26226c6de..6bc85b172 100644 --- a/.github/workflows/hook-dependencies-upate.yml +++ b/.github/workflows/hook-dependencies-upate.yml @@ -53,7 +53,7 @@ jobs: "httr" # lintr -> httr -> curl -> libcurl, but seems to give no erorr on # loading lintr, plus https://github.com/jimhester/lintr/issues/861 ) - out <- c(out, "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "git2r", "digest", "desc") + out <- c(out, "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "git2r", "desc") out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont) out <- names(renv:::renv_package_dependencies(out)) return(out) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a2ff7f56..801be0ad6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,6 @@ repos: - id: roxygenize additional_dependencies: - desc@1.3.0 - - digest@0.6.27 - docopt@0.7.1 - fs@1.5.0 - git2r@0.28.0 diff --git a/DESCRIPTION b/DESCRIPTION index f340a3074..a3342e407 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,22 +12,21 @@ License: GPL-3 URL: https://lorenzwalthert.github.io/precommit/, https://github.com/lorenzwalthert/precommit Imports: - R.cache, cli, - docopt (>= 0.7.1), fs, here, magrittr, purrr, + R.cache, rlang, rprojroot, rstudioapi, - tibble, withr, yaml Suggests: desc, digest, + docopt (>= 0.7.1), git2r, glue, knitr, @@ -40,6 +39,7 @@ Suggests: spelling, styler, testthat (>= 2.1.0), + tibble, usethis (>= 2.0.0) VignetteBuilder: knitr @@ -49,3 +49,4 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate", warning("Please install r-lib/pkgapi to make sure the file API is kept up to date"); NULL} ) ) RoxygenNote: 7.1.2 +SystemRequirements: git diff --git a/R/precommit-package.R b/R/precommit-package.R index a78198163..2730318ad 100644 --- a/R/precommit-package.R +++ b/R/precommit-package.R @@ -21,3 +21,9 @@ if (getRversion() >= "2.15.1") { NULL )) } + +if (FALSE) { + # {here} is only used as a dependency for default arguments. + # this is to avoid a false positive CRAN note. + here::here +} diff --git a/R/testing.R b/R/testing.R index de1493bf0..6684077f5 100644 --- a/R/testing.R +++ b/R/testing.R @@ -141,7 +141,7 @@ hook_state_create <- function(tempdir, files <- fs::path_rel(path_candidate_temp, tempdir) # https://stat.ethz.ch/pipermail/r-devel/2018-February/075507.html system2(paste0(Sys.getenv("R_HOME"), "/bin/Rscript"), - args = c(path_executable, cmd_args, files), + args = as.character(c(path_executable, cmd_args, files)), stderr = path_stderr, stdout = path_stdout, env = env ) } diff --git a/R/utils.R b/R/utils.R index 6b0ea84ab..be30b3f89 100644 --- a/R/utils.R +++ b/R/utils.R @@ -99,3 +99,7 @@ rev_read <- function(path = ".pre-commit-config.yaml", repo = hooks_repo) { rev_as_pkg_version <- function(rev) { package_version(gsub("^v", "", rev)) } + +has_git <- function() { + nzchar(Sys.which("git")) +} diff --git a/inst/WORDLIST b/inst/WORDLIST index c44f28e5f..19af53a27 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -188,6 +188,7 @@ styler sublicenses Sublicensing Sys +SystemRequirements tcltk tempfile testthat diff --git a/inst/hooks/exported/readme-rmd-rendered.R b/inst/hooks/exported/readme-rmd-rendered.R index 7fd8514a5..14ef54ed1 100644 --- a/inst/hooks/exported/readme-rmd-rendered.R +++ b/inst/hooks/exported/readme-rmd-rendered.R @@ -3,7 +3,9 @@ if (file.exists("README.Rmd") & file.exists("README.md")) { if (file.info("README.md")$mtime < file.info("README.Rmd")$mtime) { rlang::abort("README.md is out of date; please re-knit README.Rmd.") } - + if (!nzchar(Sys.which("git"))) { + rlang::abort("git not found on `$PATH`, hook can't be ran.") + } file_names_staged <- system2( "git", c("diff --cached --name-only"), stdout = TRUE diff --git a/renv.lock b/renv.lock index 56e3918d2..d8ba175c9 100644 --- a/renv.lock +++ b/renv.lock @@ -13,77 +13,77 @@ "Package": "R.cache", "Version": "0.15.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "e92a8ea8388c47c82ed8aa435ed3be50" }, "R.methodsS3": { "Package": "R.methodsS3", "Version": "1.8.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "4bf6453323755202d5909697b6f7c109" }, "R.oo": { "Package": "R.oo", "Version": "1.24.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "5709328352717e2f0a9c012be8a97554" }, "R.utils": { "Package": "R.utils", "Version": "2.11.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "a7ecb8e60815c7a18648e84cd121b23a" }, "R6": { "Package": "R6", "Version": "2.5.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, "Rcpp": { "Package": "Rcpp", "Version": "1.0.7", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "dab19adae4440ae55aa8a9d238b246bb" }, "brew": { "Package": "brew", "Version": "1.0-6", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "92a5f887f9ae3035ac7afde22ba73ee9" }, "callr": { "Package": "callr", "Version": "3.7.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "461aa75a11ce2400245190ef5d3995df" }, "cli": { "Package": "cli", "Version": "3.1.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "66a3834e54593c89d8beefb312347e58" }, "codetools": { "Package": "codetools", "Version": "0.2-18", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "019388fc48e48b3da0d3a76ff94608a8" }, "commonmark": { "Package": "commonmark", "Version": "1.7", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "0f22be39ec1d141fd03683c06f3a6e67" }, "cpp11": { @@ -97,56 +97,49 @@ "Package": "crayon", "Version": "1.4.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "0a6a65d92bd45b47b94b84244b528d17" }, "cyclocomp": { "Package": "cyclocomp", "Version": "1.1.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "53cbed70a2f7472d48fb6aef08442f25" }, "desc": { "Package": "desc", "Version": "1.4.0", "Source": "Repository", - "Repository": "CRAN", - "Hash": "28763d08fadd0b733e3cee9dab4e12fe" - }, - "digest": { - "Package": "digest", - "Version": "0.6.29", - "Source": "Repository", "Repository": "RSPM", - "Hash": "cf6b206a045a684728c3267ef7596190" + "Hash": "28763d08fadd0b733e3cee9dab4e12fe" }, "docopt": { "Package": "docopt", "Version": "0.7.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "e9eeef7931ee99ca0093f3f20b88e09b" }, "ellipsis": { "Package": "ellipsis", "Version": "0.3.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077" }, "evaluate": { "Package": "evaluate", "Version": "0.14", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "ec8ca05cffcc70569eaaad8469d2a3a7" }, "fansi": { "Package": "fansi", "Version": "0.5.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "d447b40982c576a72b779f0a3b3da227" }, "fs": { @@ -160,7 +153,7 @@ "Package": "git2r", "Version": "0.29.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "b114135c4749076bd5ef74a5827b6f62" }, "glue": { @@ -174,49 +167,49 @@ "Package": "here", "Version": "1.0.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "24b224366f9c2e7534d2344d10d59211" }, "highr": { "Package": "highr", "Version": "0.9", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "8eb36c8125038e648e5d111c0d7b2ed4" }, "hunspell": { "Package": "hunspell", "Version": "3.0.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "3987784c19192ad0f2261c456d936df1" }, "jsonlite": { "Package": "jsonlite", "Version": "1.7.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "98138e0994d41508c7a6b84a0600cfcb" }, "knitr": { "Package": "knitr", "Version": "1.36", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "46344b93f8854714cdf476433a59ed10" }, "lazyeval": { "Package": "lazyeval", "Version": "0.2.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "d908914ae53b04d4c0c0fd72ecc35370" }, "lifecycle": { "Package": "lifecycle", "Version": "1.0.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "a6b6d352e3ed897373ab19d8395c98d0" }, "lintr": { @@ -235,21 +228,21 @@ "Package": "magrittr", "Version": "2.0.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "41287f1ac7d28a92f0a286ed507928d3" }, "pillar": { "Package": "pillar", "Version": "1.6.4", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "60200b6aa32314ac457d3efbb5ccbd98" }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, "pkgload": { @@ -263,28 +256,28 @@ "Package": "processx", "Version": "3.5.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "0cbca2bc4d16525d009c4dbba156b37c" }, "ps": { "Package": "ps", "Version": "1.6.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "32620e2001c1dce1af49c49dccbb9420" }, "purrr": { "Package": "purrr", "Version": "0.3.4", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "97def703420c8ab10d8f0e6c72101e02" }, "rematch2": { "Package": "rematch2", "Version": "2.1.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "76c9e04c712a05848ae7a23d2f170a40" }, "remotes": { @@ -317,35 +310,35 @@ "Package": "rlang", "Version": "0.4.12", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "0879f5388fe6e4d56d7ef0b7ccb031e5" }, "roxygen2": { "Package": "roxygen2", "Version": "7.1.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "eb9849556c4250305106e82edae35b72" }, "rprojroot": { "Package": "rprojroot", "Version": "2.0.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "249d8cd1e74a8f6a26194a91b47f21d1" }, "rstudioapi": { "Package": "rstudioapi", "Version": "0.13", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "06c85365a03fdaf699966cc1d3cf53ea" }, "spelling": { "Package": "spelling", "Version": "2.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "b8c899a5c83f0d897286550481c91798" }, "stringi": { @@ -359,7 +352,7 @@ "Package": "stringr", "Version": "1.4.0", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "0759e6b6c0957edb1311028a49a35e76" }, "styler": { @@ -385,14 +378,14 @@ "Package": "utf8", "Version": "1.2.2", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "c9c462b759a5cc844ae25b5942654d13" }, "vctrs": { "Package": "vctrs", "Version": "0.3.8", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "ecf749a1b39ea72bd9b51b76292261f1" }, "withr": { @@ -406,7 +399,7 @@ "Package": "xfun", "Version": "0.28", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "f7f3a61ab62cd046d307577a8ae12999" }, "xml2": { @@ -420,14 +413,14 @@ "Package": "xmlparsedata", "Version": "1.0.5", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "45e4bf3c46476896e821fc0a408fb4fc" }, "yaml": { "Package": "yaml", "Version": "2.2.1", "Source": "Repository", - "Repository": "CRAN", + "Repository": "RSPM", "Hash": "2826c5d9efb0a88f657c7a679c7106db" } } diff --git a/tests/testthat/test-hooks.R b/tests/testthat/test-hooks.R index 7d6307893..64a0dd880 100644 --- a/tests/testthat/test-hooks.R +++ b/tests/testthat/test-hooks.R @@ -238,32 +238,36 @@ run_test("deps-in-desc", # because .Rprofile is executed on startup, this must be an installed # package (to not give an error staight away) not listed in # test_path("in/DESCRIPTION") -expect_true(rlang::is_installed("R.cache")) -run_test("deps-in-desc", - "Rprofile", - suffix = "", error_msg = "Dependency check failed", - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), - file_transformer = function(files) { - writeLines("R.cache::findCache", files) - fs::file_move( - files, - fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) - ) - } -) +if (Sys.getenv("GITHUB_WORKFLOW") != "Hook tests") { + # seems like .Rprofile with renv activation does not get executed when + # argument to Rscript contains Rprofile ?! Skip this + expect_true(rlang::is_installed("R.cache")) + run_test("deps-in-desc", + "Rprofile", + suffix = "", error_msg = "Dependency check failed", + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + file_transformer = function(files) { + writeLines("R.cache::findCache", files) + fs::file_move( + files, + fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) + ) + } + ) -run_test("deps-in-desc", - "Rprofile", - suffix = "", error_msg = NULL, - artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), - file_transformer = function(files) { - writeLines("utils::head", files) - fs::file_move( - files, - fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) - ) - } -) + run_test("deps-in-desc", + "Rprofile", + suffix = "", error_msg = NULL, + artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")), + file_transformer = function(files) { + writeLines("utils::head", files) + fs::file_move( + files, + fs::path(fs::path_dir(files), paste0(".", fs::path_file(files))) + ) + } + ) +} ### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. @@ -304,84 +308,68 @@ run_test("roxygenize", ### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. ### readme-rmd-rendered #### -run_test("readme-rmd-rendered", - file_name = c("README.Rmd", "README.md"), - suffix = "", - error_msg = NULL, - msg = NULL, - file_transformer = function(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]) - git_init() - git2r::add(path = files) +if (has_git()) { + run_test("readme-rmd-rendered", + file_name = c("README.md", "README.Rmd"), + suffix = "", + error_msg = "out of date", + msg = NULL, + file_transformer = function(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]) + git_init() + git2r::add(path = files) + } + files } - files - } -) + ) -run_test("readme-rmd-rendered", - file_name = c("README.md", "README.Rmd"), - suffix = "", - error_msg = "out of date", - msg = NULL, - file_transformer = function(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]) - git_init() - git2r::add(path = files) - } - files - } -) + # only one file staged + run_test("readme-rmd-rendered", + file_name = c("README.Rmd", "README.md"), + suffix = "", + error_msg = "should be both staged", + msg = NULL, + file_transformer = function(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]) + git_init() + git2r::add(path = files[1]) + } + files + } + ) -# only one file staged -run_test("readme-rmd-rendered", - file_name = c("README.Rmd", "README.md"), - suffix = "", - error_msg = "should be both staged", - msg = NULL, - file_transformer = function(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]) + # only has md + run_test("readme-rmd-rendered", + file_name = "README.md", + suffix = "", + error_msg = NULL, + msg = NULL, + file_transformer = function(files) { git_init() git2r::add(path = files[1]) + files } - files - } -) - -# only has md -run_test("readme-rmd-rendered", - file_name = "README.md", - suffix = "", - error_msg = NULL, - msg = NULL, - file_transformer = function(files) { - git_init() - git2r::add(path = files[1]) - files - } -) + ) -# only has Rmd -run_test("readme-rmd-rendered", - file_name = "README.Rmd", - suffix = "", - error_msg = NULL, - msg = NULL, - file_transformer = function(files) { - git_init() - git2r::add(path = files[1]) - files - } -) + # only has Rmd + run_test("readme-rmd-rendered", + file_name = "README.Rmd", + suffix = "", + error_msg = NULL, + msg = NULL, + file_transformer = function(files) { + git_init() + git2r::add(path = files[1]) + files + } + ) +}