uv/crates/uv-toolchain
Zanie Blue 3a62ba3809
Improve toolchain and environment missing error messages (#4596)
The journey here can be seen in:

- #4587 
- #4589 
- #4594 

I collapsed all the commits here because only the last one in the stack
got us to a "correct" error message.

There are a few architectural changes:

- We have a dedicated `MissingEnvironment` and `EnvironmentNotFound`
type for `PythonEnvironment::find` allowing different error messages
when searching for environments
- `ToolchainNotFound` becomes a struct with the `ToolchainRequest` which
greatly simplifies missing toolchain error formatting
- `ToolchainNotFound` tracks the `EnvironmentPreference` so it can
accurately report the locations checked

The messages look like this now, instead of the bland (and often
incorrect): "No Python interpreter found in system toolchains".

```
❯ cargo run -q -- pip sync requirements.txt
error: No virtual environment found
❯ UV_TEST_PYTHON_PATH="" cargo run -q -- pip sync requirements.txt --system
error: No system environment found
❯ UV_TEST_PYTHON_PATH="" cargo run -q -- pip sync requirements.txt --python 3.12
error: No virtual environment found for Python 3.12
❯ UV_TEST_PYTHON_PATH="" cargo run -q -- pip sync requirements.txt --python 3.12 --system
error: No system environment found for Python 3.12
❯ UV_TEST_PYTHON_PATH="" cargo run -q -- toolchain find 3.12 --preview
error: No toolchain found for Python 3.12 in system path
❯ UV_TEST_PYTHON_PATH="" cargo run -q -- pip compile requirements.in
error: No toolchain found in virtual environments or system path
```

I'd like to follow this with hints, suggesting creating an environment
or using system in some cases.
2024-06-28 15:16:59 +00:00
..
python Rename uv-interpreter crate to uv-toolchain (#4120) 2024-06-07 13:59:14 -05:00
src Improve toolchain and environment missing error messages (#4596) 2024-06-28 15:16:59 +00:00
Cargo.toml Expose toolchain-preference as a CLI and configuration file option (#4424) 2024-06-20 13:42:09 -05:00
download-metadata.json Refactor uv-toolchain::platform to use target-lexicon (#4236) 2024-06-12 09:11:56 -05:00
fetch-download-metadata.py Refactor uv-toolchain::platform to use target-lexicon (#4236) 2024-06-12 09:11:56 -05:00
template-download-metadata.py Add support for toolchain requests by key (#4332) 2024-06-17 13:11:24 -05:00