Skip to content

Commit

Permalink
initial "requirements are unsatisfiable" error msg impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed Jan 13, 2025
1 parent c7bbc59 commit ef4e2fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion R/py_require.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ get_or_create_venv <- function(packages = "numpy",
packages <- as.vector(rbind("--with", maybe_shQuote(packages)))

if (length(python_version))
python_version <- c("--python", maybe_shQuote(python_version))
python_version <- c("--python", maybe_shQuote(paste0(python_version, collapse = ",")))

if (!is.null(exclude_newer)) {
# todo, accept a POSIXct/lt, format correctly
Expand All @@ -202,6 +202,7 @@ get_or_create_venv <- function(packages = "numpy",
"run",
"--no-project",
"--python-preference=only-managed",
exclude_newer,
python_version,
packages,
"python",
Expand All @@ -215,9 +216,17 @@ get_or_create_venv <- function(packages = "numpy",
if (!is.null(attr(result, "status"))) {
msg <- c(
"Python requirements could not be satisfied.",
if (!is.null(python_version))
paste0("Python version: ", python_version[2]),
# TODO: wrap+indent+un_shQuote python packages
paste0(c("Python dependencies: ", matrix(packages, nrow = 2)[2, ]),
collapse = " "),
if (!is.null(exclude_newer))
paste0("Exclude newer: ", exclude_newer[2]),
"Call `py_require()` to remove or replace conflicting requirements."
)
msg <- paste0(msg, collapse = "\n")
# TODO: check if `stop()` will truncate msg, fix-up hint if yes.
stop(msg)
}

Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/_snaps/py_require.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Error requesting newer package version against an older snapshot

Code
r_session({
reticulate:::get_or_create_venv(c("numpy<2", "numpy>=2"))
r_session(attach_namespace = TRUE, {
get_or_create_venv(c("numpy<2", "numpy>=2"))
})
Output
> reticulate:::get_or_create_venv(c("numpy<2", "numpy>=2"))
> get_or_create_venv(c("numpy<2", "numpy>=2"))
× No solution found when resolving `--with` dependencies:
╰─▶ Because you require numpy<2 and numpy>=2, we can conclude that your
requirements are unsatisfiable.
Error in reticulate:::get_or_create_venv(c("numpy<2", "numpy>=2")) :
Error in get_or_create_venv(c("numpy<2", "numpy>=2")) :
Python requirements could not be satisfied.
Python dependencies: 'numpy<2' 'numpy>=2'
Call `py_require()` to remove or replace conflicting requirements.
Execution halted
------- session end -------
Expand Down

0 comments on commit ef4e2fc

Please sign in to comment.