-
Notifications
You must be signed in to change notification settings - Fork 85
Support renv profiles #1296
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
base: main
Are you sure you want to change the base?
Support renv profiles #1296
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,10 @@ snapshotRenvDependencies <- function( | |
| progress = FALSE | ||
| ) | ||
| renv::snapshot(bundleDir, packages = deps$Package, prompt = FALSE) | ||
| # renv::snapshot() respects RENV_PATHS_LOCKFILE and renv profiles, so the | ||
| # lockfile may have been written to a non-standard location. Copy it into the | ||
| # bundle dir so parseRenvDependencies() can find it. | ||
| ensureRenvLockFile(bundleDir) | ||
| defer(removeRenv(bundleDir)) | ||
|
|
||
| parseRenvDependencies(bundleDir, snapshot = TRUE) | ||
|
|
@@ -172,6 +176,41 @@ renvLockFile <- function(bundleDir) { | |
| file.path(bundleDir, "renv.lock") | ||
| } | ||
|
|
||
| # Ensure the renv lockfile is at the standard bundle location. | ||
| # If found at a custom location (via RENV_PATHS_LOCKFILE or renv profiles), | ||
| # copies it into bundleDir/renv.lock, overwriting any stale lockfile. | ||
| # Returns TRUE if the lockfile is available, FALSE otherwise. | ||
| ensureRenvLockFile <- function(bundleDir) { | ||
| standard <- renvLockFile(bundleDir) | ||
| resolved <- renv::paths$lockfile(project = bundleDir) | ||
|
|
||
| # If the resolved file exists, and is different from the standard location, | ||
| # copy it to the standard location. | ||
| if (file.exists(resolved)) { | ||
| # Normalize to avoid self-copy (e.g., /var vs /private/var on macOS) | ||
| if ( | ||
| normalizePath(resolved, mustWork = FALSE) != | ||
| normalizePath(standard, mustWork = FALSE) | ||
| ) { | ||
| if (file.exists(standard)) { | ||
| cli::cli_warn(c( | ||
| "Using lockfile at {.path {resolved}} instead of {.path {standard}}.", | ||
| i = "The lockfile in the project root may be outdated.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I run this function twice, I'm going to get this warning, even though the files themselves are identical. Should we be checking the contents of the files instead?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add checking the contents, but running user-exported commands in rsconnect, this path should not alter someone's app directory (so this shouldn't happen in practice unless someone calls |
||
| i = "Remove it to silence this warning." | ||
| )) | ||
| } | ||
| if (!file.copy(resolved, standard, overwrite = TRUE)) { | ||
| cli::cli_abort( | ||
| "Failed to copy lockfile from {.path {resolved}} to {.path {standard}}." | ||
| ) | ||
| } | ||
| } | ||
| return(TRUE) | ||
| } | ||
|
|
||
| file.exists(standard) | ||
| } | ||
|
|
||
| removeRenv <- function(path, lockfile = TRUE) { | ||
| if (lockfile) { | ||
| unlink(renvLockFile(path)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to copy it at all? Why can't we use it where it lives? It's a little odd to me that this function would alter the contents of the current working directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that's confusing about this is that it's actually not copying it into the working directory, but actually into the temporary directory the rsconnect creates and copies files over to a temporary directory
rsconnect/R/appDependencies.R
Lines 130 to 135 in c704931
rsconnect/R/bundle.R
Lines 1 to 12 in c704931
But thinking about this more, we might need to make sure that we can handle relative paths in
RENV_PATHS_LOCKFILEsince when this is run inside of the temp bundle dir, those might not work (e.g. ifRENV_PATHS_LOCKFILE="../renv.lock"and the app is at/home/jonkeane/Documents/myapp/subdir/, my lock file is at/home/jonkeane/Documents/myapp/renv.lockwe don't want the target of this copy to be/tmp/.../renv.lock