diff --git a/NEWS.md b/NEWS.md index 16753cc80..c7e459cbb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,13 +32,17 @@ - `as.character()` method for `python.builtin.bytes` gains a `nul` argument, allowing for convenient handling of embedded NULs in the string. (#1652) - + - New `as.character()` method for `python.builtin.str` with support for handling embedded NULs in strings. (#1653) - Reticulate will now use the `RETICULATE_VIRTUALENV_ROOT` environment variable when determining where to resolve virtual environments. (#1657) +- Fixed an error where opening a Python subprocess in Positron on Windows + resulted in "OSError: [WinError 6] The handle is invalid." + (#1658, posit-dev/positron#4457) + # reticulate 1.38.0 - Python Exceptions converted to R conditions are now R lists instead diff --git a/R/config.R b/R/config.R index a458b2ab2..947ee3c71 100644 --- a/R/config.R +++ b/R/config.R @@ -1005,6 +1005,10 @@ is_rstudio_desktop <- function() { identical(version$mode, "desktop") } +is_positron <- function() { + exists(".ps.ark.version", envir = globalenv()) +} + clean_version <- function(version) { gsub("\\.$", "", gsub("[A-Za-z_+].*$", "", version)) } diff --git a/R/package.R b/R/package.R index a1ea2f25c..f8b398b06 100644 --- a/R/package.R +++ b/R/package.R @@ -63,7 +63,7 @@ ensure_python_initialized <- function(required_module = NULL) { remap_output_streams() set_knitr_python_stdout_hook() - if (is_windows() && identical(.Platform$GUI, "RStudio")) + if (is_windows() && ( is_rstudio() || is_positron() )) import("rpytools.subprocess")$patch_subprocess_Popen() # generate 'R' helper object diff --git a/R/repl.R b/R/repl.R index adeb2141d..bbc8ad29a 100644 --- a/R/repl.R +++ b/R/repl.R @@ -92,7 +92,7 @@ repl_python <- function( ensure_python_initialized() if (is.null(input) && - Sys.getenv("POSITRON") == "1" && + is_positron() && exists(".ps.reticulate_open", inherits = TRUE)) { eval(call(".ps.reticulate_open"))