Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect executable name in uvx --from tool@latest #11465

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ fn warn_executable_not_provided_by_package(

// Clippy isn't happy about the difference in size between these variants, but
// [`ToolRequirement::Package`] is the more common case and it seems annoying to box it.
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum ToolRequirement {
Python,
Expand Down Expand Up @@ -528,7 +529,6 @@ async fn get_or_create_environment(
// Ex) `ruff>=0.6.0`
Target::Unspecified(requirement) => {
let spec = RequirementsSpecification::parse_package(requirement)?;
debug!("{:?}", spec);
if let UnresolvedRequirement::Named(requirement) = &spec.requirement {
if requirement.name.as_str() == "python" {
return Err(anyhow::anyhow!(
Expand Down Expand Up @@ -567,9 +567,12 @@ async fn get_or_create_environment(
(executable, requirement)
}
// Ex) `[email protected]`
Target::Version(executable, name, extras, version) => (
(*executable).to_string(),
Requirement {
Target::Version(executable, name, extras, version) => {
let executable = request
.executable
.map(ToString::to_string)
.unwrap_or_else(|| (*executable).to_string());
let requirement = Requirement {
name: name.clone(),
extras: extras.clone(),
groups: vec![],
Expand All @@ -582,12 +585,17 @@ async fn get_or_create_environment(
conflict: None,
},
origin: None,
},
),
};

(executable, requirement)
}
// Ex) `ruff@latest`
Target::Latest(executable, name, extras) => (
(*executable).to_string(),
Requirement {
Target::Latest(executable, name, extras) => {
let executable = request
.executable
.map(ToString::to_string)
.unwrap_or_else(|| (*executable).to_string());
let requirement = Requirement {
name: name.clone(),
extras: extras.clone(),
groups: vec![],
Expand All @@ -598,8 +606,10 @@ async fn get_or_create_environment(
conflict: None,
},
origin: None,
},
),
};

(executable, requirement)
}
};

ToolRequirement::Package {
Expand Down
47 changes: 47 additions & 0 deletions crates/uv/tests/it/tool_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,3 +1763,50 @@ fn tool_run_python_from() {
error: Using `--from python<specifier>` is not supported. Use `python@<version>` instead.
"###);
}

#[test]
fn tool_run_from_at() {
let context = TestContext::new("3.12")
.with_exclude_newer("2025-01-18T00:00:00Z")
.with_filtered_exe_suffix();
let tool_dir = context.temp_dir.child("tools");
let bin_dir = context.temp_dir.child("bin");

uv_snapshot!(context.filters(), context.tool_run()
.arg("--from")
.arg("executable-application@latest")
.arg("app")
.arg("--version")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
app 0.3.0

----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ executable-application==0.3.0
"###);

uv_snapshot!(context.filters(), context.tool_run()
.arg("--from")
.arg("[email protected]")
.arg("app")
.arg("--version")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
app 0.2.0

----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ executable-application==0.2.0
"###);
}
Loading