diff --git a/R/setup.R b/R/setup.R index cae293ce..4f9d7a12 100644 --- a/R/setup.R +++ b/R/setup.R @@ -13,8 +13,9 @@ rextendr_setup <- function(path = ".", cur_version = NULL) { } update_rextendr_version(path, cur_version = cur_version) + update_sys_reqs(path) - invisible(is_first) + invisible(TRUE) } update_rextendr_version <- function(path, cur_version = NULL) { @@ -27,11 +28,31 @@ update_rextendr_version <- function(path, cur_version = NULL) { "You have {.str {cur}} but you need {.str {prev}}" )) } else if (!identical(cur, prev)) { - cli::cli_alert_info("Setting {.var Config/rextendr/version} to {.str {cur}}") - desc::desc_set(`Config/rextendr/version` = cur, file = path) + update_description("Config/rextendr/version", cur) } } +update_sys_reqs <- function(path) { + cur <- "Cargo (rustc package manager)" + prev <- stringi::stri_trim_both(desc::desc_get("SystemRequirements", path)[[1]]) + + if (is.na(prev)) { + update_description("SystemRequirements", cur) + } else if (!identical(cur, prev)) { + cli::cli_ul( + c( + "The SystemRequirements field in the {.file DESCRIPTION} file is already set.", + "Please update it manually if needed." + ) + ) + } +} + +update_description <- function(field, value) { + cli::cli_alert_info("Setting {.var {field}} to {.str {value}} in the {.file DESCRIPTION} file.") + desc::desc_set(field, value) +} + rextendr_version <- function(path = ".") { stringi::stri_trim_both(desc::desc_get("Config/rextendr/version", path)[[1]]) } diff --git a/R/use_extendr.R b/R/use_extendr.R index 1902772c..24426115 100644 --- a/R/use_extendr.R +++ b/R/use_extendr.R @@ -146,7 +146,6 @@ use_extendr <- function(path = ".", cli::cli_alert_success("Finished configuring {.pkg extendr} for package {.pkg {pkg_name}}.") cli::cli_ul( c( - "Please update the system requirement in {.file DESCRIPTION} file.", "Please run {.fun rextendr::document} for changes to take effect." ) ) diff --git a/tests/testthat/_snaps/use_extendr.md b/tests/testthat/_snaps/use_extendr.md index b44292e5..b7ad3004 100644 --- a/tests/testthat/_snaps/use_extendr.md +++ b/tests/testthat/_snaps/use_extendr.md @@ -4,7 +4,8 @@ use_extendr() Message i First time using rextendr. Upgrading automatically... - i Setting `Config/rextendr/version` to "0.3.1.9000" + i Setting `Config/rextendr/version` to "0.3.1.9000" in the 'DESCRIPTION' file. + i Setting `SystemRequirements` to "Cargo (rustc package manager)" in the 'DESCRIPTION' file. v Creating 'src/rust/src'. v Writing 'src/entrypoint.c' v Writing 'src/Makevars' @@ -17,9 +18,28 @@ v Writing 'src/testpkg-win.def' v Writing 'R/extendr-wrappers.R' v Finished configuring extendr for package testpkg. - * Please update the system requirement in 'DESCRIPTION' file. * Please run `rextendr::document()` for changes to take effect. +--- + + Code + cat_file("DESCRIPTION") + Output + Package: testpkg + Title: What the Package Does (One Line, Title Case) + Version: 0.0.0.9000 + Authors@R: + person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), + comment = c(ORCID = "YOUR-ORCID-ID")) + Description: What the package does (one paragraph). + License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a + license + Encoding: UTF-8 + Roxygen: list(markdown = TRUE) + RoxygenNote: 7.2.3 + Config/rextendr/version: 0.3.1.9000 + SystemRequirements: Cargo (rustc package manager) + --- Code diff --git a/tests/testthat/test-use_extendr.R b/tests/testthat/test-use_extendr.R index cc473c3d..27536aaf 100644 --- a/tests/testthat/test-use_extendr.R +++ b/tests/testthat/test-use_extendr.R @@ -15,6 +15,7 @@ test_that("use_extendr() sets up extendr files correctly", { expect_true(dir.exists(file.path("src", "rust"))) expect_true(dir.exists(file.path("src", "rust", "src"))) + expect_snapshot(cat_file("DESCRIPTION")) expect_snapshot(cat_file("R", "extendr-wrappers.R")) expect_snapshot(cat_file("src", "Makevars")) expect_snapshot(cat_file("src", "Makevars.win")) @@ -46,7 +47,6 @@ test_that("use_extendr() does not set up packages with pre-existing src", { expect_false(created) }) - test_that("use_extendr() does not set up packages with pre-existing wrappers", { skip_if_not_installed("usethis") @@ -151,3 +151,21 @@ test_that("R/ folder is created when not present", { # expect no error expect_rextendr_error(use_extendr(), regexp = NA) }) + +test_that("Message if the SystemRequirements field is already set.", { + skip_if_not_installed("usethis") + + path <- local_package("testpkg") + sys_req <- "testreq" + + desc::desc_set("SystemRequirements", sys_req) + + withr::local_options(usethis.quiet = FALSE) + expect_message( + created <- use_extendr(), + "Please update it manually if needed" + ) + + expect_true(created) + expect_equal(desc::desc_get("SystemRequirements")[[1]], sys_req) +})