rstudio / rsconnect

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

handle unknown and Local package source #1006

Closed aronatkins closed 9 months ago

aronatkins commented 9 months ago

This shifts from using a local "Source" with whatever "Repository" comes from renv to using NA for both. An error now occurs because the package did not come from a well-known repository.

fixes #1004

# Create a new project and launch a separate RStudio session.
usethis::create_project("~/Desktop/mixed-content")

# In that new project ...
unlink("R", recursive = TRUE)
writeLines(c(
    "library(shiny)",
    "shinyApp('single file Shiny deploy', function(input, output) {})"
), "app.R")

renv::init()
renv::install(c("rsconnect"), prompt = FALSE)
renv::install("~/Downloads/shiny_1.7.5.tar.gz", repos = NULL, type = "source", prompt = FALSE)
renv::snapshot(prompt = FALSE)

rsconnect::writeManifest()
jsonlite::fromJSON("manifest.json")$packages$shiny[c("Source","Repository")]
#> $Source
#> [1] "Local"
#>
#> $Repository
#> [1] "CRAN"

renv::install("rstudio/rsconnect@aron-issue-1004", prompt = FALSE)

# restart R session ...

rsconnect::writeManifest()
#> ℹ Capturing R dependencies from renv.lock
#> ✔ Found 32 dependencies
#> Error in `createAppManifest()` at rstudio-rsconnect-8856765/R/writeManifest.R:61:2:
#> ! All packages must be installed from a reproducible location.
#> ✖ Can't re-install packages installed from source: shiny.
#> ℹ See `rsconnect::appDependencies()` for more details.
#> Run `rlang::last_trace()` to see where the error occurred.
aronatkins commented 9 months ago

I've pushed a second commit, which attempts to search for packages that have "Local" or "unknown" renv source.

rsconnect::writeManifest()
#> ℹ Capturing R dependencies from renv.lock
#> ✔ Found 32 dependencies
jsonlite::fromJSON("manifest.json")$packages$shiny[c("Source","Repository")]
#> $Source
#> [1] "CRAN"
#> 
#> $Repository
#> [1] "https://packagemanager.posit.co/cran/latest"

@hadley - Which option do you feel we should use? Force folks to adjust their renv project to install from a repository, or search the repositories for those packages on their behalf?

hadley commented 9 months ago

I think this approach breaks the feature that I originally wanted — if you have a locally installed version of a CRAN (like we often do when developing packages) you'd get the CRAN package, which is likely what you wanted. I'm not sure how to balance that against the needs of this user.

aronatkins commented 9 months ago

@hadley - The first commit does what you want, then -- it errs on local packages. I'm happy to merge just that and discard the second commit (which searches).

@slodge-work - Could you confirm that you are comfortable installing your package from a repository rather than source?

slodge-work commented 9 months ago

@aronatkins There's a suggestion by @kevinushey to look at options(renv.records.override = list(devtools = list(...))) and that's given me other ideas of things to play with.

Thanks both for looking at this - it's really helped me understand what's happening here.

I do appreciate our build system and local CRAN are not completely following perfect R/CRAN workflows, and I confirm I'm comfortable to try our own local solutions/workarounds for the new challenge :+1:

aronatkins commented 9 months ago

@hadley - I've rolled back the search; this PR now treats "Local" as "unknown" and produces an error, which is the result you wanted, I think. See the original PR comment for the error message.

toph-allen commented 9 months ago

QA

Roughly following the instructions in the PR comment, except substituting the main branch for renv::install("rstudio/rsconnect@aron-issue-1004", prompt = FALSE):

> renv::install("rstudio/rsconnect", prompt = FALSE)
# Downloading packages -------------------------------------------------------
- Downloading rsconnect from GitHub ...         OK [499.3 Kb in 0.69s]
Successfully downloaded 1 package in 0.83 seconds.

The following package(s) will be installed:
- rsconnect [rstudio/rsconnect@main]
These packages will be installed into "~/Local/RStudio/projects/2023-10-03-rsconnect-qa/mixed-content/renv/library/R-4.3/aarch64-apple-darwin20".

# Installing packages --------------------------------------------------------
- Installing rsconnect ...                      OK [built from source and cached in 2.7s]
Successfully installed 1 package in 2.7 seconds.

The following loaded package(s) have been updated:
- rsconnect
Restart your R session to use the new versions.

Restarting R session...

- Project '~/Local/RStudio/projects/2023-10-03-rsconnect-qa/mixed-content' loaded. [renv 1.0.1; sha: 5dc2fc9]
> rsconnect::writeManifest()
ℹ Capturing R dependencies from renv.lock
✔ Found 32 dependencies
Error in `createAppManifest()` at rstudio-rsconnect-bf42453/R/writeManifest.R:61:2:
! All packages must be installed from a reproducible location.
✖ Can't re-install packages installed from source: shiny.
ℹ See `rsconnect::appDependencies()` for more details.
Run `rlang::last_trace()` to see where the error occurred.

From the discussion (treating "Local" as "unknown" and emitting an error), it looks like this is the expected outcome, so… consider this verified.