Skip to content

Commit 3cc33e7

Browse files
Merge pull request #553 from lorenzwalthert/rc-v0.4.1
Release {precommit} 0.4.1
2 parents 282596e + 9f4e420 commit 3cc33e7

37 files changed

+996
-982
lines changed

.github/workflows/hook-tests.yaml

+10-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
options(install.packages.compile.from.source = "never", pkgType = "binary")
6262
renv::restore()
6363
# install hook-specific additional_dependencies from .pre-commit-config.yaml
64-
renv::install(c('pkgdown', 'mockery'))
64+
renv::install(c('pkgdown'))
6565
renv::install(getwd(), dependencies = FALSE)
6666
# needed to make sure renv is activated in run_test()
6767
activate <- c(
@@ -97,12 +97,15 @@ jobs:
9797
- name: Test
9898
run: |
9999
pkgload::load_all()
100-
testthat::test_file(
101-
"tests/testthat/test-hooks.R",
102-
reporter = testthat::MultiReporter$new(list(
103-
testthat::CheckReporter$new(), testthat::FailReporter$new()
104-
))
105-
)
100+
hook_test_files <- as.character(fs::dir_ls('tests/testthat/', regexp = "test-hook-.*\\.R", type = "file"))
101+
tester <- function(file) {
102+
testthat::test_file(file,
103+
reporter = testthat::MultiReporter$new(list(
104+
testthat::CheckReporter$new(), testthat::FailReporter$new()
105+
))
106+
)
107+
}
108+
purrr::walk(hook_test_files, tester)
106109
shell: Rscript {0}
107110
- name: Show testthat output
108111
if: always()

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ repos:
106106
# Only required when https://pre-commit.ci is used for config validation
107107
- id: check-pre-commit-ci-config
108108
- repo: https://github.com/lorenzwalthert/gitignore-tidy
109-
rev: 475bf5d96927a1887ce2863ff3075b1d7240bc51
109+
rev: 0.1.2
110110
hooks:
111111
- id: tidy-gitignore
112112
- repo: local

DESCRIPTION

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: precommit
22
Title: Pre-Commit Hooks
3-
Version: 0.4.0.9000
3+
Version: 0.4.1
44
Author: Lorenz Walthert
55
Maintainer: Lorenz Walthert <[email protected]>
66
Description: Useful git hooks for R building on top of the multi-language
@@ -29,7 +29,6 @@ Suggests:
2929
glue,
3030
knitr,
3131
lintr,
32-
mockery,
3332
pkgload,
3433
pkgdown,
3534
reticulate (>= 1.16),
@@ -50,3 +49,5 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
5049
up to date"); NULL} ) )
5150
RoxygenNote: 7.3.1
5251
SystemRequirements: git
52+
Config/testthat/parallel: true
53+
Config/testthat/edition: 3

NEWS.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# precommit 0.4.1
2+
3+
This release ensures unit tests can handle the error messages from {styler}
4+
correctly that were modified slightly. Apart from hook dependency updates, this
5+
release adds no user-facing changes.
6+
7+
Thanks [&#x0040;joshpersi](https://github.com/joshpersi) for contributing to this
8+
release.
9+
10+
111
# precommit 0.4.0
212

313

R/config.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ set_config_source <- function(config_source,
8484

8585
target <- fs::path_ext_set(tmp, fs::path_ext(config_source))
8686
utils::download.file(config_source, target, quiet = TRUE)
87-
rlang::with_handlers(
87+
rlang::try_fetch(
8888
yaml::read_yaml(target, fileEncoding = "UTF-8"),
8989
error = function(e) {
9090
rlang::abort(paste0(

R/exec.R

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ path_precommit_exec <- function(check_if_exists = TRUE) {
3232
final
3333
}
3434

35+
#' Get the operating System
36+
#'
37+
#' Can't mock base package (either because it's an `.Internal` or for some other
38+
#' reason).
39+
#' @keywords internal
40+
get_os <- function() {
41+
tolower(Sys.info()[["sysname"]])
42+
}
43+
3544
#' @rdname path_precommit_exec
3645
#' @examples
3746
#' \dontrun{
@@ -56,7 +65,7 @@ path_pre_commit_exec <- function(check_if_exists = TRUE) {
5665
#' @keywords internal
5766
path_derive_precommit_exec <- function() {
5867
path <- path_derive_precommit_exec_path()
59-
os <- tolower(Sys.info()[["sysname"]])
68+
os <- get_os()
6069
if (os == "darwin") {
6170
path <- c(path, path_derive_precommit_exec_macOS())
6271
} else if (os == "windows") {

R/release.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ release_prechecks <- function(bump, is_cran) {
139139
dsc <- desc::description$new()
140140
suppressMessages(dsc$bump_version(bump))
141141
new_version <- paste0("v", dsc$get_version())
142+
if (is_cran) {
143+
release_branch <- paste0("rc-", new_version)
144+
if (!(release_branch %in% names(git2r::branches()))) {
145+
rlang::abort(paste0("need to be on branch ", release_branch))
146+
}
147+
}
142148
abort_if_not_yes("Your target release has version {new_version}, correct?")
143-
abort_if_not_yes("Did you prepare NEWS.md for this version ({new_version})?")
149+
abort_if_not_yes("Did you commit NEWS.md for this version ({new_version})?")
144150
dsc
145151
}
146152

R/roxygen2.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ diff_requires_run_roxygenize <- function(root = ".") {
3939
#' @keywords internal
4040
#' @export
4141
roxygen_assert_additional_dependencies <- function() {
42-
out <- rlang::with_handlers(
42+
out <- rlang::try_fetch(
4343
# roxygen2 will load: https://github.com/r-lib/roxygen2/issues/771
4444
pkgload::load_all(quiet = TRUE),
4545
error = function(e) {
@@ -80,7 +80,7 @@ roxygen_assert_additional_dependencies <- function() {
8080
#' @importFrom R.cache saveCache
8181
# fails if accessed with R.cache::saveCache()!
8282
roxygenize_with_cache <- function(key, dirs) {
83-
out <- rlang::with_handlers(
83+
out <- rlang::try_fetch(
8484
roxygen2::roxygenise(),
8585
error = function(e) e
8686
)

R/setup.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ autoupdate <- function(root = here::here()) {
167167

168168
ensure_renv_precommit_compat <- function(package_version_renv = utils::packageVersion("renv"),
169169
root = here::here()) {
170-
is_precommit <- suppressWarnings(rlang::with_handlers(
170+
is_precommit <- suppressWarnings(rlang::try_fetch(
171171
unname(read.dcf("DESCRIPTION")[, "Package"]) == "precommit",
172172
error = function(e) FALSE
173173
))
@@ -189,7 +189,7 @@ ensure_renv_precommit_compat <- function(package_version_renv = utils::packageVe
189189
}
190190

191191
rev <- rev_read(path_config)
192-
should_fail <- rlang::with_handlers(
192+
should_fail <- rlang::try_fetch(
193193
{
194194
rev <- rev_as_pkg_version(rev)
195195
maximal_rev <- package_version("0.1.3.9014")
@@ -279,7 +279,7 @@ snippet_generate <- function(snippet = "",
279279
"supported for {.url pre-commit.ci}. See ",
280280
'{.code vignette("ci", package = "precommit")} for details and solutions.'
281281
))
282-
remote_deps <- rlang::with_handlers(
282+
remote_deps <- rlang::try_fetch(
283283
desc::desc_get_field("Remotes"),
284284
error = function(e) character()
285285
)

R/testing.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ hook_state_assert_one <- function(path_candidate,
227227
if (exit_status != 0) {
228228
testthat::fail("Expected: No error. Found:", contents)
229229
}
230-
testthat::expect_equivalent(candidate, reference)
230+
testthat::expect_equal(candidate, reference, ignore_attr = TRUE)
231231
if (!is.null(std_out)) {
232232
contents <- readLines(path_stdout)
233233
testthat::expect_match(

R/utils.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ is_conda_installation <- function() {
3030
}
3131

3232
is_package <- function(root = here::here()) {
33-
rlang::with_handlers(
33+
rlang::try_fetch(
3434
rprojroot::find_package_root_file(path = root),
3535
error = function(e) NULL
3636
) %>%
@@ -129,7 +129,7 @@ has_git <- function() {
129129
is_git_repo <- function(root = here::here()) {
130130
withr::local_dir(root)
131131
if (has_git()) {
132-
rlang::with_handlers(
132+
rlang::try_fetch(
133133
{
134134
output <- call_and_capture(
135135
"git",

cran-comments.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
This is a submission due to changes in roxygen2 7.3.0 and fixes also some issues
2-
related to R devel changes.
1+
This is a submission due to changes in styler's error messages.
32

43
## Test environments
54

6-
- ubuntu 18.04 (on GitHub Actions): R 4.2
7-
- Windows (on GitHub Actions): R 4.2
8-
- macOS (on GitHub Actions): R 4.2
5+
- ubuntu 18.04 (on GitHub Actions): R 4.3
6+
- Windows (on GitHub Actions): R 4.3
7+
- macOS (on GitHub Actions): R 4.3
98
- win-builder: R devel
109

1110
## R CMD check results

inst/WORDLIST

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ stdout
192192
sterr
193193
stopifnot
194194
styler
195+
styler's
195196
sublicenses
196197
Sublicensing
197198
Sys

inst/pre-commit-config-pkg.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# R specific hooks: https://github.com/lorenzwalthert/precommit
33
repos:
44
- repo: https://github.com/lorenzwalthert/precommit
5-
rev: v0.4.0
5+
rev: v0.4.1
66
hooks:
77
- id: style-files
88
args: [--style_pkg=styler, --style_fun=tidyverse_style]

inst/pre-commit-config-proj.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# R specific hooks: https://github.com/lorenzwalthert/precommit
33
repos:
44
- repo: https://github.com/lorenzwalthert/precommit
5-
rev: v0.4.0
5+
rev: v0.4.1
66
hooks:
77
- id: style-files
88
args: [--style_pkg=styler, --style_fun=tidyverse_style]

inst/update-dependency-graph-existing-packages.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ hook_deps <- function(root) {
44
deps <- desc$get_deps()
55
dont <- c(
66
"yaml", "usethis", "withr", "rstudioapi", "precommit",
7-
"pkgdown", "mockery",
7+
"pkgdown",
88
"httr"
99
)
10-
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc", "mockery")
10+
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc")
1111
out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont)
1212
out <- names(renv:::renv_package_dependencies(out))
1313
return(sort(out))

man/get_os.Rd

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-conda.R

+38-1
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ if (!on_cran()) {
181181
})
182182
test_that("can update via conda", {
183183
if (not_conda()) {
184+
local_mocked_bindings(assert_reticulate_is_installed = function(...) NULL)
184185
expect_error(
185-
with_mock(update_precommit(), "precommit:::assert_reticulate_is_installed" = function(...) NULL),
186+
update_precommit(),
186187
paste(
187188
"You can only update your pre-commit executable via the R API if you",
188189
"chose the installation method via conda"
@@ -201,3 +202,39 @@ if (!on_cran()) {
201202
}
202203
})
203204
}
205+
206+
test_that("Autoupdate is not conducted when renv present in incompatible setup", {
207+
skip_on_cran()
208+
209+
# mock old pre-commit and renv versions
210+
local_mocked_bindings(version_precommit = function(...) "2.13.0")
211+
212+
local_test_setup(
213+
git = TRUE, use_precommit = TRUE, install_hooks = FALSE, open = FALSE
214+
)
215+
initial <- rev_read() %>%
216+
rev_as_pkg_version()
217+
# simulate adding {renv}
218+
writeLines("", "renv.lock")
219+
220+
# should downgrade rev
221+
expect_error(
222+
ensure_renv_precommit_compat(
223+
package_version_renv = package_version("0.13.0"), root = getwd()
224+
),
225+
"Please update"
226+
)
227+
downgraded <- rev_read() %>%
228+
rev_as_pkg_version()
229+
expect_true(downgraded == initial)
230+
231+
# simulate removing {renv} should be updated
232+
fs::file_delete("renv.lock")
233+
expect_warning(
234+
ensure_renv_precommit_compat(
235+
package_version("0.13.0"),
236+
root = getwd()
237+
),
238+
NA
239+
)
240+
})

0 commit comments

Comments
 (0)