Skip to content

Commit 54c593b

Browse files
expose cache root arg
1 parent 0cea8be commit 54c593b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

.github/workflows/hook-dependencies-upate.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,26 @@ jobs:
7676
This PR updates the hook dependencies in `renv.lock`, auto-generated by [create-pull-request][1]. Close and re-open this to trigger `on: pull_request` events to circumvent [limitation of GitHub actions](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork).
7777
7878
[1]: https://github.com/peter-evans/create-pull-request
79+
80+
81+
82+
# # also see corresponding files to update
83+
# hook_deps <- function(root) {
84+
# out <- renv::dependencies("inst/hooks/exported/")$Package
85+
# desc <- desc::desc()
86+
# deps <- desc$get_deps()
87+
# dont <- c(
88+
# "yaml", "usethis", "withr", "rstudioapi", "precommit",
89+
# "httr" # lintr -> httr -> curl -> libcurl, but seems to give no erorr on
90+
# # loading lintr, plus https://github.com/jimhester/lintr/issues/861
91+
# )
92+
# out <- c(out, "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "git2r", "digest", "desc")
93+
# out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont)
94+
# out <- names(renv:::renv_package_dependencies(out))
95+
# return(out)
96+
# }
97+
#
98+
# options(renv.snapshot.filter = hook_deps)
99+
#
100+
# renv::snapshot(type = "custom", prompt = FALSE)
101+
# # or renv::snapshot(packages = hook_deps(), prompt = FALSE)

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
rev: v0.1.3.9133
99
hooks:
1010
- id: style-files
11-
args: [--style_pkg=styler, --style_fun=tidyverse_style]
11+
args: [--style_pkg=styler, --style_fun=tidyverse_style, --cache_root=styler-perm]
1212
exclude: >
1313
(?x)^(
1414
tests/testthat/in/.*\.R|

inst/hooks/exported/style-files.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env Rscript
22
'style files.
33
Usage:
4-
style_files [--style_pkg=<style_guide_pkg>] [--style_fun=<style_guide_fun>] [--no-warn-cache] <files>...
4+
style_files [--style_pkg=<style_guide_pkg>] [--style_fun=<style_guide_fun>] [--cache-root=<cache_root_>] [--no-warn-cache] <files>...
55
66
Options:
77
--style_pkg=<style_guide_pkg> Package where the style guide is stored [default: "styler"].
88
--style_fun=<style_guide_fun> The styling function in style_pkg [default: "tidyverse_style"].
99
--no-warn-cache Suppress the warning about a missing permanent cache.
10+
--cache-root=<cache_root_> Passed to `options("styler.cache_root")` [default: "styler"].
1011
' -> doc
1112

1213
if (packageVersion("precommit") < "0.1.3.9010") {
@@ -25,7 +26,7 @@ args <- commandArgs(trailingOnly = TRUE)
2526
non_file_args <- args[!grepl("^[^-][^-]", args)]
2627
keys <- setdiff(
2728
gsub("(^--[0-9A-Za-z_]+).*", "\\1", non_file_args),
28-
c("--style_pkg", "--style_fun", "--no-warn-cache", "cache")
29+
c("--style_pkg", "--style_fun", "--no-warn-cache", "--cache-root")
2930
)
3031
if (length(keys) > 0) {
3132
bare_keys <- gsub("^--", "", keys)
@@ -45,6 +46,8 @@ if (packageVersion("styler") < "1.3.2") {
4546
} else {
4647
precommit::may_require_permanent_cache(arguments$no_warn_cache)
4748
}
49+
options('styler.cache_root' = arguments$cache_root)
50+
print(c('cache root set to ', arguments$cache_root))
4851

4952
style <- eval(parse(text = paste(arguments$style_pkg, "::", arguments$style_fun)))
5053
tryCatch(

0 commit comments

Comments
 (0)