Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/run.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Use `python-packages` or `python-version` to ask `ir run` for a Python environme
- It sets `RETICULATE_PYTHON` to the resolved Python executable.

Declare `reticulate` under `packages` when the R script loads reticulate.
When Python metadata is absent, `ir run` sets `RETICULATE_PYTHON=managed` if `RETICULATE_PYTHON` is unset.
This lets reticulate create its lazy managed environment from `py_require()` declarations made by R packages.
Set `RETICULATE_PYTHON` explicitly to keep another Python selection.

```r
#!/usr/bin/env -S ir run
Expand Down
2 changes: 2 additions & 0 deletions src/quickstart.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Python:
`ir preview` also set QUARTO_PYTHON and inject jupyter.
Add `reticulate` under `packages` when R code loads reticulate; `ir render`
and `ir preview` add it for knitr-backed Quarto documents with Python chunks.
Without Python metadata, `ir run` defaults an unset RETICULATE_PYTHON to
managed; set it explicitly to keep another Python selection.
`exclude-newer` also applies to Python unless `python-exclude-newer` is set.

Bioconductor:
Expand Down
2 changes: 2 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ fn run_script(
if let Some(python) = python {
cmd.env("RETICULATE_PYTHON", python);
activate_python_env(&mut cmd, python)?;
} else if env::var_os("RETICULATE_PYTHON").is_none() {
cmd.env("RETICULATE_PYTHON", "managed");
Comment thread
t-kalinowski marked this conversation as resolved.
Resolved
Comment thread
t-kalinowski marked this conversation as resolved.
Resolved
}

if isolated {
Expand Down
31 changes: 31 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,37 @@ cat("frontmatter.user_library=", Sys.getenv("R_LIBS_USER", unset = "<unset>"), "
assert_stdout_contains(&out, "frontmatter.user_library=NULL");
}

#[test]
fn run_without_python_metadata_defaults_reticulate_python_to_managed() {
let script = temp_path("ir-run-reticulate-python-default", "R");
fs::write(
&script,
r#"cat("reticulate_python=", Sys.getenv("RETICULATE_PYTHON", unset = "<unset>"), "\n", sep = "")
"#,
)
.unwrap();

let out = ir()
.env_remove("RETICULATE_PYTHON")
.args(["run", "--vanilla"])
.arg(&script)
.output()
.unwrap();

assert_success(&out);
assert_stdout_contains(&out, "reticulate_python=managed");

let out = ir()
.env("RETICULATE_PYTHON", "configured-python")
.args(["run", "--vanilla"])
.arg(&script)
.output()
.unwrap();

assert_success(&out);
assert_stdout_contains(&out, "reticulate_python=configured-python");
}

#[cfg(unix)]
#[test]
fn run_script_frontmatter_sets_reticulate_python_and_activates_env() {
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/quickstart.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Python:
`ir preview` also set QUARTO_PYTHON and inject jupyter.
Add `reticulate` under `packages` when R code loads reticulate; `ir render`
and `ir preview` add it for knitr-backed Quarto documents with Python chunks.
Without Python metadata, `ir run` defaults an unset RETICULATE_PYTHON to
managed; set it explicitly to keep another Python selection.
`exclude-newer` also applies to Python unless `python-exclude-newer` is set.

Bioconductor:
Expand Down
Loading