Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release {precommit} 0.4.1 #553

Merged
merged 22 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b9aa1de
prepare for change in error message in styler
lorenzwalthert Mar 25, 2024
b9dab4b
prepare release
lorenzwalthert Mar 25, 2024
75c44a5
use latest hook revisions
lorenzwalthert Mar 25, 2024
7955554
add thanks
lorenzwalthert Mar 25, 2024
e9ad5e0
require to be on release candidate branch for cran release
lorenzwalthert Mar 25, 2024
9b013d6
Release v0.4.1, see NEWS.md for details.
lorenzwalthert Mar 25, 2024
f19c0f3
parser error is different depending on R version
lorenzwalthert Mar 25, 2024
308d39c
Don't use deprecated with_handlers anynore to avoid testthat warning …
lorenzwalthert Mar 25, 2024
b8f72d2
Revert R version specific parser error
lorenzwalthert Mar 25, 2024
84dcff7
have no assumption about error messages of third-party packages
lorenzwalthert Mar 29, 2024
9bc452a
fix tests that ocurrs in interactive RStudio testing only ?!
lorenzwalthert Mar 29, 2024
b82f5c2
each hook gets own hook test file
lorenzwalthert Mar 29, 2024
17b764b
switch to third edition for testing
lorenzwalthert Mar 29, 2024
9237668
switch to third edition for testing
lorenzwalthert Mar 29, 2024
a9ac923
bump
lorenzwalthert Mar 30, 2024
fdd4f3a
rename to simplify filtering based on start of path (filter out impl …
lorenzwalthert Mar 30, 2024
c253b45
hook tests are now scattered over all files
lorenzwalthert Mar 30, 2024
4ae940a
rename for consistency
lorenzwalthert Mar 30, 2024
d2339ad
skip 8 tests about roots on CRAN since using something else than curr…
lorenzwalthert Mar 30, 2024
d8f2dba
skip impl-hook tests since we have hook tests
lorenzwalthert Mar 30, 2024
15a1ff4
with parallel tests, we can't rely on order, so tests requiring the p…
lorenzwalthert Mar 31, 2024
9f4e420
remove dependency on mockery
lorenzwalthert Mar 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
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
)
})
Loading
Loading