From 040acf52bfd09541505962897b55538c8e781be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Sun, 15 Dec 2024 12:36:09 +0100 Subject: [PATCH 1/2] scan_deps(): bookdown, pkgdown, quarto (#410) * scan_deps(): bookdown, pkgdown, quarto * scan_deps(): .rmarkdown support --- R/scan-deps.R | 3 +++ tests/testthat/_snaps/unix/scan-deps.md | 24 ++++++++++--------- .../fixtures/scan/project-1/index.Rmarkdown | 11 +++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/fixtures/scan/project-1/index.Rmarkdown diff --git a/R/scan-deps.R b/R/scan-deps.R index e841869d..5e814222 100644 --- a/R/scan-deps.R +++ b/R/scan-deps.R @@ -109,6 +109,8 @@ scan_deps_pattern <- function() { "[.]r$", "[.]Rmd$", "[.]rmd$", + "[.]rmarkdown", + "[.]Rmarkdown", "[.]qmd$", "^_bookdown[.]yml$", "^_quarto[.]yml$", @@ -261,6 +263,7 @@ scan_path_deps_do <- function(code, path) { ext, ".r" = scan_path_deps_do_r(code, path), ".qmd" = , + ".rmarkdown" = , ".rmd" = scan_path_deps_do_rmd(code, path), "DESCRIPTION" = scan_path_deps_do_dsc(code, path), "NAMESPACE" = scan_path_deps_do_namespace(code, path), diff --git a/tests/testthat/_snaps/unix/scan-deps.md b/tests/testthat/_snaps/unix/scan-deps.md index 1b718566..b8be090f 100644 --- a/tests/testthat/_snaps/unix/scan-deps.md +++ b/tests/testthat/_snaps/unix/scan-deps.md @@ -3,15 +3,17 @@ Code scan_deps(project)[] Output - # A data frame: 6 x 9 - path ref package version type code start_row start_column start_byte - - 1 R/code.R CD CD * prod CD::pkg 4 1 26 - 2 R/code.R AB AB * prod library(AB) 1 1 1 - 3 R/code.R BC BC * prod require(BC) 2 1 13 - 4 doc.qmd pkgload pkgload * prod pkgload::load_all 12 1 174 - 5 index.Rmd ST ST * prod ST::fun 10 1 97 - 6 index.Rmd RS RS * prod library(RS) 9 1 85 + # A data frame: 8 x 9 + path ref package version type code start_row start_column start_byte + + 1 R/code.R CD CD * prod CD::pkg 4 1 26 + 2 R/code.R AB AB * prod library(AB) 1 1 1 + 3 R/code.R BC BC * prod require(BC) 2 1 13 + 4 doc.qmd pkgload pkgload * prod pkgload::load_all 12 1 174 + 5 index.Rmarkdown ST ST * prod ST::fun 10 1 97 + 6 index.Rmarkdown RS RS * prod library(RS) 9 1 85 + 7 index.Rmd ST ST * prod ST::fun 10 1 97 + 8 index.Rmd RS RS * prod library(RS) 9 1 85 --- @@ -23,8 +25,8 @@ + AB @ R/code.R + BC @ R/code.R + CD @ R/code.R - + RS @ index.Rmd - + ST @ index.Rmd + + RS @ index.Rmarkdown, index.Rmd + + ST @ index.Rmarkdown, index.Rmd + pkgload @ doc.qmd # scan_path_deps diff --git a/tests/testthat/fixtures/scan/project-1/index.Rmarkdown b/tests/testthat/fixtures/scan/project-1/index.Rmarkdown new file mode 100644 index 00000000..87205409 --- /dev/null +++ b/tests/testthat/fixtures/scan/project-1/index.Rmarkdown @@ -0,0 +1,11 @@ +--- +title: pkgdepends +output: + github_document: +always_allow_html: yes +--- + +```{r} +library(RS) +ST::fun() +``` From 0978545c1a8eccba040812f14853e870cc316ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Sun, 15 Dec 2024 12:36:26 +0100 Subject: [PATCH 2/2] scan_deps() renv.lock means we need renv (#412) --- R/scan-deps.R | 15 ++++++++++++++- tests/testthat/_snaps/scan-deps.md | 5 +++-- tests/testthat/fixtures/scan/project-2/renv.lock | 0 tests/testthat/test-scan-deps.R | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/fixtures/scan/project-2/renv.lock diff --git a/R/scan-deps.R b/R/scan-deps.R index 5e814222..a0e1c839 100644 --- a/R/scan-deps.R +++ b/R/scan-deps.R @@ -93,6 +93,9 @@ scan_deps <- function(path = ".") { if (file.exists(file.path(path, "_pkgdown.yml"))) { paths <- c(paths, "_pkgdown.yml") } + if (file.exists(file.path(path, "renv.lock"))) { + paths <- c(paths, "renv.lock") + } 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)) @@ -253,7 +256,8 @@ scan_path_should_cache <- function(paths) { ! basename(paths) %in% c( "_bookdown.yml", "_pkgdown.yml", - "_quarto.yml" + "_quarto.yml", + "renv.lock" ) } @@ -270,6 +274,7 @@ scan_path_deps_do <- function(code, path) { "_bookdown.yml" = scan_path_deps_do_bookdown(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), stop("Cannot parse ", ext, " file for dependencies, internal error") ) } @@ -1008,4 +1013,12 @@ scan_path_deps_do_quarto <- function(code, path) { # Maybe that's too opinionated? } +scan_path_deps_do_renv_lock <- function(code, path) { + scan_deps_df( + path = path, + package = "renv", + code = NA_character_ + ) +} + # ------------------------------------------------------------------------- diff --git a/tests/testthat/_snaps/scan-deps.md b/tests/testthat/_snaps/scan-deps.md index 9a6efac5..c0a6db53 100644 --- a/tests/testthat/_snaps/scan-deps.md +++ b/tests/testthat/_snaps/scan-deps.md @@ -381,14 +381,15 @@ 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} +# scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock} Code scan_deps(project)[] Output - # A data frame: 2 x 9 + # 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 diff --git a/tests/testthat/fixtures/scan/project-2/renv.lock b/tests/testthat/fixtures/scan/project-2/renv.lock new file mode 100644 index 00000000..e69de29b diff --git a/tests/testthat/test-scan-deps.R b/tests/testthat/test-scan-deps.R index fdecc2e1..5daaa120 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}", { +test_that("scan_path_deps_do_{bookdown,pkgdown,quarto,renv_lock}", { local_reproducible_output(width = 500) project <- test_path("fixtures/scan/project-2") expect_snapshot({