Skip to content

Commit 7cd3033

Browse files
committed
Allow cached environment reuse with @latest
1 parent f59d00b commit 7cd3033

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

crates/uv/src/commands/project/environment.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,9 @@ impl CachedEnvironment {
174174
// Search in the content-addressed cache.
175175
let cache_entry = cache.entry(CacheBucket::Environments, interpreter_hash, resolution_hash);
176176

177-
if cache.refresh().is_none() {
178-
if let Ok(root) = cache.resolve_link(cache_entry.path()) {
179-
if let Ok(environment) = PythonEnvironment::from_root(root, cache) {
180-
return Ok(Self(environment));
181-
}
177+
if let Ok(root) = cache.resolve_link(cache_entry.path()) {
178+
if let Ok(environment) = PythonEnvironment::from_root(root, cache) {
179+
return Ok(Self(environment));
182180
}
183181
}
184182

crates/uv/src/settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ impl ToolRunSettings {
536536
if installer.reinstall || !installer.reinstall_package.is_empty() {
537537
if with.is_empty() && with_requirements.is_empty() {
538538
warn_user_once!(
539-
"Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --all --reinstall` to reinstall all installed tools, or `{invocation_source} package@latest` to run the latest version of a tool."
539+
"Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --all --reinstall` to reinstall all installed tools, `{invocation_source} package@latest` to run the latest version of a tool, or `uv cache prune` to clear any cached tool environments."
540540
);
541541
} else {
542542
warn_user_once!(
543-
"Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --all --reinstall` to reinstall all installed tools, `{invocation_source} package@latest` to run the latest version of a tool, or `{invocation_source} --refresh package` to reinstall any `--with` dependencies."
543+
"Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --all --reinstall` to reinstall all installed tools, `{invocation_source} package@latest` to run the latest version of a tool, `{invocation_source} --refresh package` to reinstall any `--with` dependencies, or `uv cache prune` to clear any cached tool environments."
544544
);
545545
}
546546
}

crates/uv/tests/it/tool_run.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ fn tool_run_cache() {
742742
.arg("black")
743743
.arg("--version")
744744
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
745-
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
745+
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r"
746746
success: true
747747
exit_code: 0
748748
----- stdout -----
@@ -751,15 +751,7 @@ fn tool_run_cache() {
751751
752752
----- stderr -----
753753
Resolved [N] packages in [TIME]
754-
Prepared [N] packages in [TIME]
755-
Installed [N] packages in [TIME]
756-
+ black==24.3.0
757-
+ click==8.1.7
758-
+ mypy-extensions==1.0.0
759-
+ packaging==24.0
760-
+ pathspec==0.12.1
761-
+ platformdirs==4.2.0
762-
"###);
754+
");
763755

764756
// Verify that `--refresh-package` recreates everything. We may want to change this.
765757
uv_snapshot!(context.filters(), context.tool_run()
@@ -770,7 +762,7 @@ fn tool_run_cache() {
770762
.arg("black")
771763
.arg("--version")
772764
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
773-
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
765+
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r"
774766
success: true
775767
exit_code: 0
776768
----- stdout -----
@@ -779,15 +771,7 @@ fn tool_run_cache() {
779771
780772
----- stderr -----
781773
Resolved [N] packages in [TIME]
782-
Prepared [N] packages in [TIME]
783-
Installed [N] packages in [TIME]
784-
+ black==24.3.0
785-
+ click==8.1.7
786-
+ mypy-extensions==1.0.0
787-
+ packaging==24.0
788-
+ pathspec==0.12.1
789-
+ platformdirs==4.2.0
790-
"###);
774+
");
791775

792776
// Verify that varying the interpreter leads to a fresh environment.
793777
uv_snapshot!(context.filters(), context.tool_run()

0 commit comments

Comments
 (0)