Skip to content

Commit

Permalink
Merge pull request #81 from mlverse/updates
Browse files Browse the repository at this point in the history
Adds way to handle Posit Connect
  • Loading branch information
edgararuiz authored Dec 4, 2023
2 parents 502d447 + 71f8ba0 commit 966977a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pysparklyr
Title: Provides a 'PySpark' Back-End for the 'sparklyr' Package
Version: 0.1.1.9004
Version: 0.1.1.9005
Authors@R: c(
person("Edgar", "Ruiz", , "[email protected]", role = c("aut", "cre")),
person(given = "Posit Software, PBC", role = c("cph", "fnd"))
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This way, the R user will not have to run `install_databricks()`/

* Instead of simply warning that `RETICULATE_PYTHON` is set, it will now un-set
the variable. This allows `pysparklyr` to select the correct Python environment.
It will output a console message to the user when the variable is un-set. (#65)
It will output a console message to the user when the variable is un-set. (#65).
Because of how Posit Connect manages `reticulate` Python environments, `pysparklyr`
will force the use of the Python environment under that particular published
content's `RETICULATE_PYTHON`.

* Adds enhanced RStudio Snippet for Databricks connections. It will automatically
check the cluster's version by pooling the Databricks REST API with the cluster's
Expand Down
6 changes: 5 additions & 1 deletion R/python-use-envname.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use_envname <- function(
ask_if_not_installed = interactive()
) {

reticulate_python_check(ignore_reticulate_python)
ret_python <- reticulate_python_check(ignore_reticulate_python)

if(ret_python != "") {
return(set_names(ret_python, "env_var"))
}

if(!is.null(envname)) {
return(set_names(envname, "argument"))
Expand Down
2 changes: 1 addition & 1 deletion R/sparklyr-spark-connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ build_user_agent <- function() {
return(env_var)
}

if (Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") {
if (current_product_connect()) {
product <- "posit-connect"
}

Expand Down
25 changes: 19 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ NULL

reticulate_python_check <- function(ignore = FALSE, unset = TRUE, message = TRUE) {

in_connect <- Sys.getenv("R_CONFIG_ACTIVE") == "rsconnect"

if (ignore | in_connect) {
return(invisible)
if (ignore) {
return("")
}

out <- ""

env_var <- Sys.getenv("RETICULATE_PYTHON", unset = NA)
if (!is.na(env_var)) {

if(current_product_connect() && !is.na(env_var)){
out <- env_var
}

if (!is.na(env_var) && out == "") {
if (unset) {
Sys.unsetenv("RETICULATE_PYTHON")
if (message) {
Expand Down Expand Up @@ -51,7 +56,7 @@ reticulate_python_check <- function(ignore = FALSE, unset = TRUE, message = TRUE
}
}
}
invisible()
out
}

check_arg_supported <- function(x, msg = NULL) {
Expand Down Expand Up @@ -85,3 +90,11 @@ cli_internal_abort <- function(msg) {
cli_abort(msg, call = NULL)
cli_end()
}

current_product_connect <- function() {
out <- FALSE
if (Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") {
out <- TRUE
}
out
}

0 comments on commit 966977a

Please sign in to comment.