mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Cache tool environments in uv tool run
(#4784)
## Summary The basic strategy: - When the user does `uv tool run`, we resolve the `from` and `with` requirements (always). - After resolving, we generate a hash of the requirements. For now, I'm just converting to a lockfile and hashing _that_, but that's an implementation detail. - Once we have a hash, we _also_ hash the interpreter. - We then store environments in `${CACHE_DIR}/${INTERPRETER_HASH}/${RESOLUTION_HASH}`. Some consequences: - We cache based on the interpreter, so if you request a different Python, we'll create a new environment (even if they're compatible). This has the nice side-effect of ensuring that we don't use environments for interpreters that were later deleted. - We cache the `from` and `with` together. In practice, we may want to cache them separately, then layer them? But this is also an implementation detail that we could change later. - Because we use the lockfile as the cache key, we will invalidate the cache when the format changes. That seems ok, but we could improve it in the future by generating a stable hash from a lockfile that's independent of the schema. Closes https://github.com/astral-sh/uv/issues/4752.
This commit is contained in:
parent
1e8f5926e6
commit
de40f798b9
12 changed files with 561 additions and 101 deletions
|
@ -697,7 +697,7 @@ impl InterpreterInfo {
|
|||
|
||||
// If `executable` is a pyenv shim, a bash script that redirects to the activated
|
||||
// python executable at another path, we're not allowed to cache the interpreter info.
|
||||
if same_file::is_same_file(executable, &info.sys_executable).unwrap_or(false) {
|
||||
if is_same_file(executable, &info.sys_executable).unwrap_or(false) {
|
||||
fs::create_dir_all(cache_entry.dir())?;
|
||||
write_atomic_sync(
|
||||
cache_entry.path(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue