Skip to content

Commit 072debe

Browse files
Merge pull request #295 from lorenzwalthert/fix-lang-r
2 parents e33cc36 + 0d7654b commit 072debe

File tree

10 files changed

+99
-71
lines changed

10 files changed

+99
-71
lines changed

R/roxygen2.R

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,21 @@ extract_diff_root <- function(root = here::here()) {
5858
#' @export
5959
diff_requires_run_roxygenize <- function(root = here::here()) {
6060
if (rlang::with_handlers(withr::with_namespace("git2r", FALSE), error = function(...) TRUE)) {
61-
rlang::warn("You need to install the R package git2r (and the required system dependency if you are on Linux) to benefit from caching of this hook.")
61+
generic <- paste0(
62+
" Please add the package as a dependency to ",
63+
"`.pre-commit-config.yaml` -> `id: roxygenize` -> ",
64+
"`additional_dependencies` and try again. The package must be ",
65+
"specified so `renv::install()` understands it, e.g. like this:\n\n",
66+
" - id: roxygenize",
67+
"
68+
additional_dependencies:
69+
- r-lib/git2r\n\n"
70+
)
71+
msg <- paste0(
72+
"The R package {git2r} must be available to benefit from caching of this hook.",
73+
generic
74+
)
75+
rlang::warn(msg)
6276
return(TRUE)
6377
}
6478
changed_lines_content <- extract_diff_root(root)
@@ -89,7 +103,7 @@ roxygen_assert_additional_dependencies <- function() {
89103
e
90104
}
91105
)
92-
if (inherits(out, "packageNotFoundError")) {
106+
if (inherits(out, "packageNotFoundError") || ("message" %in% names(out) && grepl("Dependency package(\\(s\\))? .* not available", out$message))) {
93107
# case used in package but not installed
94108
rlang::abort(paste0(
95109
"The roxygenize hook requires all* dependencies of your package to be listed in ",
@@ -143,8 +157,7 @@ roxygenize_with_cache <- function(key, dirs) {
143157
" - id: roxygenize",
144158
"
145159
additional_dependencies:
146-
- r-lib/pkgapi
147-
160+
- r-lib/pkgapi\n\n"
148161
))
149162
} else if (inherits(out, "error")) {
150163
rlang::abort(conditionMessage(out))

R/setup.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ snippet_generate <- function(snippet = "", root = here::here()) {
113113
)
114114
deps <- desc::desc_get_deps()
115115
deps <- deps[order(deps$package), ]
116-
paste0(
117-
" - ", deps$package, "@",
118-
purrr::map_chr(deps$package, ~ as.character(packageVersion(.x))), "\n",
119-
collapse = ""
120-
) %>%
121-
sort() %>%
116+
snippet_generate_impl_additional_deps_roxygenize(deps$package) %>%
122117
cat(sep = "")
123118
remote_deps <- rlang::with_handlers(
124119
desc::desc_get_field("Remotes"),
@@ -144,3 +139,12 @@ You need in your `.pre-commit-config.yaml`
144139
}
145140
}
146141
}
142+
143+
snippet_generate_impl_additional_deps_roxygenize <- function(packages) {
144+
paste0(
145+
" - ", packages, "@",
146+
purrr::map_chr(packages, ~ as.character(packageVersion(.x))), "\n",
147+
collapse = ""
148+
) %>%
149+
sort()
150+
}

inst/WORDLIST

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ CMD
44
Ctrl
55
EOF
66
Ei
7+
Eic
78
Homebrew
9+
KernSmooth
810
Lifecycle
911
MERCHANTABILITY
1012
RData
@@ -25,24 +27,31 @@ SHA
2527
Sublicensing
2628
Sys
2729
Uninstallation
30+
Unstaged
2831
Upvote
2932
VignetteBuilder
3033
WIPO
3134
Walthert
35+
Za
3236
ae
3337
api
3438
appveyor
3539
arg
3640
args
3741
artific
3842
autoupdate
43+
bd
3944
beaefa
4045
behaviour
4146
bliblablupp
47+
cfe
4248
ci
4349
cli
4450
cmd
4551
codemeta
52+
codemetar
53+
codetools
54+
commandArgs
4655
comparator
4756
conda
4857
conditionMessage
@@ -73,10 +82,13 @@ fs
7382
fsf
7483
fsssile
7584
getOption
85+
getParseData
7686
getwd
7787
gh
7888
github
7989
gitignore
90+
grDevices
91+
grepl
8092
gsub
8193
href
8294
http
@@ -87,10 +99,12 @@ impl
8799
init
88100
io
89101
isAvailable
102+
isTRUE
90103
jpeg
91104
json
92105
knitr
93106
lang
107+
lapply
94108
lgpl
95109
licensors
96110
lintr
@@ -102,16 +116,20 @@ macOS
102116
magrittr
103117
maxkb
104118
md
119+
mgcv
105120
miniconda
106121
mis
107122
modef
108123
msg
109124
mtime
110125
navbar
111126
netlify
127+
nlme
128+
nnet
112129
noncommercially
113130
nrow
114131
nt
132+
num
115133
oneliner
116134
os
117135
overscope
@@ -150,23 +168,32 @@ ropenscilabs
150168
roxygen
151169
roxygenise
152170
roxygenize
171+
rpart
153172
rprojroot
154173
rstudio
155174
rstudioapi
156175
saveCache
157176
seealso
177+
sep
178+
setdiff
158179
stderr
159180
stdout
160181
sterr
161182
stopifnot
162183
styler
163184
sublicenses
185+
tcltk
186+
tempfile
164187
testthat
165188
tibble
166189
tidyverse
190+
trailingOnly
167191
travis
168192
tryCatch
169193
ubuntu
194+
uninitialised
195+
unlist
196+
unname
170197
usethis
171198
usr
172199
walthert

inst/hooks/exported/readme-rmd-rendered

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/testthat/test-cache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test_that("CLI API works for roxygenize", {
5353
suffix = "-cache-success.R",
5454
env = paste0("R_CACHE_ROOTPATH=", R.cache_root),
5555
msg = "You can silent this",
56-
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION")),
56+
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION-no-deps.dcf")),
5757
file_transformer = function(x) {
5858
git2r::init()
5959
x

tests/testthat/test-conda.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,37 @@ if (!on_cran()) {
66
})
77

88
test_that("can use pre-commit", {
9-
tempdir <- local_test_setup(quiet = FALSE)
9+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
1010
expect_message(
11-
use_precommit(open = FALSE, force = TRUE, root = tempdir),
11+
use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir),
1212
"to get the latest"
1313
)
1414
expect_message(
15-
use_precommit(open = FALSE, force = FALSE, root = tempdir),
15+
use_precommit(open = FALSE, force = FALSE, install_hooks = FALSE, root = tempdir),
1616
"There is already "
1717
)
1818
})
1919

2020
test_that("fails early if repo is not a git repo ", {
21-
tempdir <- local_test_setup(git = FALSE, quiet = FALSE)
21+
tempdir <- local_test_setup(git = FALSE, quiet = FALSE, install_hooks = FALSE)
2222

2323
expect_error(
24-
use_precommit(open = FALSE, root = tempdir),
24+
use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir),
2525
"is not a git repo"
2626
)
2727
})
2828

2929
test_that("can use custom config file ", {
30-
tempdir1 <- local_test_setup()
31-
tempdir2 <- local_test_setup()
30+
tempdir1 <- local_test_setup(install_hooks = FALSE)
31+
tempdir2 <- local_test_setup(install_hooks = FALSE)
3232

3333
path_custom <- fs::path(tempdir2, "some-precommit.yaml")
3434
new_text <- "# 4js93"
3535
readLines(system.file("pre-commit-config-proj.yaml", package = "precommit")) %>%
3636
c(new_text) %>%
3737
writeLines(path_custom)
3838
git2r::init(tempdir1)
39-
use_precommit(config_source = path_custom, open = FALSE, force = TRUE, root = tempdir1)
39+
use_precommit(config_source = path_custom, open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir1)
4040
config <- readLines(fs::path(tempdir1, ".pre-commit-config.yaml"))
4141
expect_equal(
4242
config[length(config)],
@@ -45,33 +45,33 @@ if (!on_cran()) {
4545
})
4646

4747
test_that("existing hooks are recognized", {
48-
tempdir <- local_test_setup(quiet = FALSE)
48+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
4949
withr::with_dir(tempdir, {
5050
git2r::init()
5151
usethis::proj_set(".")
5252
usethis::use_readme_rmd(open = FALSE)
5353

5454
# usethis hook is removed without error
5555
expect_message(
56-
use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."),
56+
use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."),
5757
"Removed the render-README hook,"
5858
)
5959
writeLines(letters, ".git/hooks/pre-commit")
6060
expect_error(
61-
use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."),
61+
use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."),
6262
"existing hooks installed"
6363
)
6464

6565
# tolerate other hook scripts in migration mode
6666
expect_message(
67-
use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, root = "."),
67+
use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."),
6868
"Running in migration"
6969
)
7070

7171
# can also remove other hooks
7272
writeLines(letters, ".git/hooks/pre-commit")
7373
expect_message(
74-
use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, root = "."),
74+
use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."),
7575
"Sucessfully installed"
7676
)
7777
})
@@ -80,7 +80,7 @@ if (!on_cran()) {
8080

8181
test_that("Can uninstall pre-commit (repo scope)", {
8282
# with all files there
83-
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE)
83+
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE)
8484
expect_message(
8585
uninstall_precommit(scope = "repo", root = tempdir),
8686
"Uninstalled pre-commit from repo scope.*"
@@ -94,7 +94,7 @@ if (!on_cran()) {
9494
)
9595

9696
# when there is no pre-commit.yaml anymore
97-
suppressMessages(use_precommit(open = FALSE, force = TRUE, root = tempdir))
97+
suppressMessages(use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir))
9898
fs::file_delete(fs::path(tempdir, ".pre-commit-config.yaml"))
9999
expect_message(
100100
uninstall_precommit(scope = "repo", root = tempdir),
@@ -104,13 +104,13 @@ if (!on_cran()) {
104104

105105
test_that("Can uninstall (userly)", {
106106
if (not_conda()) {
107-
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE)
107+
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE)
108108
expect_error(
109109
uninstall_precommit(scope = "user", ask = "none", root = tempdir),
110110
"installed with conda"
111111
)
112112
} else {
113-
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE)
113+
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE)
114114
expect_message(
115115
uninstall_precommit(scope = "user", ask = "none", root = tempdir),
116116
"Removed pre-commit from"
@@ -124,18 +124,18 @@ if (!on_cran()) {
124124

125125
test_that("use_precommit fails when no user installation is found", {
126126
skip_if(not_conda())
127-
expect_error(use_precommit(open = FALSE, root = tempdir), "installed on your system")
127+
expect_error(use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir), "installed on your system")
128128
})
129129

130130
test_that("can install pre-commit with remote config", {
131131
if (!not_conda()) {
132132
expect_error(install_precommit(), NA)
133133
}
134-
tempdir <- local_test_setup(quiet = FALSE)
134+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
135135
expect_message(
136136
use_precommit(
137137
example_remote_config(),
138-
open = FALSE, force = TRUE, root = tempdir
138+
open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir
139139
),
140140
"to get the latest"
141141
)
@@ -145,14 +145,14 @@ if (!on_cran()) {
145145
if (!not_conda()) {
146146
expect_message(install_precommit(), "already installed")
147147
}
148-
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE)
148+
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE)
149149
withr::with_dir(
150150
tempdir,
151151
{
152152
withr::defer(call_and_capture("git", "config --unset-all core.hooksPath"))
153153
call_and_capture("git", "config core.hooksPath .githooks")
154154
expect_error(
155-
use_precommit(open = FALSE, force = TRUE, root = tempdir),
155+
use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir),
156156
"stdout: [ERROR] Cowardly refusing to install hooks with `core.hooksPath` set.",
157157
fixed = TRUE
158158
)

tests/testthat/test-hook-roxygenize.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ test_that("fails gratefully when not installed package is required according to
138138
)
139139
mockery::stub(roxygenize_with_cache, "diff_requires_run_roxygenize", TRUE)
140140
expect_error(
141-
roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize")),
141+
suppressWarnings(
142+
roxygenize_with_cache(list(getwd()), dirs = dirs_R.cache("roxygenize"))
143+
),
142144
"Please add the package"
143145
)
144146
})

0 commit comments

Comments
 (0)