Skip to content

Commit

Permalink
deployDoc includes requirements.txt and renv.lock (#920)
Browse files Browse the repository at this point in the history
* deployDoc includes requirements.txt and renv.lock

fixes #919

* whitespace lint

* vectorized existence
  • Loading branch information
aronatkins authored Jul 19, 2023
1 parent 647bb4d commit d9692d4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 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)

* `deployDoc()` includes `.Rprofile`, `requirements.txt` and `renv.lock` when
deploying `.Rmd` or `.qmd`. These additional files are not included with
rendered HTML documents. (#919)

* Explicit renv dependencies are preserved. (#916)

# rsconnect 1.0.0
Expand Down
12 changes: 10 additions & 2 deletions R/deployDoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ standardizeSingleDocDeployment <- function(path,

appFiles <- c(basename(path), resources$path)

if (file.exists(file.path(dirname(path), ".Rprofile"))) {
appFiles <- c(appFiles, ".Rprofile")
if (isRenderedFile(path)) {
candidates <- c(".Rprofile", "renv.lock", "requirements.txt")
exists <- file.exists(file.path(dirname(path), candidates))
appFiles <- c(appFiles, candidates[exists])
}

appFiles
} else {
# deploy just the file
Expand All @@ -78,3 +81,8 @@ isStaticFile <- function(path) {
ext <- tolower(tools::file_ext(path))
ext %in% c("rmd", "qmd", "html", "htm")
}

isRenderedFile <- function(path) {
ext <- tolower(tools::file_ext(path))
ext %in% c("rmd", "qmd")
}
49 changes: 49 additions & 0 deletions tests/testthat/test-deployDoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,55 @@ test_that("regular rmd deploys .Rprofile, if present", {
expect_equal(doc$appFiles, c("foo.Rmd", ".Rprofile"))
})

test_that("regular rmd deploys requirements.txt, if present", {
dir <- local_temp_app(list(
"foo.Rmd" = "",
"requirements.txt" = ""
))

doc <- standardizeSingleDocDeployment(file.path(dir, "foo.Rmd"), quiet = TRUE)
expect_equal(doc$appFiles, c("foo.Rmd", "requirements.txt"))
})

test_that("regular rmd deploys renv.lock, if present", {
dir <- local_temp_app(list(
"foo.Rmd" = "",
"renv.lock" = ""
))

doc <- standardizeSingleDocDeployment(file.path(dir, "foo.Rmd"), quiet = TRUE)
expect_equal(doc$appFiles, c("foo.Rmd", "renv.lock"))
})

test_that("regular html does not deploy .Rprofile", {
dir <- local_temp_app(list(
"foo.html" = "",
".Rprofile" = ""
))

doc <- standardizeSingleDocDeployment(file.path(dir, "foo.html"), quiet = TRUE)
expect_equal(doc$appFiles, c("foo.html"))
})

test_that("regular html does not deploy requirements.txt", {
dir <- local_temp_app(list(
"foo.html" = "",
"requirements.txt" = ""
))

doc <- standardizeSingleDocDeployment(file.path(dir, "foo.html"), quiet = TRUE)
expect_equal(doc$appFiles, c("foo.html"))
})

test_that("regular html does not deploy renv.lock", {
dir <- local_temp_app(list(
"foo.html" = "",
"renv.lock" = ""
))

doc <- standardizeSingleDocDeployment(file.path(dir, "foo.html"), quiet = TRUE)
expect_equal(doc$appFiles, c("foo.html"))
})

test_that("other types deploy that one file", {
dir <- local_temp_app(list("foo.R" = ""))
Expand Down

0 comments on commit d9692d4

Please sign in to comment.