Skip to content

Commit 88fad73

Browse files
authored
Py require default python (#1720)
* Adds reticulate_default_python(), updates msg and error py_require() output to clarify that it will use, or used, the default version * Updates snapshot
1 parent 4a50238 commit 88fad73

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

R/package.R

+4
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,7 @@ py_set_qt_qpa_platform_plugin_path <- function(config) {
390390
FALSE
391391

392392
}
393+
394+
reticulate_default_python <- function() {
395+
"3.11"
396+
}

R/py_require.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ print.python_requirements <- function(x, ...) {
147147
}
148148
python_version <- x$python_version
149149
if (is.null(python_version)) {
150-
python_version <- "[No Python version specified]"
150+
python_version <- paste0("[No Python version specified. Will default to '", reticulate_default_python() , "']")
151151
}
152152

153153
requested_from <- as.character(lapply(x$history, function(x) x$requested_from))
@@ -435,7 +435,8 @@ uv_get_or_create_env <- function(packages = py_reqs_get("packages"),
435435
# capture args; maybe used in error message later
436436
call_args <- list(
437437
packages = packages,
438-
python_version = python_version,
438+
python_version = python_version %||%
439+
paste(reticulate_default_python(), "(reticulate default)"),
439440
exclude_newer = exclude_newer
440441
)
441442

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

445446
if (length(python_version)) {
446447
constraints <- unlist(strsplit(python_version, ",", fixed = TRUE))
447-
python_version <- c("--python", paste0(constraints, collapse = ","))
448+
constraints <- paste0(constraints, collapse = ",")
449+
} else {
450+
constraints <- reticulate_default_python()
448451
}
452+
python_version <- c("--python", constraints)
449453

450454
if (!is.null(exclude_newer)) {
451455
# todo, accept a POSIXct/lt, format correctly

tests/testthat/_snaps/py_require.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
╰─▶ Because you require numpy<2 and numpy>=2, we can conclude that your
1515
requirements are unsatisfiable.
1616
-- Current requirements -------------------------------------------------
17+
Python: 3.11 (reticulate default)
1718
Packages: numpy, numpy<2, numpy>=2
1819
-------------------------------------------------------------------------
1920
Error in uv_get_or_create_env() :
@@ -37,6 +38,7 @@
3738
╰─▶ Because notexists was not found in the package registry and you require
3839
notexists, we can conclude that your requirements are unsatisfiable.
3940
-- Current requirements -------------------------------------------------
41+
Python: 3.11 (reticulate default)
4042
Packages: numpy, pandas, notexists
4143
-------------------------------------------------------------------------
4244
Error in uv_get_or_create_env() :
@@ -84,7 +86,7 @@
8486
> py_require()
8587
══════════════════════════ Python requirements ══════════════════════════
8688
── Current requirements ─────────────────────────────────────────────────
87-
Python: [No Python version specified]
89+
Python: [No Python version specified. Will default to '3.11']
8890
Packages: numpy, pandas, numpy==2
8991
── R package requests ───────────────────────────────────────────────────
9092
R package Python packages Python version
@@ -110,7 +112,7 @@
110112
> py_require()
111113
══════════════════════════ Python requirements ══════════════════════════
112114
── Current requirements ─────────────────────────────────────────────────
113-
Python: [No Python version specified]
115+
Python: [No Python version specified. Will default to '3.11']
114116
Packages: numpy, pandas
115117
── R package requests ───────────────────────────────────────────────────
116118
R package Python packages Python version
@@ -138,7 +140,7 @@
138140
> py_require()
139141
══════════════════════════ Python requirements ══════════════════════════
140142
── Current requirements ─────────────────────────────────────────────────
141-
Python: [No Python version specified]
143+
Python: [No Python version specified. Will default to '3.11']
142144
Packages: numpy, pandas
143145
Exclude: Anything newer than 1990-01-01
144146
── R package requests ───────────────────────────────────────────────────

0 commit comments

Comments
 (0)