From df0dcc5e0c9d861424eb3b1f3d4a62a91a5f62ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Sun, 15 Dec 2024 12:56:56 +0100 Subject: [PATCH] scan_deps(): recognize rsconnect directory (#418) * scan_deps() renv.lock means we need renv * scan_deps(): recognize rsconnect directory --- R/scan-deps.R | 22 +++++++++++++++++-- tests/testthat/_snaps/scan-deps.md | 15 +++++++------ .../fixtures/scan/project-2/rsconnect/keepme | 0 tests/testthat/test-scan-deps.R | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 tests/testthat/fixtures/scan/project-2/rsconnect/keepme diff --git a/R/scan-deps.R b/R/scan-deps.R index a0e1c839..9ba2d412 100644 --- a/R/scan-deps.R +++ b/R/scan-deps.R @@ -96,6 +96,9 @@ scan_deps <- function(path = ".") { if (file.exists(file.path(path, "renv.lock"))) { paths <- c(paths, "renv.lock") } + if (file.exists(file.path(path, "rsconnect"))) { + paths <- c(paths, "rsconnect") + } full_paths <- normalizePath(file.path(path, paths)) deps_list <- lapply(full_paths, scan_path_deps) deps <- do.call("rbind", c(list(scan_deps_df()), deps_list)) @@ -189,7 +192,11 @@ re_r_dep <- function() { } scan_path_deps <- function(path) { - code <- readBin(path, "raw", file.size(path)) + code <- if (file.info(path)$isdir) { + NULL + } else { + readBin(path, "raw", file.size(path)) + } # check if already known, set path should_cache <- scan_path_should_cache(path) @@ -257,7 +264,9 @@ scan_path_should_cache <- function(paths) { "_bookdown.yml", "_pkgdown.yml", "_quarto.yml", - "renv.lock" + "renv.lock", + "rsconnect", + NULL ) } @@ -275,6 +284,7 @@ scan_path_deps_do <- function(code, path) { "_pkgdown.yml" = scan_path_deps_do_pkgdown(code, path), "_quarto.yml" = scan_path_deps_do_quarto(code, path), "renv.lock" = scan_path_deps_do_renv_lock(code, path), + "rsconnect" = scan_path_deps_do_rsconnect(code, path), stop("Cannot parse ", ext, " file for dependencies, internal error") ) } @@ -1021,4 +1031,12 @@ scan_path_deps_do_renv_lock <- function(code, path) { ) } +scan_path_deps_do_rsconnect <- function(code, path) { + scan_deps_df( + path = path, + package = "rsconnect", + code = NA_character_ + ) +} + # ------------------------------------------------------------------------- diff --git a/tests/testthat/_snaps/scan-deps.md b/tests/testthat/_snaps/scan-deps.md index c0a6db53..14cbcb3d 100644 --- a/tests/testthat/_snaps/scan-deps.md +++ b/tests/testthat/_snaps/scan-deps.md @@ -381,15 +381,16 @@ 1 fixtures/scan/NAMESPACE stats stats * prod stats 1 1 1 2 fixtures/scan/NAMESPACE utils utils * prod utils 1 1 1 -# scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock} +# scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock,rsconnect} Code scan_deps(project)[] Output - # A data frame: 3 x 9 - path ref package version type code start_row start_column start_byte - - 1 bookdown/_bookdown.yml bookdown bookdown * prod 1 1 1 - 2 _pkgdown.yml pkgdown pkgdown * prod 1 1 1 - 3 renv.lock renv renv * prod 1 1 1 + # A data frame: 4 x 9 + path ref package version type code start_row start_column start_byte + + 1 bookdown/_bookdown.yml bookdown bookdown * prod 1 1 1 + 2 _pkgdown.yml pkgdown pkgdown * prod 1 1 1 + 3 renv.lock renv renv * prod 1 1 1 + 4 rsconnect rsconnect rsconnect * prod 1 1 1 diff --git a/tests/testthat/fixtures/scan/project-2/rsconnect/keepme b/tests/testthat/fixtures/scan/project-2/rsconnect/keepme new file mode 100644 index 00000000..e69de29b diff --git a/tests/testthat/test-scan-deps.R b/tests/testthat/test-scan-deps.R index 5daaa120..7e7fe799 100644 --- a/tests/testthat/test-scan-deps.R +++ b/tests/testthat/test-scan-deps.R @@ -484,7 +484,7 @@ test_that("scan_path_deps_do_namespace", { }) }) -test_that("scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock}", { +test_that("scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock,rsconnect}", { local_reproducible_output(width = 500) project <- test_path("fixtures/scan/project-2") expect_snapshot({