Skip to content

Comments

Allow pip compile to fall back to find_best for --python#17218

Closed
EliteTK wants to merge 1 commit intomainfrom
tk/pip-compile-missing-py-2
Closed

Allow pip compile to fall back to find_best for --python#17218
EliteTK wants to merge 1 commit intomainfrom
tk/pip-compile-missing-py-2

Conversation

@EliteTK
Copy link
Contributor

@EliteTK EliteTK commented Dec 22, 2025

Summary

Partially address #16709.

For cases when uv pip compile is used with --python <ver> and this flag is being honoured, allow falling back to find_best in cases where the python version cannot be found or downloaded.

Test Plan

A number of existing testcases already hit this and have been updated.

@EliteTK EliteTK requested a review from zanieb December 22, 2025 19:16
@EliteTK EliteTK added the enhancement New feature or improvement to existing functionality label Dec 22, 2025
Comment on lines +362 to +369
if let Some(python_missing_download) = python_missing_download {
warn_user!(
"The requested Python version {} was not found and could not be downloaded; {} will be used to build dependencies instead.",
python_missing_download,
interpreter.python_version(),
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an argument to be made here that this should print the original error too... Let me know.

Comment on lines +326 to +327
Err(uv_python::Error::MissingPython(..)) => (None, Some(python)),
Err(uv_python::Error::Discovery(err)) if !err.is_critical() => (None, Some(python)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are taken from find_or_download. Maybe this is an argument for some kind of predicate function for uv_python::Error so this case can be tested in one place?

@EliteTK EliteTK temporarily deployed to uv-test-registries December 22, 2025 19:20 — with GitHub Actions Inactive
.await?;
let interpreter = if let Some(python) = python.as_ref() {

let (installation, python_missing_download) = if let Some(python) = python.as_ref() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why python_missing_download is an Option instead of a bool is to avoid needing to check a bool and let Some(python) = python.as_ref() a second time.

The reason why this exists at all is to detect the case when the attempt to download failed in the first place, I couldn't find some way of testing if an interpreter satisfied a specific version. If there is a way to do that, let me know, then this code can simplified.

@EliteTK
Copy link
Contributor Author

EliteTK commented Dec 22, 2025

Might be a candidate for the breaking label?

I guess the previous PR was too...


if let Some(python_missing_download) = python_missing_download {
warn_user!(
"The requested Python version {} was not found and could not be downloaded; {} will be used to build dependencies instead.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this should be is not available and could not be downloaded or it could just be is not available like the other message?

@EliteTK
Copy link
Contributor Author

EliteTK commented Dec 23, 2025

I actually don't think this is right. We don't fall back to find_best for other things when --python is specified. e.g.

$ uv sync --no-python-downloads --python 3.13
warning: Ignoring existing virtual environment linked to non-existent Python interpreter: .venv/bin/python3 -> python
error: No interpreter found for Python 3.13 in managed installations or search path

hint: A managed Python download is available for Python 3.13, but Python downloads are set to 'never'

@EliteTK EliteTK marked this pull request as draft December 29, 2025 13:16
@EliteTK EliteTK closed this Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant