Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resolve_python_version() #1722

Merged
merged 5 commits into from
Jan 30, 2025
Merged

Conversation

t-kalinowski
Copy link
Member

@t-kalinowski t-kalinowski commented Jan 30, 2025

Currently, adding a Python constraint like py_require(python_version = ">=3.8") changes the selected Python from 3.11 to 3.13, which then results in errors when trying to install packages that are not compatible yet with the latest Python version (e.g., tensorflow, torch).

This PR implements a custom constraint resolver that prefers returning a bugfix Python release, rather than the bleeding edge.

Some examples:

> resolve_python_version()
[1] "3.11.11"
> resolve_python_version(">=3.9")
[1] "3.11.11"
> resolve_python_version(">=3.9")
[1] "3.11.11"
> resolve_python_version(">=3.11")
[1] "3.11.11"
> resolve_python_version(">=3.12")
[1] "3.12.8"
> resolve_python_version(">=3.13")
[1] "3.13.1"
> resolve_python_version("<=3.13")
[1] "3.11.11"
> resolve_python_version("<=3.11")
[1] "3.11.11"
> resolve_python_version("<3.11")
[1] "3.10.16"
> resolve_python_version("3.14.0a3")
[1] "3.14.0a3"
> resolve_python_version("<=3.12,>=3.9,!=3.11")
[1] "3.10.16"
> resolve_python_version("<=3.12,>=3.9")
[1] "3.11.11"
> resolve_python_version("<=3.12,>=3.9,3.10")
[1] "3.10.16"
> resolve_python_version("3.10,3.11")
Error in `resolve_python_version()`:
! Requested Python version constraints could not be satisfied.
  constraints: "3.10,3.11"
Hint: Call `py_require(<version>, action = "set")` to select a specific Python version.
Run `rlang::last_trace()` to see where the error occurred.
> resolve_python_version(">=3.9,3.12")
[1] "3.12.8"
> resolve_python_version(">=3.9,3.12.1")
[1] "3.12.1"

Copy link
Collaborator

@edgararuiz edgararuiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@t-kalinowski t-kalinowski merged commit ec4bcbc into main Jan 30, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants