-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added local get_ss3_exe function to resolve gh::gh SAML token issues …
- Loading branch information
1 parent
2120d76
commit cb35a2a
Showing
5 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ Imports: | |
r4ss (== 1.49.3), | ||
randtests, | ||
reshape2, | ||
gh, | ||
rlang | ||
Suggests: | ||
knitr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#' Download the Stock Synthesis (SS3) executable | ||
#' | ||
#' Downloads the SS3 executable according to specified version and the user | ||
#' operating system. | ||
#' | ||
#' @param dir The directory that you would like the executable downloaded to. | ||
#' @param version A character string of the executable version tag to download | ||
#' (e.g.'v3.30.20' or 'v3.30.18'). A list of tags is available at | ||
#' https://github.com/nmfs-ost/ss3-source-code/tags | ||
#' @return A string of the file path to the downloaded executable | ||
#' @author Elizabeth F. Gugliotti | ||
#' @export | ||
#' @import gh | ||
#' @examples | ||
#' \dontrun{ | ||
#' get_ss3_exe() | ||
#' get_ss3_exe(version = "v3.30.18") | ||
#' } | ||
#' @description The `get_ss3_exe()` function uses the `gh` package to get either | ||
#' the latest release (if version = NULL) or the specified version of the Stock | ||
#' Synthesis executable for the appropriate operating system to the directory `dir` | ||
#' (if dir = NULL, then the executable is downloaded to the working directory). | ||
#' To view the version tags available go to | ||
#' https://github.com/nmfs-ost/ss3-source-code/tags | ||
|
||
get_ss3_exe <- function(dir = NULL, version = NULL) { | ||
# Get latest release if version not specified | ||
if (is.null(version)) { | ||
latest_release <- gh::gh("GET /repos/nmfs-ost/ss3-source-code/releases/latest", page = 1, .token = NA_character_) | ||
tag <- latest_release[["tag_name"]] | ||
} else { | ||
# Otherwise get specified version | ||
all_tags <- gh::gh("GET /repos/nmfs-ost/ss3-source-code/tags", .token = NA_character_) | ||
df_tags <- as.data.frame(do.call(rbind, all_tags)) | ||
tags <- unlist(df_tags[["name"]]) | ||
|
||
if (!version %in% tags) { | ||
warning("The version tag that you entered is invalid or not in the right format, | ||
please go to https://github.com/nmfs-ost/ss3-source-code/tags | ||
to get a correct version tag or version tag format") | ||
} else { | ||
tag <- version | ||
} | ||
} | ||
|
||
if (is.null(dir)) { | ||
dir <- getwd() | ||
message("No directory provided, the executable will be downloaded to the working directory") | ||
} | ||
|
||
if (!dir.exists(dir)) { | ||
stop("Directory doesn't exist: ", dir) | ||
} | ||
|
||
#if (.Platform[["OS.type"]] == "windows") { | ||
if(R.version[["os"]] == "mingw32") { | ||
|
||
download_location <- ss3_exe_windows(dir, tag) | ||
|
||
} else if(substr(R.version[["os"]], 1, 6) == "darwin") { | ||
|
||
download_location <- ss3_exe_darwin(dir, tag, R.version[["arch"]]) | ||
} else if(R.version[["os"]] == "linux-gnu") { | ||
|
||
download_location <- ss3_exe_linux(dir, tag) | ||
} else { | ||
|
||
stop("The Stock Synthesis executable is not available for ", R.version[["os"]], ".") # nocov end | ||
} | ||
|
||
return(invisible(download_location)) | ||
} | ||
|
||
|
||
|
||
|
||
#' @rdname get_ss3_exe | ||
#' | ||
#' @param dir Target Directory | ||
#' @param tag Target ss3 Version release | ||
#' | ||
#' @return A string of the file path to the downloaded executable | ||
#' | ||
#' @keywords internal | ||
#' | ||
ss3_exe_windows <- function (dir, tag) { | ||
if (.Platform[["r_arch"]] == "x32") { # nocov start | ||
warning( | ||
"Stock Synthesis binary is not available for 32-bit ", | ||
.Platform[["OS.type"]], "." | ||
) | ||
} else { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss3_win.exe" | ||
) | ||
try_ss <- tryCatch( | ||
suppressWarnings(utils::download.file(url, destfile = file.path(dir, "ss3.exe"), mode = "wb")), | ||
error = function(e) "ss3 name not right for this version, trying ss" | ||
) | ||
|
||
if (try_ss == "ss3 name not right for this version, trying ss") { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss_win.exe" | ||
) | ||
utils::download.file(url, destfile = file.path(dir, "ss3.exe"), mode = "wb") | ||
} | ||
download_location <- file.path(dir, "ss3.exe") | ||
message(paste0( | ||
"The stock synthesis executable for Windows ", tag, " was downloaded to: ", | ||
download_location | ||
)) | ||
|
||
return(invisible(download_location)) | ||
} | ||
} | ||
|
||
|
||
#' @rdname get_ss3_exe | ||
#' | ||
#' @param dir Target Directory | ||
#' @param tag Target ss3 Version release | ||
#' @param arch arch | ||
#' | ||
#' @return A string of the file path to the downloaded executable | ||
#' | ||
#' @keywords internal | ||
#' | ||
ss3_exe_darwin <- function(dir, tag, arch = c("aarch64", "x86_64" )) { | ||
|
||
arch <- match.arg(arch) | ||
|
||
if(arch == "aarch64"){ | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss3_osx_arm64" | ||
) | ||
try_arm64 <- tryCatch( | ||
suppressWarnings(utils::download.file(url, destfile = file.path(dir, "ss3"), mode = "wb")), | ||
error = function(e) "ss3 executable not available for macOS arm64 architecture | ||
computers for versions prior to v.3.30.22.1" | ||
) | ||
|
||
if (try_arm64 == "ss3 executable not available for macOS arm64 architecture computers for | ||
versions prior to v.3.30.22.1") { | ||
print(try_arm64) | ||
} else { | ||
Sys.chmod(paths = file.path(dir, "ss3"), mode = "0700") | ||
download_location <- file.path(dir, "ss3") | ||
message(paste0( | ||
"The stock synthesis executable for Mac ", tag, " was downloaded to: ", | ||
download_location | ||
)) | ||
} | ||
} else if (arch == "x86_64") { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss3_osx" | ||
) | ||
try_ss <- tryCatch( | ||
suppressWarnings(utils::download.file(url, destfile = file.path(dir, "ss3"), mode = "wb")), | ||
error = function(e) "ss3 name not right for this version, trying ss" | ||
) | ||
|
||
if (try_ss == "ss3 name not right for this version, trying ss") { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss_osx" | ||
) | ||
utils::download.file(url, destfile = file.path(dir, "ss3"), mode = "wb") | ||
} | ||
Sys.chmod(paths = file.path(dir, "ss3"), mode = "0700") | ||
download_location <- file.path(dir, "ss3") | ||
message(paste0( | ||
"The stock synthesis executable for Mac ", tag, " was downloaded to: ", | ||
download_location | ||
)) | ||
} | ||
return(invisible(download_location)) | ||
} | ||
|
||
#' @rdname get_ss3_exe | ||
#' | ||
#' @param dir Target Directory | ||
#' @param tag Target ss3 Version release | ||
#' | ||
#' @return A string of the file path to the downloaded executable | ||
#' | ||
#' @keywords internal | ||
#' | ||
ss3_exe_linux <- function(dir, tag) { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss3_linux" | ||
) | ||
try_ss <- tryCatch( | ||
suppressWarnings(utils::download.file(url, destfile = file.path(dir, "ss3"), mode = "wb")), | ||
error = function(e) "ss3 name not right for this version, trying ss" | ||
) | ||
|
||
if (try_ss == "ss3 name not right for this version, trying ss") { | ||
url <- paste0( | ||
"https://github.com/nmfs-ost/ss3-source-code/releases/download/", | ||
tag, "/ss_linux" | ||
) | ||
utils::download.file(url, destfile = file.path(dir, "ss3"), mode = "wb") | ||
} | ||
Sys.chmod(paths = file.path(dir, "ss3"), mode = "0700") | ||
Sys.chmod(paths = dir, mode = "0777") | ||
download_location <- file.path(dir, "ss3") | ||
message(paste0( | ||
"The stock synthesis executable for Linux ", tag, " was downloaded to: ", | ||
download_location | ||
)) | ||
return(invisible(download_location)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters