Skip to content

Commit

Permalink
Merge pull request #553 from lorenzwalthert/rc-v0.4.1
Browse files Browse the repository at this point in the history
Release {precommit} 0.4.1
  • Loading branch information
lorenzwalthert committed Apr 1, 2024
2 parents 282596e + 9f4e420 commit 3cc33e7
Show file tree
Hide file tree
Showing 37 changed files with 996 additions and 982 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/hook-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
options(install.packages.compile.from.source = "never", pkgType = "binary")
renv::restore()
# install hook-specific additional_dependencies from .pre-commit-config.yaml
renv::install(c('pkgdown', 'mockery'))
renv::install(c('pkgdown'))
renv::install(getwd(), dependencies = FALSE)
# needed to make sure renv is activated in run_test()
activate <- c(
Expand Down Expand Up @@ -97,12 +97,15 @@ jobs:
- name: Test
run: |
pkgload::load_all()
testthat::test_file(
"tests/testthat/test-hooks.R",
reporter = testthat::MultiReporter$new(list(
testthat::CheckReporter$new(), testthat::FailReporter$new()
))
)
hook_test_files <- as.character(fs::dir_ls('tests/testthat/', regexp = "test-hook-.*\\.R", type = "file"))
tester <- function(file) {
testthat::test_file(file,
reporter = testthat::MultiReporter$new(list(
testthat::CheckReporter$new(), testthat::FailReporter$new()
))
)
}
purrr::walk(hook_test_files, tester)
shell: Rscript {0}
- name: Show testthat output
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ repos:
# Only required when https://pre-commit.ci is used for config validation
- id: check-pre-commit-ci-config
- repo: https://github.com/lorenzwalthert/gitignore-tidy
rev: 475bf5d96927a1887ce2863ff3075b1d7240bc51
rev: 0.1.2
hooks:
- id: tidy-gitignore
- repo: local
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: precommit
Title: Pre-Commit Hooks
Version: 0.4.0.9000
Version: 0.4.1
Author: Lorenz Walthert
Maintainer: Lorenz Walthert <lorenz.walthert@icloud.com>
Description: Useful git hooks for R building on top of the multi-language
Expand Down Expand Up @@ -29,7 +29,6 @@ Suggests:
glue,
knitr,
lintr,
mockery,
pkgload,
pkgdown,
reticulate (>= 1.16),
Expand All @@ -50,3 +49,5 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
up to date"); NULL} ) )
RoxygenNote: 7.3.1
SystemRequirements: git
Config/testthat/parallel: true
Config/testthat/edition: 3
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# precommit 0.4.1

This release ensures unit tests can handle the error messages from {styler}
correctly that were modified slightly. Apart from hook dependency updates, this
release adds no user-facing changes.

Thanks [&#x0040;joshpersi](https://github.com/joshpersi) for contributing to this
release.


# precommit 0.4.0


Expand Down
2 changes: 1 addition & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ set_config_source <- function(config_source,

target <- fs::path_ext_set(tmp, fs::path_ext(config_source))
utils::download.file(config_source, target, quiet = TRUE)
rlang::with_handlers(
rlang::try_fetch(
yaml::read_yaml(target, fileEncoding = "UTF-8"),
error = function(e) {
rlang::abort(paste0(
Expand Down
11 changes: 10 additions & 1 deletion R/exec.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ path_precommit_exec <- function(check_if_exists = TRUE) {
final
}

#' Get the operating System
#'
#' Can't mock base package (either because it's an `.Internal` or for some other
#' reason).
#' @keywords internal
get_os <- function() {
tolower(Sys.info()[["sysname"]])
}

#' @rdname path_precommit_exec
#' @examples
#' \dontrun{
Expand All @@ -56,7 +65,7 @@ path_pre_commit_exec <- function(check_if_exists = TRUE) {
#' @keywords internal
path_derive_precommit_exec <- function() {
path <- path_derive_precommit_exec_path()
os <- tolower(Sys.info()[["sysname"]])
os <- get_os()
if (os == "darwin") {
path <- c(path, path_derive_precommit_exec_macOS())
} else if (os == "windows") {
Expand Down
8 changes: 7 additions & 1 deletion R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ release_prechecks <- function(bump, is_cran) {
dsc <- desc::description$new()
suppressMessages(dsc$bump_version(bump))
new_version <- paste0("v", dsc$get_version())
if (is_cran) {
release_branch <- paste0("rc-", new_version)
if (!(release_branch %in% names(git2r::branches()))) {
rlang::abort(paste0("need to be on branch ", release_branch))
}
}
abort_if_not_yes("Your target release has version {new_version}, correct?")
abort_if_not_yes("Did you prepare NEWS.md for this version ({new_version})?")
abort_if_not_yes("Did you commit NEWS.md for this version ({new_version})?")
dsc
}

Expand Down
4 changes: 2 additions & 2 deletions R/roxygen2.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ diff_requires_run_roxygenize <- function(root = ".") {
#' @keywords internal
#' @export
roxygen_assert_additional_dependencies <- function() {
out <- rlang::with_handlers(
out <- rlang::try_fetch(
# roxygen2 will load: https://github.com/r-lib/roxygen2/issues/771
pkgload::load_all(quiet = TRUE),
error = function(e) {
Expand Down Expand Up @@ -80,7 +80,7 @@ roxygen_assert_additional_dependencies <- function() {
#' @importFrom R.cache saveCache
# fails if accessed with R.cache::saveCache()!
roxygenize_with_cache <- function(key, dirs) {
out <- rlang::with_handlers(
out <- rlang::try_fetch(
roxygen2::roxygenise(),
error = function(e) e
)
Expand Down
6 changes: 3 additions & 3 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ autoupdate <- function(root = here::here()) {

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

rev <- rev_read(path_config)
should_fail <- rlang::with_handlers(
should_fail <- rlang::try_fetch(
{
rev <- rev_as_pkg_version(rev)
maximal_rev <- package_version("0.1.3.9014")
Expand Down Expand Up @@ -279,7 +279,7 @@ snippet_generate <- function(snippet = "",
"supported for {.url pre-commit.ci}. See ",
'{.code vignette("ci", package = "precommit")} for details and solutions.'
))
remote_deps <- rlang::with_handlers(
remote_deps <- rlang::try_fetch(
desc::desc_get_field("Remotes"),
error = function(e) character()
)
Expand Down
2 changes: 1 addition & 1 deletion R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ hook_state_assert_one <- function(path_candidate,
if (exit_status != 0) {
testthat::fail("Expected: No error. Found:", contents)
}
testthat::expect_equivalent(candidate, reference)
testthat::expect_equal(candidate, reference, ignore_attr = TRUE)
if (!is.null(std_out)) {
contents <- readLines(path_stdout)
testthat::expect_match(
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ is_conda_installation <- function() {
}

is_package <- function(root = here::here()) {
rlang::with_handlers(
rlang::try_fetch(
rprojroot::find_package_root_file(path = root),
error = function(e) NULL
) %>%
Expand Down Expand Up @@ -129,7 +129,7 @@ has_git <- function() {
is_git_repo <- function(root = here::here()) {
withr::local_dir(root)
if (has_git()) {
rlang::with_handlers(
rlang::try_fetch(
{
output <- call_and_capture(
"git",
Expand Down
9 changes: 4 additions & 5 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
This is a submission due to changes in roxygen2 7.3.0 and fixes also some issues
related to R devel changes.
This is a submission due to changes in styler's error messages.

## Test environments

- ubuntu 18.04 (on GitHub Actions): R 4.2
- Windows (on GitHub Actions): R 4.2
- macOS (on GitHub Actions): R 4.2
- ubuntu 18.04 (on GitHub Actions): R 4.3
- Windows (on GitHub Actions): R 4.3
- macOS (on GitHub Actions): R 4.3
- win-builder: R devel

## R CMD check results
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ stdout
sterr
stopifnot
styler
styler's
sublicenses
Sublicensing
Sys
Expand Down
2 changes: 1 addition & 1 deletion inst/pre-commit-config-pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
rev: v0.4.1
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
Expand Down
2 changes: 1 addition & 1 deletion inst/pre-commit-config-proj.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
rev: v0.4.1
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
Expand Down
4 changes: 2 additions & 2 deletions inst/update-dependency-graph-existing-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ hook_deps <- function(root) {
deps <- desc$get_deps()
dont <- c(
"yaml", "usethis", "withr", "rstudioapi", "precommit",
"pkgdown", "mockery",
"pkgdown",
"httr"
)
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc", "mockery")
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc")
out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont)
out <- names(renv:::renv_package_dependencies(out))
return(sort(out))
Expand Down
13 changes: 13 additions & 0 deletions man/get_os.Rd

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

39 changes: 38 additions & 1 deletion tests/testthat/test-conda.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ if (!on_cran()) {
})
test_that("can update via conda", {
if (not_conda()) {
local_mocked_bindings(assert_reticulate_is_installed = function(...) NULL)
expect_error(
with_mock(update_precommit(), "precommit:::assert_reticulate_is_installed" = function(...) NULL),
update_precommit(),
paste(
"You can only update your pre-commit executable via the R API if you",
"chose the installation method via conda"
Expand All @@ -201,3 +202,39 @@ if (!on_cran()) {
}
})
}

test_that("Autoupdate is not conducted when renv present in incompatible setup", {
skip_on_cran()

# mock old pre-commit and renv versions
local_mocked_bindings(version_precommit = function(...) "2.13.0")

local_test_setup(
git = TRUE, use_precommit = TRUE, install_hooks = FALSE, open = FALSE
)
initial <- rev_read() %>%
rev_as_pkg_version()
# simulate adding {renv}
writeLines("", "renv.lock")

# should downgrade rev
expect_error(
ensure_renv_precommit_compat(
package_version_renv = package_version("0.13.0"), root = getwd()
),
"Please update"
)
downgraded <- rev_read() %>%
rev_as_pkg_version()
expect_true(downgraded == initial)

# simulate removing {renv} should be updated
fs::file_delete("renv.lock")
expect_warning(
ensure_renv_precommit_compat(
package_version("0.13.0"),
root = getwd()
),
NA
)
})

0 comments on commit 3cc33e7

Please sign in to comment.