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 v0.2.1 #344

Merged
merged 27 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
71c5300
improve news
lorenzwalthert Dec 10, 2021
a790d2e
Release v0.2.1, see NEWS.md for details.
lorenzwalthert Dec 10, 2021
bda064b
update cran comments
lorenzwalthert Dec 10, 2021
2148df6
use rc branch name
lorenzwalthert Dec 10, 2021
895f43a
Revert "always expand paths"
lorenzwalthert Dec 10, 2021
ace2a22
also depend on newer fs
lorenzwalthert Dec 10, 2021
15af8bb
update packages
lorenzwalthert Dec 10, 2021
12c8854
improve error message
lorenzwalthert Dec 10, 2021
4f035b6
remove unused hook scripts
lorenzwalthert Dec 10, 2021
ca50a47
make sure to emit origiinal path, not tempfile path
lorenzwalthert Dec 10, 2021
b0a3688
bump hook ids
lorenzwalthert Dec 10, 2021
9196bbf
improve docs.
lorenzwalthert Dec 11, 2021
2663c19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2021
9c99069
error behavior
lorenzwalthert Dec 11, 2021
4ad2d5f
more test
lorenzwalthert Dec 11, 2021
6438291
derive executale from system for macOS (#347)
lorenzwalthert Dec 12, 2021
69f2e93
valid external link
lorenzwalthert Dec 12, 2021
f30be7c
replace rev if too high in autoupdate (affects use_precommit as well)
lorenzwalthert Dec 12, 2021
e9ed947
fix prefix v
lorenzwalthert Dec 12, 2021
5f6480a
roxygenize
lorenzwalthert Dec 12, 2021
cbb3d31
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2021
c1aaf94
doc news
lorenzwalthert Dec 12, 2021
489982e
new configs
lorenzwalthert Dec 12, 2021
22b94c0
fix news problems
lorenzwalthert Dec 13, 2021
447c91c
Revert "Revert "always expand paths""
lorenzwalthert Dec 13, 2021
5dd6523
avoid test on CRAN
lorenzwalthert Dec 13, 2021
8dfe04b
only require hard dependencies
lorenzwalthert Dec 13, 2021
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
2 changes: 1 addition & 1 deletion API
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ roxygenize_with_cache(key, dirs)
snippet_generate(snippet, open = rstudioapi::isAvailable(), root = here::here())
uninstall_precommit(scope = "repo", ask = "user", root = here::here())
update_precommit()
use_ci(ci = getOption("precommit.ci", "native"), force = FALSE, root = here::here())
use_ci(ci = getOption("precommit.ci", "native"), force = FALSE, open = rstudioapi::isAvailable(), root = here::here())
use_precommit(config_source = getOption("precommit.config_source"), force = FALSE, legacy_hooks = "forbid", open = rstudioapi::isAvailable(), install_hooks = TRUE, ci = getOption("precommit.ci", "native"), root = here::here())
use_precommit_config(config_source = getOption("precommit.config_source"), force = FALSE, open = rstudioapi::isAvailable(), verbose = FALSE, root = here::here())
version_precommit()
4 changes: 2 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.2.0.9002
Version: 0.2.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 @@ -48,4 +48,4 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
warning("Please install r-lib/pkgapi to make sure the file API is kept
up to date"); NULL} ) )
RoxygenNote: 7.1.1.9001
RoxygenNote: 7.1.2
19 changes: 15 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# precommit v0.2.0.9001 (Development version)
# precommit v0.2.1

# precommit v0.2.0.9000
This is a maintenance release on the request of CRAN (#337) and to improve
experience with the `language: r` switch conducted in `v0.2.0`. In particular,
note that projects using {renv} and RStudio are not very compatible with hook
versions > 0.1.3.9014 and `autoupdate()` results in downgrading the hook
versions (#346).

**API Changes**

Expand All @@ -17,6 +21,13 @@
* `deps-in-desc` always excludes `README.md` (#336).
* Document timeout and other problems with pre-commit.ci (#335).
* simplify `roxygenize` problem handling (#338).
* More executables on macOS are detected (#344).
* Only hard dependencies are generated with
`snippet_generate("additional-deps-roxygenize")` (#344)

Thanks to all people who contributed to this release:

[&#x0040;lorenzwalthert](https://github.com/lorenzwalthert), [&#x0040;pat-s](https://github.com/pat-s), and [&#x0040;smingerson](https://github.com/smingerson).

# precommit v0.2.0

Expand Down Expand Up @@ -139,11 +150,11 @@ A big hand to all the contributors of this release:
[&#x0040;arbues6](https://github.com/arbues6),
[&#x0040;b4D8](https://github.com/b4D8),
[&#x0040;bart1](https://github.com/bart1),
[&#x0040;dhersz](https://github.com/dhersz), [&#x0040;github-actions[bot]](https://github.com/github-actions[bot]), [&#x0040;joelnitta](https://github.com/joelnitta),
[&#x0040;dhersz](https://github.com/dhersz), [&#x0040;joelnitta](https://github.com/joelnitta),
[&#x0040;jucor](https://github.com/jucor),
[&#x0040;lorenzwalthert](https://github.com/lorenzwalthert), [&#x0040;lukasfeick-sw](https://github.com/lukasfeick-sw), [&#x0040;MarkMc1089](https://github.com/MarkMc1089),
[&#x0040;njtierney](https://github.com/njtierney),
[&#x0040;pat-s](https://github.com/pat-s), [&#x0040;pre-commit-ci[bot]](https://github.com/pre-commit-ci[bot]), [&#x0040;pwildenhain](https://github.com/pwildenhain), and [&#x0040;rossdrucker](https://github.com/rossdrucker)
[&#x0040;pat-s](https://github.com/pat-s), [&#x0040;pwildenhain](https://github.com/pwildenhain), and [&#x0040;rossdrucker](https://github.com/rossdrucker)

For previous versions of `NEWS.md` with news bullet per patch release, see the
[latest `NEWS.md` before gathering](https://github.com/lorenzwalthert/precommit/blob/7a8740714ab868d20e981b8b80898d7be050e34e/NEWS.md).
Expand Down
18 changes: 15 additions & 3 deletions R/exec.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,24 @@ path_derive_precommit_exec_win_python3plus_candidates <- function() {


path_derive_precommit_exec_macOS <- function() {
path_derive_precommit_exec_macOS_candidates() %>%
path_derive_precommit_exec_impl()
}

path_derive_precommit_exec_macOS_candidates <- function() {
candidate_system <- fs::dir_ls(
path_if_exist("/Library/Frameworks/Python.framework/Versions/"),
# avoid alias to /Library/Frameworks/Python.framework/Versions/Current/
regexp = "[0-9]$"
)

candidate_user <- fs::dir_ls(path_if_exist("~/Library/Python/"))
c(
fs::path(sort(fs::dir_ls(path_if_exist("~/Library/Python/")), decreasing = TRUE), "bin"), # pip
fs::path(sort(candidate_user, decreasing = TRUE), "bin"), # pip
fs::path(sort(candidate_system, decreasing = TRUE), "bin"),
"/usr/local/bin", # homebrew
"/opt/homebrew/bin" # homebrew Apple Silicon (M1 chip)
) %>%
path_derive_precommit_exec_impl()
)
}

#' Derive the pre-commit executable from the path
Expand Down
2 changes: 1 addition & 1 deletion R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ sys_call <- function(...) {

git_branch_set <- function(is_cran) {
if (is_cran) {
branch_name <- paste0("r-v", desc::desc_get_version())
branch_name <- paste0("rc-v", desc::desc_get_version())

sys_call(
"git",
Expand Down
12 changes: 7 additions & 5 deletions R/roxygen2.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ roxygen_assert_additional_dependencies <- function() {
# case used in package but not installed
rlang::abort(paste0(
"The roxygenize hook requires all dependencies of your package to be listed in ",
"the file `.pre-commit-config.yaml`.",
"the file `.pre-commit-config.yaml`. ",
"Call `precommit::snippet_generate('additional-deps-roxygenize')` ",
"to generate that list or ",
"comment out the hook under \n\n",
"` - id: roxygenize` \n\n to deactivate the hook.",
"\n\nThe initial error (from `pkgload::load_all()`) was: ",
"to generate that list or, to completely deactivate the hook, ",
"comment out all lines corresponding to that hook under \n\n",
" - id: roxygenize\n",
" some_key_under_id_roxygenize: comment-out-as-well\n",
" - id: some-other-hook-do-not-comment-out\n\n",
"The initial error (from `pkgload::load_all()`) was: ",
conditionMessage(out), ".\n\n"
))
}
Expand Down
114 changes: 90 additions & 24 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#' managed by pre-commit. "forbid", the default, will cause `use_precommit()`
#' to fail if there are such hooks. "allow" will run these along with
#' pre-commit. "remove" will delete them.
#' @param open Whether or not to open `.pre-commit-config.yaml` after
#' it's been placed in your repo as well as
#' [pre-commit.ci](https://pre-commit.ci) (if `ci = "native"`). The default is
#' `TRUE` when working in RStudio.
#' @inheritParams fallback_doc
#' @inheritParams use_precommit_config
#' @inheritSection use_precommit_config Copying an existing config file
Expand Down Expand Up @@ -54,13 +58,8 @@ use_precommit <- function(config_source = getOption("precommit.config_source"),
install_repo(root, install_hooks, legacy_hooks)
if (open) {
open_config(root)
use_ci(ci)
} else {
if (ci == "gha") {
use_ci(ci, force = force, root = root)
}
}

use_ci(ci, force = force, open = open, root = root)
invisible(NULL)
}

Expand All @@ -78,10 +77,20 @@ use_precommit <- function(config_source = getOption("precommit.config_source"),
#' to `NULL` if you don't want to use a continuous integration.
#' @param force Whether or not to overwrite an existing ci config file (only
#' relevant for `ci = "gha"`).
#' @param open Whether or not to open [pre-commit.ci](https://pre-commit.ci)
#' (if `ci = "native"`). The default is `TRUE` when working in RStudio.
#' @inheritParams fallback_doc
#' @export
use_ci <- function(ci = getOption("precommit.ci", "native"),
force = FALSE, root = here::here()) {
force = FALSE,
open = rstudioapi::isAvailable(),
root = here::here()) {
if (!fs::file_exists(fs::path(root, ".pre-commit-config.yaml"))) {
rlang::abort(paste0(
"Your repo has no `.pre-commit-config.yaml` file, please initialize ",
"{precommit} with `precommit::use_precommit()`."
))
}
if (is.na(ci)) {
return()
} else if (ci == "gha") {
Expand All @@ -99,16 +108,28 @@ use_ci <- function(ci = getOption("precommit.ci", "native"),
"{.code https://github.com/lorenzwalthert/precommit}."
))
} else if (ci == "native") {
cli::cli_ul('You may need to skip the roxygenize hook in the CI run as explained in {.code vignette("ci", package = "precommit")}')
Sys.sleep(2)
cli::cli_ul("Sign in with GitHub to authenticate {.url https://pre-commit.ci}.")
cli::cli_ul(paste0(
"Sign in with GitHub to authenticate {.url https://pre-commit.ci} and ",
"then come back to complete the set-up process."
))
Sys.sleep(2)
utils::browseURL("https://pre-commit.ci")
if (open) {
utils::browseURL("https://pre-commit.ci")
}
} else {
rlang::abort(
'Argument `ci` must be one of `"native"` (default), `"gha"` or `NULL`.'
)
}
config <- readLines(fs::path(root, ".pre-commit-config.yaml"))
if (length(grep("^ *- *id *: *roxygenize", config)) > 0) {
cli::cli_ul(paste0(
"It seems like you are using the roxygenize hook. This requires further ",
"edits in your {.code .pre-commit-config.yaml}, please run ",
"{.code precommit::snippet_generate('additional-deps-roxygenize')} to ",
"proceed."
))
}
}

#' Auto-update your hooks
Expand Down Expand Up @@ -136,13 +157,50 @@ autoupdate <- function(root = here::here()) {
preamble = "Running precommit autoupdate failed."
)
}
ensure_renv_precommit_compat(root = root)
invisible(out$exit_status)
})
}

ensure_renv_precommit_compat <- function(root = here::here()) {
withr::local_dir(root)
path_config <- ".pre-commit-config.yaml"
config_lines <- readLines(path_config, encoding = "UTF-8")
has_renv <- fs::file_exists("renv.lock")
if (!has_renv) {
return()
}

rev <- rev_read(path_config)
rlang::with_handlers(
{
rev <- rev_as_pkg_version(rev)
maximal_rev <- package_version("0.1.3.9014")
if (rev > maximal_rev) {
rlang::warn(paste0(
"It seems like you want to use {renv} and {precommit} in the same ",
"repo. This is not well supported for users of RStudio and ",
"`precommit > 0.1.3.9014` at the moment (details: ",
"https://github.com/lorenzwalthert/precommit/issues/342). ",
"Autoupdate aborted and `rev:` in `.pre-commit-config.yaml` set to ",
"a version compatible with {renv}."
))
config_lines <- gsub(
paste0("^ *rev *: *", "v", as.character(rev)),
" rev: v0.1.3.9014",
config_lines
)
withr::local_options(encoding = "native.enc")
writeLines(enc2utf8(config_lines), path_config, useBytes = TRUE)
}
},
error = function(e) NULL
)
}


upstream_repo_url_is_outdated <- function() {
purrr::map_chr(yaml::read_yaml(".pre-commit-config.yaml")$repos, ~ .x$repo) %>%
rev_read(".pre-commit-config.yaml") %>%
grepl("https://github.com/lorenzwalthert/pre-commit-hooks", ., fixed = TRUE) %>%
any()
}
Expand All @@ -156,7 +214,7 @@ upstream_repo_url_is_outdated <- function() {
#'
#' * additional-deps-roxygenize: Code to paste into
#' `.pre-commit-config.yaml` for the additional dependencies required by
#' roxygen2.
#' the roxygenize hook.
#' @param snippet Name of the snippet.
#' @param open Whether or not to open the .pre-commit-config.yaml. The default
#' is `TRUE` when working in RStudio. Otherwise, we recommend manually opening
Expand All @@ -175,20 +233,29 @@ snippet_generate <- function(snippet = "",
"\n"
))
deps <- desc::desc_get_deps()
non_r_deps <- deps[!(deps$type == "Depends" & deps$package == "R"), ]
non_r_deps <- non_r_deps[order(non_r_deps$package), ]
snippet_generate_impl_additional_deps_roxygenize(non_r_deps$package) %>%
hard_dependencies <- deps[(deps$type %in% c("Depends", "Imports")), "package"]
hard_dependencies_vec <- hard_dependencies %>%
setdiff("R")
if (length(hard_dependencies_vec) < 1) {
cli::cli_alert_success(paste0(
"According to {.code DESCRIPTION}`, there are no hard dependencies of ",
"your package. You are set."
))
return()
}
hard_dependencies %>%
snippet_generate_impl_additional_deps_roxygenize() %>%
cat(sep = "")
cat("\n")
cli::cli_ul(
cli::cli_ul(paste0(
"Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the ",
"above code."
)
))
cli::cli_alert_info(paste0(
"Note that CI services like {.url pre-commit.ci} have build-time ",
"restrictions and installing the above dependencies may exceed those. ",
"To skip the hook on {.url pre-commit.ci}, see ",
'{.code vignette("ci", package = "precommit")}.'
"restrictions and installing the above dependencies may exceed those, ",
"resulting in a timeout. See ",
'{.code vignette("ci", package = "precommit")} for details and solutions.'
))
remote_deps <- rlang::with_handlers(
desc::desc_get_field("Remotes"),
Expand All @@ -198,7 +265,7 @@ snippet_generate <- function(snippet = "",
rlang::warn(paste0(
"It seems you have remote dependencies in your `DESCRIPTION`. You ",
"need to edit the above list manually to match the syntax `renv::install()` ",
"understands, i.e. if you have in your `DESCRIPTION`", "
"understands, i.e. if you have in your `DESCRIPTION`

Imports:
tidyr
Expand All @@ -221,8 +288,7 @@ You need in your `.pre-commit-config.yaml`

snippet_generate_impl_additional_deps_roxygenize <- function(packages, with_version = FALSE) {
out <- paste0(
" - ", packages, if (with_version) "@",
if (with_version) purrr::map_chr(packages, ~ as.character(packageVersion(.x))), "\n",
" - ", packages, "\n",
collapse = ""
) %>%
sort()
Expand Down
2 changes: 1 addition & 1 deletion R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ hook_state_create <- function(tempdir,
env) {
withr::local_dir(tempdir)
files <- fs::path_rel(path_candidate_temp, tempdir)
# https://r.789695.n4.nabble.com/Error-message-Rscript-should-not-be-used-without-a-path-td4748071.html
# 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),
stderr = path_stderr, stdout = path_stdout, env = env
Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,17 @@ git_init <- function(path = ".") {
core.autocrlf = "true"
)
}


#' Read the refs corresponding to a hooks repo
#' @keywords internal
rev_read <- function(path = ".pre-commit-config.yaml", repo = hooks_repo) {
config <- yaml::read_yaml(path)
idx <- purrr::map_chr(config$repos, ~ .x$repo) %>%
grep(repo, ., fixed = TRUE)
config$repos[[idx]]$rev
}

rev_as_pkg_version <- function(rev) {
package_version(gsub("^v", "", rev))
}
3 changes: 3 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
This is a re-submission to fix problems related to end of line encoding
in R devel on windows related to the new UCRT toolchain (https://github.com/lorenzwalthert/precommit/issues/320).

## Test environments

* ubuntu 18.04 (on GitHub Actions): R 4.1.2
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ tibble
tidelift
Tidelift
tidyverse
toolchain
trailingOnly
travis
tryCatch
ubuntu
UCRT
uninitialised
Uninstallation
unlist
Expand Down
9 changes: 0 additions & 9 deletions inst/bin/codemeta-description-updated

This file was deleted.

Loading