Skip to content

Commit

Permalink
fix handling of named remotes (closes #2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Dec 6, 2024
1 parent 26f7790 commit b990d1d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# renv 1.1.0 (UNRELEASED)

* Fixed an issue where `renv::init()` could fail when using named remotes
in a DESCRIPTION file's `Remotes:` field. (#2055)

* Fixed an issue where ignore rules of the form `!*.*` were not parsed
and handled correctly during dependency discovery. (#2052)

Expand Down
15 changes: 14 additions & 1 deletion R/hydrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,21 @@ hydrate <- function(packages = NULL,
# also consider remotes; if a package is listed within Remotes,
# then choose to install that package instead of linking it
filter <- function(specs, remotes) {
packages <- map_chr(remotes, `[[`, "Package")

packages <- enum_chr(remotes, function(package, remote) {

# if we have a package name, use it
if (is.character(package) && nzchar(package))
return(package)

# otherwise, resolve the remote and use the package field
remote <- resolve(remote)
remote[["Package"]]

})

keep(specs, packages)

}

remotes <- renv_project_remotes(project, filter = filter, resolve = TRUE)
Expand Down
5 changes: 5 additions & 0 deletions R/remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ renv_remotes_resolve <- function(spec, latest = FALSE) {
if (is.null(spec) || is.list(spec))
return(spec)

# check for a package name prefix and remove it
regexps <- .standard_regexps()
pattern <- sprintf("^%s=", regexps$valid_package_name)
spec <- sub(pattern, "", spec)

# remove a trailing slash
# https://github.com/rstudio/renv/issues/1135
spec <- gsub("/+$", "", spec, perl = TRUE)
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,19 @@ test_that("init() respects Remotes in a project DESCRIPTION file", {
init()
expect_true(renv_package_installed("skeleton"))
})

test_that("a project using named remotes can be initialized", {
project <- renv_tests_scope()

contents <- heredoc('
Depends:
toast
Remotes:
toast=toast
')
writeLines(contents, con = "DESCRIPTION")

init(settings = list(snapshot.type = "explicit"))
expect_true(renv_package_installed("toast"))

})

0 comments on commit b990d1d

Please # to comment.