From 89eb4aa3f9e5d7665e7994745146499412a13e8d Mon Sep 17 00:00:00 2001 From: kbvernon Date: Tue, 19 Nov 2024 17:00:42 -0700 Subject: [PATCH 1/3] internal functions and tests --- R/find_extendr.R | 65 ++++++++++++++++++++++++++++++ tests/testthat/test-find_extendr.R | 33 +++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 R/find_extendr.R create mode 100644 tests/testthat/test-find_extendr.R diff --git a/R/find_extendr.R b/R/find_extendr.R new file mode 100644 index 00000000..dcd5b490 --- /dev/null +++ b/R/find_extendr.R @@ -0,0 +1,65 @@ +#' Get path to Rust crate in R package directory +#' +#' @param path character scalar, the R package directory +#' @param error_call call scalar, from rlang docs: "the defused call with which +#' the function running in the frame was invoked" +#' +#' @return character scalar, path to Rust crate +#' +#' @examples +#' \dontrun{ +#' find_extendr_crate() +#' } +find_extendr_crate <- function( + path = ".", + error_call = rlang::caller_call()) { + check_character(path, call = error_call, class = "rextendr_error") + + rust_folder <- rprojroot::find_package_root_file( + "src", "rust", + path = path + ) + + if (!dir.exists(rust_folder)) { + cli::cli_abort( + "Could not find Rust crate at {.path rust_folder}.", + call = error_call, + class = "rextendr_error" + ) + } + + rust_folder +} + +#' Get path to Cargo manifest in R package directory +#' +#' @param path character scalar, the R package directory +#' @param error_call call scalar, from rlang docs: "the defused call with which +#' the function running in the frame was invoked" +#' +#' @return character scalar, path to Cargo manifest +#' +#' @examples +#' \dontrun{ +#' find_extendr_manifest() +#' } +find_extendr_manifest <- function( + path = ".", + error_call = rlang::caller_call()) { + check_character(path, call = error_call, class = "rextendr_error") + + manifest_path <- rprojroot::find_package_root_file( + "src", "rust", "Cargo.toml", + path = path + ) + + if (!file.exists(manifest_path)) { + cli::cli_abort( + "Could not find Cargo manifest at {.path manifest_path}.", + call = error_call, + class = "rextendr_error" + ) + } + + manifest_path +} diff --git a/tests/testthat/test-find_extendr.R b/tests/testthat/test-find_extendr.R new file mode 100644 index 00000000..d8a85177 --- /dev/null +++ b/tests/testthat/test-find_extendr.R @@ -0,0 +1,33 @@ +test_that("find_extendr_crate() returns path to Rust crate", { + skip_if_not_installed("usethis") + + path <- local_package("testpkg") + + # capture setup messages + withr::local_options(usethis.quiet = FALSE) + + expect_error(find_extendr_crate(), class = "rextendr_error") + + use_extendr(path, quiet = TRUE) + + rust_folder <- find_extendr_crate() + + expect_true(dir.exists(rust_folder)) +}) + +test_that("find_extendr_manifest() returns path to Cargo manifest", { + skip_if_not_installed("usethis") + + path <- local_package("testpkg") + + # capture setup messages + withr::local_options(usethis.quiet = FALSE) + + expect_error(find_extendr_manifest(), class = "rextendr_error") + + use_extendr(path, quiet = TRUE) + + manifest_path <- find_extendr_manifest() + + expect_true(file.exists(manifest_path)) +}) From 0a6216a784b365b30954c6842617131a02b50947 Mon Sep 17 00:00:00 2001 From: Kenneth Blake Vernon <53311626+kbvernon@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:21:17 -0700 Subject: [PATCH 2/3] Update R/find_extendr.R Co-authored-by: Josiah Parry --- R/find_extendr.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/find_extendr.R b/R/find_extendr.R index dcd5b490..d6bcdaa7 100644 --- a/R/find_extendr.R +++ b/R/find_extendr.R @@ -9,6 +9,8 @@ #' @examples #' \dontrun{ #' find_extendr_crate() +#' @keywords internal +#' @noRd #' } find_extendr_crate <- function( path = ".", From 2de41fcdb33377555638bc42dbb997e605599052 Mon Sep 17 00:00:00 2001 From: Kenneth Blake Vernon <53311626+kbvernon@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:21:27 -0700 Subject: [PATCH 3/3] Update R/find_extendr.R Co-authored-by: Josiah Parry --- R/find_extendr.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/find_extendr.R b/R/find_extendr.R index d6bcdaa7..f423b5bc 100644 --- a/R/find_extendr.R +++ b/R/find_extendr.R @@ -44,6 +44,8 @@ find_extendr_crate <- function( #' @examples #' \dontrun{ #' find_extendr_manifest() +#' @keywords internal +#' @noRd #' } find_extendr_manifest <- function( path = ".",