Skip to content

Commit

Permalink
patch subprocess.Popen on Windows/Rstudio
Browse files Browse the repository at this point in the history
closes #1448
closes #518
closes
  • Loading branch information
t-kalinowski committed Aug 22, 2023
1 parent 083552c commit aa86136
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion NEWS.md
@@ -1,13 +1,16 @@
# reticulate (development version)

- reticulate now exports a `chooseOpsMethod()` method, allowing for Ops dispatch
to more specialized Ops methods defined for Python objects.
to more specialized Ops methods defined for Python objects.

- reticulate now supports casting R data.frames to Pandas data.frames using nullable
data types allowing users to preserve NA's from R atomic vectors. This feature is
opt-in and can be enabled by setting the R option `reticulate.pandas_use_nullable_dtypes`
to `TRUE`. (#1439)

- Fixed issue where Python would raise an exception when opening a subprocess while
running in Rstudio on Windows. (#1448, #518)

- Fixed issue where `virtualenv_create()` would fail to discover a 'virtualenv' module
in the system Python installation on Ubuntu. Reticulate will no longer discover
and attempt to use the `venv` module stub present on Ubuntu systems
Expand Down
3 changes: 3 additions & 0 deletions R/package.R
Expand Up @@ -66,6 +66,9 @@ ensure_python_initialized <- function(required_module = NULL) {
remap_output_streams()
set_knitr_python_stdout_hook()

if (is_windows() && identical(.Platform$GUI, "RStudio"))
import("rpytools.subprocess")$patch_subprocess_Popen()

# generate 'R' helper object
py_inject_r()

Expand Down
9 changes: 9 additions & 0 deletions inst/python/rpytools/subprocess.py
@@ -0,0 +1,9 @@
# When running on Windows in RStudio, we need to patch subprocess.Popen
# https://github.com/rstudio/reticulate/issues/1448


def patch_subprocess_Popen():
import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, stdin = subprocess.DEVNULL)
18 changes: 18 additions & 0 deletions tests/testthat/test-subprocess.R
@@ -0,0 +1,18 @@
context("subprocess module")

test_that("subprocess.Popen works", {

subprocess <- import("subprocess")

# needs patching on Windows in the RStudio IDE
# https://github.com/rstudio/reticulate/issues/1448
expect_no_error({
subprocess$Popen(
c("ls", "."),
shell = FALSE,
stderr = subprocess$PIPE,
stdout = subprocess$PIPE
)
})

})

0 comments on commit aa86136

Please sign in to comment.