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

Lines changed: 10 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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(

0 commit comments

Comments
 (0)