Skip to content

Commit

Permalink
Py require default python (#1720)
Browse files Browse the repository at this point in the history
* Adds reticulate_default_python(), updates msg and error py_require() output to clarify that it will use, or used, the default version

* Updates snapshot
  • Loading branch information
edgararuiz authored Jan 28, 2025
1 parent 4a50238 commit 88fad73
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,7 @@ py_set_qt_qpa_platform_plugin_path <- function(config) {
FALSE

}

reticulate_default_python <- function() {
"3.11"
}
10 changes: 7 additions & 3 deletions R/py_require.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ print.python_requirements <- function(x, ...) {
}
python_version <- x$python_version
if (is.null(python_version)) {
python_version <- "[No Python version specified]"
python_version <- paste0("[No Python version specified. Will default to '", reticulate_default_python() , "']")
}

requested_from <- as.character(lapply(x$history, function(x) x$requested_from))
Expand Down Expand Up @@ -435,7 +435,8 @@ uv_get_or_create_env <- function(packages = py_reqs_get("packages"),
# capture args; maybe used in error message later
call_args <- list(
packages = packages,
python_version = python_version,
python_version = python_version %||%
paste(reticulate_default_python(), "(reticulate default)"),
exclude_newer = exclude_newer
)

Expand All @@ -444,8 +445,11 @@ uv_get_or_create_env <- function(packages = py_reqs_get("packages"),

if (length(python_version)) {
constraints <- unlist(strsplit(python_version, ",", fixed = TRUE))
python_version <- c("--python", paste0(constraints, collapse = ","))
constraints <- paste0(constraints, collapse = ",")
} else {
constraints <- reticulate_default_python()
}
python_version <- c("--python", constraints)

if (!is.null(exclude_newer)) {
# todo, accept a POSIXct/lt, format correctly
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/py_require.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
╰─▶ Because you require numpy<2 and numpy>=2, we can conclude that your
requirements are unsatisfiable.
-- Current requirements -------------------------------------------------
Python: 3.11 (reticulate default)
Packages: numpy, numpy<2, numpy>=2
-------------------------------------------------------------------------
Error in uv_get_or_create_env() :
Expand All @@ -37,6 +38,7 @@
╰─▶ Because notexists was not found in the package registry and you require
notexists, we can conclude that your requirements are unsatisfiable.
-- Current requirements -------------------------------------------------
Python: 3.11 (reticulate default)
Packages: numpy, pandas, notexists
-------------------------------------------------------------------------
Error in uv_get_or_create_env() :
Expand Down Expand Up @@ -84,7 +86,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified]
Python: [No Python version specified. Will default to '3.11']
Packages: numpy, pandas, numpy==2
── R package requests ───────────────────────────────────────────────────
R package Python packages Python version
Expand All @@ -110,7 +112,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified]
Python: [No Python version specified. Will default to '3.11']
Packages: numpy, pandas
── R package requests ───────────────────────────────────────────────────
R package Python packages Python version
Expand Down Expand Up @@ -138,7 +140,7 @@
> py_require()
══════════════════════════ Python requirements ══════════════════════════
── Current requirements ─────────────────────────────────────────────────
Python: [No Python version specified]
Python: [No Python version specified. Will default to '3.11']
Packages: numpy, pandas
Exclude: Anything newer than 1990-01-01
── R package requests ───────────────────────────────────────────────────
Expand Down

0 comments on commit 88fad73

Please sign in to comment.