Skip to content

Commit 4ba4a29

Browse files
support argument root for deps in desc
1 parent fc42b7e commit 4ba4a29

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

inst/hooks/exported/deps-in-desc.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
"Ensure all dependencies of the form pkg::fun are in DESCRIPTION
44
Usage:
5-
deps-in-desc [--allow_private_imports] <files>...
5+
deps-in-desc [--allow_private_imports] [--root=<root_>]<files>...
66
77
Options:
88
--allow_private_imports Whether or not to allow the use of ::: on imported functions.
9+
--root=<root_> Path relative to the git root that contains the R package root [default: .].
10+
911
" -> doc
1012
pre_installed <- c(
1113
"base", "boot", "class", "cluster", "codetools", "compiler",
@@ -16,6 +18,8 @@ pre_installed <- c(
1618
)
1719

1820
arguments <- docopt::docopt(doc)
21+
arguments$files <- normalizePath(arguments$files) # because working directory changes to root
22+
setwd(normalizePath(arguments$root))
1923
deps_in_desc <- function(file, arguments) {
2024
if (basename(file) == "README.Rmd") {
2125
# is .Rbuildignored, dependencies irrelevant
@@ -70,6 +74,7 @@ deps_in_desc <- function(file, arguments) {
7074
}
7175
out
7276
}
77+
7378
out <- lapply(arguments$files, deps_in_desc, arguments = arguments)
7479
if (!all(unlist(out))) {
7580
stop("Dependency check failed", call. = FALSE)

tests/testthat/test-hooks.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ run_test("deps-in-desc",
213213
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
214214
)
215215

216+
# in sub directory with wrong root
217+
run_test("deps-in-desc",
218+
suffix = "-fail.R", std_err = "contains a file",
219+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
220+
)
221+
222+
# in sub directory with correct root
223+
run_test("deps-in-desc",
224+
cmd_args = "--root=rpkg",
225+
suffix = "-fail.R", std_err = "Dependency check failed",
226+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
227+
)
228+
229+
# in sub directory with correct root
230+
run_test("deps-in-desc",
231+
cmd_args = "--root=rpkg",
232+
suffix = "-success.R", std_err = NULL,
233+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
234+
)
235+
216236
# with :::
217237
run_test("deps-in-desc",
218238
"deps-in-desc-dot3",

vignettes/available-hooks.Rmd

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,32 @@ roclets you specified in `DESCRIPTION`.
226226
## `deps-in-desc`
227227

228228
Checks if packages used with the `pkgname::fun()` syntax are listed in
229-
your DESCRIPTION file. Note that `README.Rmd` is never checked. Flag
230-
`allow_private_imports` lets the user specify that private imports into
231-
the package namespace are tolerable, e.g. `somepkg:::x()`. Flag not set
232-
by default, i.e. the hook will fail if such a call is found.
229+
your DESCRIPTION file. Note that `README.Rmd` is never checked.
233230

231+
**Arguments**
232+
233+
- Flag `allow_private_imports` lets the user specify that private
234+
imports into the package namespace are tolerable, e.g.
235+
`somepkg:::x()`. Flag not set by default, i.e. the hook will fail if
236+
such a call is found.
237+
238+
```{=html}
239+
<!-- -->
240+
```
234241
id: deps-in-desc
235242
args: [--allow_private_imports]
236243

244+
- Argument `root` specifies the directory in the git repo that
245+
contains the R package. Defaults to `.` since for most R package git
246+
repos, the git and R package root coincide. Added in version
247+
0.3.2.9000.
248+
249+
```{=html}
250+
<!-- -->
251+
```
252+
id: deps-in-desc
253+
args: [--root=<R package root>]
254+
237255
This hook does not modify the file `DESCRIPTION` because the user should
238256
decide for each package if it should go to `Imports:` or `Suggests:`,
239257
which can be done easily with `usethis::use_package()`.

0 commit comments

Comments
 (0)