-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Added product environment check helpers #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,8 +194,28 @@ endpoint_does_not_exist <- function(res) { | |
!("code" %in% names(httr::content(res, as = "parsed"))) | ||
} | ||
|
||
get_product <- function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions that we wanna export as part of the package namespace (i.e. loaded when running
#' Get available runtimes on server
#'
#' Get a table showing available versions of R, Python, Quarto, and Tensorflow
#' on the Connect server.
#'
#' @param client A `Connect` object.
#' @param runtimes Optional. A character vector of runtimes to include. Must be
#' some combination of `"r"`, `"python"`, `"quarto"`, and `"tensorflow"`. Quarto
#' is only supported on Connect >= 2021.08.0, and Tensorflow is only supported
#' on Connect >= 2024.03.0.
#' @return A tibble with columns for `runtime`, `version`, and `cluster_name`
#' and `image_name`. Cluster name and image name are only meaningful on Connect
#' instances running off-host execution.
#'
#' @examples
#' \dontrun{
#' library(connectapi)
#' client <- connect()
#' get_runtimes(client, runtimes = c("r", "python", "tensorflow"))
#' }
#'
#' @export These won't need much. In fact, they could be listed on the same documentation page. To do that, you'd follow the pattern with #' @return
#'
#' - `get_jobs()`: A data frame with a row representing each job.
#' - `get_job_list()`: A list with each element representing a job. and the end of the documentation includes the #' @rdname get_jobs
#' @export Other functions can then include just those same two lines as their documentation to show the same help page when queried (e.g. That explanation is a little terse — let me know if you have any other questions! |
||
posit_product <- Sys.getenv("POSIT_PRODUCT") | ||
if (posit_product != "") { | ||
return(posit_product) | ||
} | ||
Sys.getenv("RSTUDIO_PRODUCT") | ||
} | ||
|
||
# Returns `TRUE` if we're running locally (no product env var set), | ||
# else `FALSE`. | ||
is_local <- function() { | ||
get_product() == "" | ||
} | ||
|
||
# Returns `TRUE` if we're running on Connect as determined by the | ||
# `RSTUDIO_PRODUCT` env var, else `FALSE`. | ||
# `POSIT_PRODUCT` or `RSTUDIO_PRODUCT` env var, else `FALSE`. | ||
on_connect <- function() { | ||
Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT" | ||
get_product() == "CONNECT" | ||
} | ||
|
||
# Returns `TRUE` if we're running on Workbench as determined by the | ||
# `POSIT_PRODUCT` or `RSTUDIO_PRODUCT` env var, else `FALSE`. | ||
on_workbench <- function() { | ||
get_product() == "WORKBENCH" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the first time
on_connect()
will be exported, it's actually "new" and not updated.