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

Simplify handling of Suggested dependencies #1394

Merged
merged 15 commits into from
Jun 7, 2023
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# renv 0.18.0 (UNRELEASED)

* `dependencies()` now marks `Suggested` packages listed in `DESCRIPTION` files
kevinushey marked this conversation as resolved.
Show resolved Hide resolved
as development dependencies regardless of whether or not they're in
"package" project.

* If `renv::snapshot()` finds missing packages, a new prompt allows you to
install them before continuing (#1198).

Expand Down
32 changes: 22 additions & 10 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@
#' * `"fatal"`: errors are fatal and stop execution.
#' * `"ignored"`: errors are ignored and not reported to the user.
#'
#' @param dev Boolean; include 'development' dependencies as well? That is,
#' packages which may be required during development but are unlikely to be
#' required during runtime for your project. By default, only runtime
#' dependencies are returned.
#' @param dev Boolean; include development dependencies? These packages are
#' typically required when developing the project, but not when running it
#' (i.e. you want them installed when humans are working on the project but
#' not when computers are deploying it).
#'
#' Development dependencies include packages listed in the `Suggests` field
#' of a `DESCRIPTION` found in the project root, and roxygen2 or devtools if
#' their use is implied by other project metadata.
#'
#' @return An \R `data.frame` of discovered dependencies, mapping inferred
#' package names to the files in which they were discovered. Note that the
Expand Down Expand Up @@ -536,25 +540,34 @@ renv_dependencies_discover_description <- function(path,
sprintf("Config/renv/profiles/%s/dependencies", profile)

fields <- c(fields, "Suggests", profile_field)
type <- renv_description_type(desc = dcf)
proj_desc <- TRUE

} else {
type <- "unknown"
proj_desc <- FALSE
}

data <- map(
fields,
renv_dependencies_discover_description_impl,
dcf = dcf,
path = path,
type = type
proj_desc = proj_desc
)

# Infer a dependency on roxygen2 and devtools if RoxygenNote present
if (!is.null(dcf$RoxygenNote)) {
data <- c(
data,
list(renv_dependencies_list(path, c("roxygen2", "devtools"), dev = TRUE))
hadley marked this conversation as resolved.
Show resolved Hide resolved
)
}


bind(data)

}

renv_dependencies_discover_description_impl <- function(dcf, field, path, type) {
renv_dependencies_discover_description_impl <- function(dcf, field, path, proj_desc) {

# read field
contents <- dcf[[field]]
Expand All @@ -579,13 +592,12 @@ renv_dependencies_discover_description_impl <- function(dcf, field, path, type)
return(list())

# create dependency list
dev <- field == "Suggests" && type != "package"
renv_dependencies_list(
path,
extract_chr(matches, 2L),
extract_chr(matches, 3L),
extract_chr(matches, 4L),
dev
dev = proj_desc && field == "Suggests"
)

}
Expand Down
13 changes: 0 additions & 13 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ renv_project_remotes <- function(project, fields = NULL) {
ignored <- renv_project_ignored_packages(project = project)
specs <- specs[setdiff(names(specs), c("R", ignored))]

# if any Roxygen fields are included,
# infer a dependency on roxygen2 and devtools
desc <- renv_description_read(descpath)
if (any(grepl("^Roxygen", names(desc)))) {
for (package in c("devtools", "roxygen2")) {
if (!package %in% ignored) {
specs[[package]] <-
specs[[package]] %||%
renv_dependencies_list(descpath, package, dev = TRUE)
}
}
}

# now, try to resolve the packages
records <- enumerate(specs, function(package, spec) {

Expand Down
12 changes: 8 additions & 4 deletions man/dependencies.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions tests/testthat/test-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,24 @@ test_that("no warnings are produced when crawling dependencies", {

})

test_that("Suggests are dev. deps for non-package projects", {
test_that("Suggests are dev. deps for all projects", {

renv_tests_scope()

expected <- data.frame(
Package = "bread",
Dev = TRUE,
stringsAsFactors = FALSE
)

writeLines(c("Type: Project", "Suggests: bread"), con = "DESCRIPTION")
deps <- dependencies(dev = TRUE)
expect_true(nrow(deps) == 1)
expect_true(deps$Package == "bread")
expect_true(deps$Dev)
})
expect_equal(deps[c("Package", "Dev")], expected)
hadley marked this conversation as resolved.
Show resolved Hide resolved

test_that("Suggests are _not_ dev. deps for package projects", {
renv_tests_scope()
writeLines(c("Type: Package", "Suggests: bread"), con = "DESCRIPTION")
deps <- dependencies(dev = FALSE)
expect_true(nrow(deps) == 1)
expect_true(deps$Package == "bread")
expect_false(deps$Dev)
deps <- dependencies(dev = TRUE)
expect_equal(deps[c("Package", "Dev")], expected)

})

test_that("packages referenced by modules::import() are discovered", {
Expand Down