Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions docs/run.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ 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.
This portable default intentionally takes precedence over reticulate's other Python selectors.
To opt out, set `RETICULATE_PYTHON` to a concrete interpreter before launch, or unset it in the script before configuring reticulate.

```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
7 changes: 7 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,13 @@ 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() {
// `ir run` owns Python selection by default so package-level
// `py_require()` declarations produce portable scripts. This
// intentionally outranks reticulate's other selectors and requires a
// reticulate release that supports `managed`; do not add runtime probes
// for older releases or externally managed environments here.
cmd.env("RETICULATE_PYTHON", "managed");
Comment thread
t-kalinowski marked this conversation as resolved.
Comment thread
t-kalinowski marked this conversation as 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