Skip to content

Commit

Permalink
Improve the error message when a Python install request is not valid (#…
Browse files Browse the repository at this point in the history
…9783)

```
❯ uv python install foo
error: Cannot download managed Python for request: directory `foo`
❯ cargo run -q -- python install foo
error: `foo` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
```
  • Loading branch information
zanieb authored Dec 10, 2024
1 parent 535ab69 commit 7191865
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion crates/uv/src/commands/python/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl InstallRequest {
// Make sure the request is a valid download request and fill platform information
let download_request = PythonDownloadRequest::from_request(&request)
.ok_or_else(|| {
anyhow::anyhow!("Cannot download managed Python for request: {request}")
anyhow::anyhow!(
"`{}` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions",
request.to_canonical_string()
)
})?
.fill()?;

Expand Down
31 changes: 29 additions & 2 deletions crates/uv/tests/it/python_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::Path, process::Command};

use assert_fs::{
assert::PathAssert,
prelude::{FileTouch, PathChild},
prelude::{FileTouch, PathChild, PathCreateDir},
};
use predicates::prelude::predicate;
use uv_fs::Simplified;
Expand Down Expand Up @@ -491,7 +491,7 @@ fn python_install_invalid_request() {
----- stdout -----
----- stderr -----
error: Cannot download managed Python for request: executable name `foobar`
error: `foobar` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
"###);

// Request a version we don't have a download for
Expand Down Expand Up @@ -812,3 +812,30 @@ fn read_link_path(path: &Path) -> String {
unreachable!()
}
}

#[test]
fn python_install_unknown() {
let context: TestContext = TestContext::new_with_versions(&[]);

// An unknown request
uv_snapshot!(context.filters(), context.python_install().arg("foobar"), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: `foobar` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
"###);

context.temp_dir.child("foo").create_dir_all().unwrap();

// A directory
uv_snapshot!(context.filters(), context.python_install().arg("./foo"), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: `./foo` is not a valid Python download request; see `uv python help` for supported formats and `uv python list --only-downloads` for available versions
"###);
}

0 comments on commit 7191865

Please sign in to comment.