Skip to content

Commit c8d6e76

Browse files
Merge pull request #432 from lorenzwalthert/issue-429
Allow a root for deps-in-desc
2 parents c03d3e1 + 83914bd commit c8d6e76

File tree

5 files changed

+60
-9
lines changed

5 files changed

+60
-9
lines changed

.github/workflows/hook-tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
}
8989
# avoid build-time deps
9090
options(install.packages.compile.from.source = "never")
91-
renv::install(c('testthat', 'devtools', 'git2r'))
91+
renv::install(c('testthat', 'pkgload', 'git2r'))
9292
# some testing infrastructure we need is in R/testing.R
9393
renv::install(getwd())
9494
shell: Rscript {0}
@@ -101,7 +101,7 @@ jobs:
101101
shell: Rscript {0}
102102
- name: Test
103103
run: |
104-
devtools::load_all()
104+
pkgload::load_all()
105105
testthat::test_file(
106106
"tests/testthat/test-hooks.R",
107107
reporter = testthat::MultiReporter$new(list(

R/testing.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ run_test_impl <- function(path_executable,
9494
file_transformer,
9595
env,
9696
expect_success) {
97-
tempdir <- fs::dir_create(fs::file_temp())
97+
# ensure cannonical /private/var/... not /var/... on macOS
98+
tempdir <- fs::path(normalizePath((fs::dir_create(fs::file_temp()))))
9899
copy_artifacts(artifacts, tempdir)
99100
# if name set use this, otherwise put in root
100101
path_candidate_temp <- fs::path(tempdir, names(path_candidate))

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: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,35 @@ 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+
file_transformer = function(files) {
220+
fs::path_abs(fs::file_move(files, "rpkg"))
221+
},
222+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
223+
)
224+
225+
# in sub directory with correct root
226+
run_test("deps-in-desc",
227+
cmd_args = "--root=rpkg",
228+
suffix = "-fail.R", std_err = "Dependency check failed",
229+
file_transformer = function(files) {
230+
fs::path_abs(fs::file_move(files, "rpkg"))
231+
},
232+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
233+
)
234+
235+
# in sub directory with correct root
236+
run_test("deps-in-desc",
237+
cmd_args = "--root=rpkg",
238+
suffix = "-success.R", std_err = NULL,
239+
file_transformer = function(files) {
240+
fs::path_abs(fs::file_move(files, "rpkg"))
241+
},
242+
artifacts = c("rpkg/DESCRIPTION" = test_path("in/DESCRIPTION"))
243+
)
244+
216245
# with :::
217246
run_test("deps-in-desc",
218247
"deps-in-desc-dot3",
@@ -237,7 +266,7 @@ run_test("deps-in-desc",
237266
run_test("deps-in-desc",
238267
"deps-in-desc",
239268
suffix = "-fail.Rmd", std_err = "Dependency check failed",
240-
std_out = "in file `deps-in-desc-fail.Rmd`",
269+
std_out = "deps-in-desc-fail.Rmd`: ttyzp",
241270
artifacts = c("DESCRIPTION" = test_path("in/DESCRIPTION"))
242271
)
243272

vignettes/available-hooks.Rmd

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,30 @@ 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.
230+
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+
<!-- -->
233239

234240
id: deps-in-desc
235241
args: [--allow_private_imports]
236242

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

0 commit comments

Comments
 (0)