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
27 changes: 12 additions & 15 deletions tests/testthat/_snaps/py_require.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
> py_require("numpy<2")
> py_require("numpy>=2")
> import("numpy")
× No solution found when resolving tool dependencies:
╰─▶ Because you require numpy<2 and numpy>=2, we can conclude that your
requirements are unsatisfiable.
error: No solution found when resolving tool dependencies
cause: Because you require numpy<2 and numpy>=2, we can conclude that your requirements are unsatisfiable.
uv error code: 1
-- Current requirements -------------------------------------------------
Python: 3.12.xx (reticulate default)
Python: <version> (reticulate default)
Packages: numpy, numpy<2, numpy>=2
-------------------------------------------------------------------------
Error in uv_get_or_create_env() :
Expand Down Expand Up @@ -166,12 +165,11 @@
Output
> py_require(c("pandas", "numpy", "notexists"))
> uv_get_or_create_env()
× No solution found when resolving tool dependencies:
╰─▶ Because notexists was not found in the package registry and you require
notexists, we can conclude that your requirements are unsatisfiable.
error: No solution found when resolving tool dependencies
cause: Because notexists was not found in the package registry and you require notexists, we can conclude that your requirements are unsatisfiable.
uv error code: 1
-- Current requirements -------------------------------------------------
Python: 3.12.xx (reticulate default)
Python: <version> (reticulate default)
Packages: numpy, pandas, notexists
-------------------------------------------------------------------------
Error in uv_get_or_create_env() :
Expand Down Expand Up @@ -218,7 +216,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified. Will default to '3.12.xx']
Python: [No Python version specified. Will default to '<version>']
Packages: numpy, pandas, numpy==2
── Python requirement requests (in order) ───────────────────────────────
1. R package reticulate:
Expand All @@ -245,7 +243,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified. Will default to '3.12.xx']
Python: [No Python version specified. Will default to '<version>']
Packages: numpy, pandas
── Python requirement requests (in order) ───────────────────────────────
1. R package reticulate:
Expand Down Expand Up @@ -274,7 +272,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified. Will default to '3.12.xx']
Python: [No Python version specified. Will default to '<version>']
Packages: numpy, pandas
Exclude: Anything newer than 1990-01-01
── Python requirement requests (in order) ───────────────────────────────
Expand Down Expand Up @@ -379,12 +377,11 @@
> library(reticulate)
> py_require("os")
> os <- import("os")
× No solution found when resolving tool dependencies:
╰─▶ Because os was not found in the package registry and you require os, we
can conclude that your requirements are unsatisfiable.
error: No solution found when resolving tool dependencies
cause: Because os was not found in the package registry and you require os, we can conclude that your requirements are unsatisfiable.
uv error code: 1
-- Current requirements -------------------------------------------------
Python: 3.12.xx (reticulate default)
Python: <version> (reticulate default)
Packages: numpy, os
-------------------------------------------------------------------------
Hint: `py_require()` expects Python package names rather than Python module names.
Expand Down
17 changes: 14 additions & 3 deletions tests/testthat/test-py_require.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
transform_scrub_python_patch <- function(x) {
transform_scrub_python_version <- function(x) {
x <- sub("3\\.([0-9]{1,2})\\.[0-9]{1,2}", "3.\\1.xx", x)
# The default Python version moves with each new Python release.
x <- sub(
"3\\.[0-9]{1,2}\\.xx \\(reticulate default\\)",
"<version> (reticulate default)",
x
)
x <- sub(
"Will default to '3\\.[0-9]{1,2}\\.xx'",
"Will default to '<version>'",
x
)
# uv may report install timing depending on cache state; keep snapshots stable.
x <- x[!grepl("^\\s*Installed [0-9]+ package(s)? in [0-9]+ms\\s*$", x)]
x
}

expect_snapshot2 <- function(..., transform = transform_scrub_python_patch) {
expect_snapshot2 <- function(..., transform = transform_scrub_python_version) {
expect_snapshot(..., transform = transform)
}

Expand Down Expand Up @@ -281,7 +292,7 @@ test_that("py_require() warns missing packages in a virtual env", {
expect_snapshot2(
do.call(r_session, list(force_managed_python = FALSE, exprs = expr)),
transform = function(x) {
x <- transform_scrub_python_patch(x)
x <- transform_scrub_python_version(x)
# scrub paths
gsub("[A-Za-z]:[\\\\/][^\"' ]+|/[A-Za-z0-9._/\\\\-]+", "***", x)
}
Expand Down
Loading