From dc4feb88be9f8f6ad8e6bfd8c49c39cd896a89b0 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 4 Sep 2024 17:10:27 -0400 Subject: [PATCH 1/2] patch subprocess Popen when running on Windows under Positron --- R/config.R | 4 ++++ R/package.R | 2 +- R/repl.R | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) 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")) From e92d3a0196dbe018e779ba3e5201d22e71355f4e Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 4 Sep 2024 17:26:06 -0400 Subject: [PATCH 2/2] add NEWS --- NEWS.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 301686c57..70f06e052 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,10 +32,14 @@ - `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) +- 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