Skip to content

Commit 94508ef

Browse files
committed
Add option for installing from release archive
1 parent ede72e3 commit 94508ef

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

R/install.R

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#' The URL should point to the tarball (`.tar.gz.` file) itself, e.g.,
5252
#' `release_url="https://github.com/stan-dev/cmdstan/releases/download/v2.25.0/cmdstan-2.25.0.tar.gz"`.
5353
#' If both `version` and `release_url` are specified then `version` will be used.
54+
#' @param release_file (string) A file path to a CmdStan release tar.gz file
55+
#' downloaded from the releases page: <https://github.com/stan-dev/cmdstan/releases>.
56+
#' For example: `release_file=""./cmdstan-2.33.1.tar.gz"`. If `release_file` is
57+
#' specified then both `release_url` and `version` will be ignored.
5458
#' @param cpp_options (list) Any makefile flags/variables to be written to
5559
#' the `make/local` file. For example, `list("CXX" = "clang++")` will force
5660
#' the use of clang for compilation.
@@ -82,6 +86,7 @@ install_cmdstan <- function(dir = NULL,
8286
timeout = 1200,
8387
version = NULL,
8488
release_url = NULL,
89+
release_file = NULL,
8590
cpp_options = list(),
8691
check_toolchain = TRUE,
8792
wsl = FALSE) {
@@ -118,7 +123,15 @@ install_cmdstan <- function(dir = NULL,
118123
dir <- repair_path(dir)
119124
assert_dir_exists(dir, access = "rwx")
120125
}
121-
if (!is.null(version)) {
126+
if (!is.null(release_file)) {
127+
if (!is.null(release_url) || !is.null(version)) {
128+
warning("release_file and release_url/version shouldn't both be specified!",
129+
"\nrelease_url/version will be ignored.", call. = FALSE)
130+
}
131+
132+
release_url <- release_file
133+
}
134+
if (!is.null(version) && is.null(release_file)) {
122135
if (!is.null(release_url)) {
123136
warning("version and release_url shouldn't both be specified!",
124137
"\nrelease_url will be ignored.", call. = FALSE)
@@ -155,18 +168,22 @@ install_cmdstan <- function(dir = NULL,
155168
if (!check_install_dir(dir_cmdstan, overwrite)) {
156169
return(invisible(NULL))
157170
}
158-
tar_downloaded <- download_with_retries(download_url, dest_file, quiet = quiet)
159-
if (inherits(tar_downloaded, "try-error")) {
160-
error_msg <- paste("Download of CmdStan failed with error:",
161-
attr(tar_downloaded, "condition")$message)
162-
if (!is.null(version)) {
163-
error_msg <- paste0(error_msg, "\nPlease check if the supplied version number is valid.")
164-
} else if (!is.null(release_url)) {
165-
error_msg <- paste0(error_msg, "\nPlease check if the supplied release URL is valid.")
171+
if (is.null(release_file)) {
172+
tar_downloaded <- download_with_retries(download_url, dest_file, quiet = quiet)
173+
if (inherits(tar_downloaded, "try-error")) {
174+
error_msg <- paste("Download of CmdStan failed with error:",
175+
attr(tar_downloaded, "condition")$message)
176+
if (!is.null(version)) {
177+
error_msg <- paste0(error_msg, "\nPlease check if the supplied version number is valid.")
178+
} else if (!is.null(release_url)) {
179+
error_msg <- paste0(error_msg, "\nPlease check if the supplied release URL is valid.")
180+
}
181+
stop(error_msg, call. = FALSE)
166182
}
167-
stop(error_msg, call. = FALSE)
183+
message("* Download complete")
184+
} else {
185+
file.copy(release_file, dest_file)
168186
}
169-
message("* Download complete")
170187
message("* Unpacking archive...")
171188
if (wsl) {
172189
# Significantly faster to use WSL to untar the downloaded archive, as there are
@@ -762,7 +779,7 @@ cmdstan_arch_suffix <- function(version = NULL) {
762779
} else {
763780
arch <- R.version$arch
764781
}
765-
782+
766783
if (any(grepl(arch, c("x86_64", "i686")))) {
767784
return(NULL)
768785
}

man/install_cmdstan.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-install.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,28 @@ test_that("Download failures return error message", {
247247
"GitHub download of release list failed with error: cannot open URL 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'")
248248
})
249249

250+
test_that("Install from release file works", {
251+
if (getRversion() < '3.5.0') {
252+
dir <- tempdir()
253+
} else {
254+
dir <- tempdir(check = TRUE)
255+
}
256+
257+
destfile = file.path(dir, "cmdstan-2.33.1.tar.gz")
258+
259+
download_with_retries(
260+
"https://github.com/stan-dev/cmdstan/releases/download/v2.33.1/cmdstan-2.33.1.tar.gz",
261+
destfile)
262+
263+
expect_message(
264+
expect_output(
265+
install_cmdstan(dir = dir, cores = 2, quiet = FALSE, overwrite = TRUE,
266+
release_file = destfile,
267+
wsl = os_is_wsl()),
268+
"Compiling, linking C++ code",
269+
fixed = TRUE
270+
),
271+
"CmdStan path set",
272+
fixed = TRUE
273+
)
274+
})

0 commit comments

Comments
 (0)