wjones127 commented on code in PR #12849:
URL: https://github.com/apache/arrow/pull/12849#discussion_r849004739
##########
r/R/install-arrow.R:
##########
@@ -137,6 +137,54 @@ reload_arrow <- function() {
}
}
+#' Run download script
+#'
+#' @param tools_dir The `tools/` directory in the package.
+#' @param skip_download Skip doing the actual download?
+#' Note: we only need bash and wget here, not a full compiler suite.
+#' These will often be missing on Windows, but are typically present on other
+#' systems.
+#' @noRd
+run_download_script <- function(tools_dir, skip_download = FALSE) {
+ if (.Platform$OS.type == "windows") {
+ if (!requireNamespace("pkgbuild", quietly = TRUE)) {
+ stop("pkgbuild is required on Windows")
+ }
+ if (!pkgbuild::has_build_tools()) {
+ stop("This script requires bash and wget. Please install Rtools or run
this in WSL.")
+ }
+ # Have build tools available for the rest of this function
+ pkgbuild::local_build_tools()
+ }
+ suppressWarnings(
+ is_wget_available <- system2(
+ "bash", c("-c", "'wget -V'"),
+ stdout = FALSE, stderr = FALSE
+ ) == 0
+ )
+ if (!is_wget_available) {
+ stop("Can't run wget - will not be able to download files")
+ }
+ bash_file <- file.path(tools_dir, "cpp/thirdparty/download_dependencies.sh")
+ if (!file.exists(bash_file)) {
+ stop("Can't find expected download_dependencies.sh file.")
+ }
+ # If you change this path, also need to edit nixlibs.R
+ download_dir <- file.path(tools_dir, "thirdparty_dependencies")
+ dir.create(download_dir)
+
+ if (!skip_download) {
Review Comment:
> Do you mean temporarily redefining the system2 function?
Yes, I mean redefining within the scope of the test, also called mocking. I
think you'd have to use `mockery::stub` and not `testthat::with_mock` or mockr,
since the latter don't work with functions in base. Would look something like
(though I haven't tested this code):
```r
test_that("Prep thirdparty download", {
skip_on_cran()
# Replaces system2 with a function that always returns 0 when called
from run_download_script
mockery::stub(run_download_script, 'system2', 0)
tools_dir <- tempdir()
run_download_script(tools_dir)
})
```
See: https://github.com/r-lib/mockery#examples
This would mean adding mockery as a dev dependency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]