Use a stable directory for (local) script virtual environments (#11347)

## Summary

Today, scripts use `CachedEnvironment`, which results in a different
virtual environment path every time the interpreter changes _or_ the
project requirements change. This makes it impossible to provide users
with a stable path to the script that they can use for (e.g.) directing
their editor.

This PR modifies `uv run` to use a stable path for local scripts (we
continue to use `CachedEnvironment` for remote scripts and scripts from
`stdin`). The logic now looks a lot more like it does for projects: we
`get_or_init` an environment, etc.

For now, the path to the script is like:
`environments-v1/4485801245a4732f`, where `4485801245a4732f` is a SHA of
the absolute path to the script. But I'm not picky on that :)
This commit is contained in:
Charlie Marsh 2025-02-11 19:45:26 -05:00 committed by GitHub
parent ba5efa8aa4
commit 79ad7a1ab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 430 additions and 196 deletions

View file

@ -65,7 +65,7 @@ impl Pep723Item {
}
/// A reference to a PEP 723 item.
#[derive(Debug)]
#[derive(Debug, Copy, Clone)]
pub enum Pep723ItemRef<'item> {
/// A PEP 723 script read from disk.
Script(&'item Pep723Script),