Skip to content

Commit

Permalink
preserve renv.lock (not the renv directory) for renv projects (#927)
Browse files Browse the repository at this point in the history
* preserve renv.lock (not the renv directory) for renv projects

fixes #926

* named lockfile argument
  • Loading branch information
aronatkins authored Jul 25, 2023
1 parent a5db832 commit 4c55d69
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rsconnect (development version)

* Deploying from an renv project includes the `renv.lock` in the bundle. A
manifest created for an renv project references the `renv.lock` in the
`manifest.json`. (#926)

# rsconnect 1.0.1

* `deployDoc()` includes `.Rprofile`, `requirements.txt` and `renv.lock` when
Expand Down
5 changes: 3 additions & 2 deletions R/bundlePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ computePackageDependencies <- function(bundleDir,
# responsibility to install any other packages you need
taskStart(quiet, "Capturing R dependencies from renv.lock")
deps <- parseRenvDependencies(bundleDir)
# Once we've captured the deps, we can remove renv from the bundle
removeRenv(bundleDir)
# Once we've captured the deps, we can remove the renv directory
# from the bundle (retaining the renv.lock).
removeRenv(bundleDir, lockfile = FALSE)
} else if (isFALSE(getOption("rsconnect.packrat", FALSE))) {
taskStart(quiet, "Capturing R dependencies with renv")
# TODO: give user option to choose between implicit and explicit
Expand Down
8 changes: 5 additions & 3 deletions R/bundlePackageRenv.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ parseRenvDependencies <- function(bundleDir, snapshot = FALSE) {

# Generate a library from the lockfile
lib_dir <- dirCreate(file.path(bundleDir, "renv_library"))
renv::restore(bundleDir, library = lib_dir, prompt = FALSE)
defer(unlink(lib_dir, recursive = TRUE))
renv::restore(bundleDir, library = lib_dir, prompt = FALSE)

deps$description <- lapply(
deps$Package,
Expand Down Expand Up @@ -136,7 +136,9 @@ renvLockFile <- function(bundleDir) {
file.path(bundleDir, "renv.lock")
}

removeRenv <- function(path) {
unlink(renvLockFile(path))
removeRenv <- function(path, lockfile = TRUE) {
if (lockfile) {
unlink(renvLockFile(path))
}
unlink(file.path(path, "renv"), recursive = TRUE)
}
4 changes: 2 additions & 2 deletions tests/testthat/test-bundlePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test_that("can capture deps from renv lockfile", {
expect_named(pkgs$foreign, c("Source", "Repository", "description"))
expect_named(pkgs$MASS, c("Source", "Repository", "description"))

# No renv lockfile or directory left behind
expect_equal(list.files(app_dir), "foo.R")
# No renv directory left behind, but the renv.lock is preserved.
expect_equal(list.files(app_dir), c("foo.R", "renv.lock"))
})

# -------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-writeManifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ makeManifest <- function(appDir, appPrimaryDoc = NULL, ...) {
manifestJson
}

test_that("renv.lock is included for renv projects", {
withr::local_options(renv.verbose = FALSE)

app_dir <- local_temp_app(list(app.R = "library(foreign); library(MASS)"))
renv::snapshot(app_dir, prompt = FALSE)

manifest <- makeManifest(app_dir)
# note: we don't see an .Rprofile here because we only renv::snapshot and
# do not fully create an renv project.
expect_named(manifest$files, c("app.R", "renv.lock"))
})

test_that("renv.lock is not included for non-renv projects", {
withr::local_options(renv.verbose = FALSE)

app_dir <- local_temp_app(list(app.R = "library(foreign); library(MASS)"))

manifest <- makeManifest(app_dir)
expect_named(manifest$files, c("app.R"))
})

test_that("Rmd with reticulate as a dependency includes python in the manifest", {
skip_on_cran()
skip_if_not_installed("reticulate")
Expand Down

0 comments on commit 4c55d69

Please sign in to comment.