Improve python pin error messages (#13862)
Addresses https://github.com/astral-sh/uv/issues/13854
This commit is contained in:
@@ -60,6 +60,9 @@ pub(crate) async fn pin(
|
||||
|
||||
if rm {
|
||||
let Some(file) = version_file? else {
|
||||
if global {
|
||||
bail!("No global Python pin found");
|
||||
}
|
||||
bail!("No Python version file found");
|
||||
};
|
||||
fs_err::tokio::remove_file(file.path()).await?;
|
||||
@@ -87,7 +90,7 @@ pub(crate) async fn pin(
|
||||
}
|
||||
return Ok(ExitStatus::Success);
|
||||
}
|
||||
bail!("No pinned Python version found")
|
||||
bail!("No Python version file found; specify a version to create one")
|
||||
};
|
||||
let request = PythonRequest::parse(&request);
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ fn python_pin() {
|
||||
let context: TestContext = TestContext::new_with_versions(&["3.11", "3.12"]);
|
||||
|
||||
// Without arguments, we attempt to read the current pin (which does not exist yet)
|
||||
uv_snapshot!(context.filters(), context.python_pin(), @r###"
|
||||
uv_snapshot!(context.filters(), context.python_pin(), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: No pinned Python version found
|
||||
"###);
|
||||
error: No Python version file found; specify a version to create one
|
||||
");
|
||||
|
||||
// Given an argument, we pin to that version
|
||||
uv_snapshot!(context.filters(), context.python_pin().arg("any"), @r###"
|
||||
@@ -209,14 +209,14 @@ fn python_pin_global_if_no_local() -> Result<()> {
|
||||
uv.create_dir_all()?;
|
||||
|
||||
// Without arguments, we attempt to read the current pin (which does not exist yet)
|
||||
uv_snapshot!(context.filters(), context.python_pin(), @r###"
|
||||
uv_snapshot!(context.filters(), context.python_pin(), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: No pinned Python version found
|
||||
"###);
|
||||
error: No Python version file found; specify a version to create one
|
||||
");
|
||||
|
||||
// Given an argument, we globally pin to that version
|
||||
uv_snapshot!(context.filters(), context.python_pin().arg("3.11").arg("--global"), @r"
|
||||
@@ -846,7 +846,7 @@ fn python_pin_rm() {
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: No Python version file found
|
||||
error: No global Python pin found
|
||||
");
|
||||
|
||||
// Global does not detect the local pin
|
||||
@@ -857,7 +857,7 @@ fn python_pin_rm() {
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: No Python version file found
|
||||
error: No global Python pin found
|
||||
");
|
||||
|
||||
context
|
||||
|
||||
Reference in New Issue
Block a user