From 438184cdbb010868b368799b367e3df2a97a1d68 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Mon, 4 Dec 2023 09:27:06 -0600 Subject: [PATCH 1/2] Setting RETICULATE_PYTHON as the Python env if the env var is set, and if inside Connect --- R/python-use-envname.R | 6 +++++- R/sparklyr-spark-connect.R | 2 +- R/utils.R | 25 +++++++++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/R/python-use-envname.R b/R/python-use-envname.R index 2a99660..1600685 100644 --- a/R/python-use-envname.R +++ b/R/python-use-envname.R @@ -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")) diff --git a/R/sparklyr-spark-connect.R b/R/sparklyr-spark-connect.R index 8af8890..371da9e 100644 --- a/R/sparklyr-spark-connect.R +++ b/R/sparklyr-spark-connect.R @@ -187,7 +187,7 @@ build_user_agent <- function() { return(env_var) } - if (Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") { + if (current_product_connect()) { product <- "posit-connect" } diff --git a/R/utils.R b/R/utils.R index 96b27dc..d355c4a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) { @@ -51,7 +56,7 @@ reticulate_python_check <- function(ignore = FALSE, unset = TRUE, message = TRUE } } } - invisible() + out } check_arg_supported <- function(x, msg = NULL) { @@ -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 +} From 71f8ba0fa4465959bbfc2c50b421a7fefaadb1e9 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Mon, 4 Dec 2023 09:30:52 -0600 Subject: [PATCH 2/2] Version bump, updates NEWS --- DESCRIPTION | 2 +- NEWS.md | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 453c542..265376b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "edgar@posit.co", role = c("aut", "cre")), person(given = "Posit Software, PBC", role = c("cph", "fnd")) diff --git a/NEWS.md b/NEWS.md index 857d568..44ee9de 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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