rstudio / rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
http://rstudio.github.io/rsconnect/
133 stars 81 forks source link

writeManifest does not work with renv profiles #1041

Open tomjemmett opened 8 months ago

tomjemmett commented 8 months ago

In computePackageDependencies the check for whether an renv.lock file exists only checks for a file in the bundleDir. If you are using renv profiles the check returns FALSE, so it falls back to the case of trying to create a new renv lock file.

It would be nice if writeManifest could accept as an argument the name of an renv profile to use, or automatically detect the currently active renv profile.

Locally, I've monkey-patched renvLockFile to return the path to the profile in use in my specific project. This seems to work and successfully generates the manifest.json file for me

assignInNamespace(
  "renvLockFile",
  \(...) "renv/profiles/dev/renv.lock",
  "rsconnect"
)
aronatkins commented 7 months ago

Background:

When renv has a default profile, it writes the name of that profile to renv/profile. This indicates that the renv/profiles/{NAME}/renv.lock is in use. Alternatively, the RENV_PROFILE environment variable can name the active profile.

rsconnect should consume the renv.lock associated with the active profile.

renv does not appear to have public functions which expose the name of the active profile or lock file.

It has internal functions:

@kevinushey - Do you have thoughts about how to best consume the renv.lock for the active renv profile from rsconnect? Should we rely on renv:::renv_profile_get() as a public interface? Will we always have a project renv.lock (default profile) when there are named renv profiles?

kevinushey commented 7 months ago

renv does not appear to have public functions which expose the name of the active profile or lock file.

There is this:

> Sys.setenv(RENV_PROFILE = "test")
> renv::paths$lockfile()
[1] "/Users/kevin/r/pkg/renv/renv/profiles/test/renv.lock"

Maybe we should create and export lockfile_path(), as a companion to the other existing lockfile functions?

That said, the RENV_PROFILE environment variable is the de-facto source of truth for the active profile.

Will we always have a project renv.lock (default profile) when there are named renv profiles?

It's possible that you could have project-specific lockfiles available without any default lockfile, although that might be rare in theory.