Skip to content

Commit

Permalink
Merge pull request #866 from stan-dev/install-release-file
Browse files Browse the repository at this point in the history
Add option for installing from release archive
  • Loading branch information
jgabry authored Oct 17, 2023
2 parents ede72e3 + 94508ef commit 5bd7ef3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
41 changes: 29 additions & 12 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#' The URL should point to the tarball (`.tar.gz.` file) itself, e.g.,
#' `release_url="https://github.com/stan-dev/cmdstan/releases/download/v2.25.0/cmdstan-2.25.0.tar.gz"`.
#' If both `version` and `release_url` are specified then `version` will be used.
#' @param release_file (string) A file path to a CmdStan release tar.gz file
#' downloaded from the releases page: <https://github.com/stan-dev/cmdstan/releases>.
#' For example: `release_file=""./cmdstan-2.33.1.tar.gz"`. If `release_file` is
#' specified then both `release_url` and `version` will be ignored.
#' @param cpp_options (list) Any makefile flags/variables to be written to
#' the `make/local` file. For example, `list("CXX" = "clang++")` will force
#' the use of clang for compilation.
Expand Down Expand Up @@ -82,6 +86,7 @@ install_cmdstan <- function(dir = NULL,
timeout = 1200,
version = NULL,
release_url = NULL,
release_file = NULL,
cpp_options = list(),
check_toolchain = TRUE,
wsl = FALSE) {
Expand Down Expand Up @@ -118,7 +123,15 @@ install_cmdstan <- function(dir = NULL,
dir <- repair_path(dir)
assert_dir_exists(dir, access = "rwx")
}
if (!is.null(version)) {
if (!is.null(release_file)) {
if (!is.null(release_url) || !is.null(version)) {
warning("release_file and release_url/version shouldn't both be specified!",
"\nrelease_url/version will be ignored.", call. = FALSE)
}

release_url <- release_file
}
if (!is.null(version) && is.null(release_file)) {
if (!is.null(release_url)) {
warning("version and release_url shouldn't both be specified!",
"\nrelease_url will be ignored.", call. = FALSE)
Expand Down Expand Up @@ -155,18 +168,22 @@ install_cmdstan <- function(dir = NULL,
if (!check_install_dir(dir_cmdstan, overwrite)) {
return(invisible(NULL))
}
tar_downloaded <- download_with_retries(download_url, dest_file, quiet = quiet)
if (inherits(tar_downloaded, "try-error")) {
error_msg <- paste("Download of CmdStan failed with error:",
attr(tar_downloaded, "condition")$message)
if (!is.null(version)) {
error_msg <- paste0(error_msg, "\nPlease check if the supplied version number is valid.")
} else if (!is.null(release_url)) {
error_msg <- paste0(error_msg, "\nPlease check if the supplied release URL is valid.")
if (is.null(release_file)) {
tar_downloaded <- download_with_retries(download_url, dest_file, quiet = quiet)
if (inherits(tar_downloaded, "try-error")) {
error_msg <- paste("Download of CmdStan failed with error:",
attr(tar_downloaded, "condition")$message)
if (!is.null(version)) {
error_msg <- paste0(error_msg, "\nPlease check if the supplied version number is valid.")
} else if (!is.null(release_url)) {
error_msg <- paste0(error_msg, "\nPlease check if the supplied release URL is valid.")
}
stop(error_msg, call. = FALSE)
}
stop(error_msg, call. = FALSE)
message("* Download complete")
} else {
file.copy(release_file, dest_file)
}
message("* Download complete")
message("* Unpacking archive...")
if (wsl) {
# Significantly faster to use WSL to untar the downloaded archive, as there are
Expand Down Expand Up @@ -762,7 +779,7 @@ cmdstan_arch_suffix <- function(version = NULL) {
} else {
arch <- R.version$arch
}

if (any(grepl(arch, c("x86_64", "i686")))) {
return(NULL)
}
Expand Down
6 changes: 6 additions & 0 deletions man/install_cmdstan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions tests/testthat/test-install.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,28 @@ test_that("Download failures return error message", {
"GitHub download of release list failed with error: cannot open URL 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'")
})

test_that("Install from release file works", {
if (getRversion() < '3.5.0') {
dir <- tempdir()
} else {
dir <- tempdir(check = TRUE)
}

destfile = file.path(dir, "cmdstan-2.33.1.tar.gz")

download_with_retries(
"https://github.com/stan-dev/cmdstan/releases/download/v2.33.1/cmdstan-2.33.1.tar.gz",
destfile)

expect_message(
expect_output(
install_cmdstan(dir = dir, cores = 2, quiet = FALSE, overwrite = TRUE,
release_file = destfile,
wsl = os_is_wsl()),
"Compiling, linking C++ code",
fixed = TRUE
),
"CmdStan path set",
fixed = TRUE
)
})

0 comments on commit 5bd7ef3

Please sign in to comment.