Skip to content

Commit 7e30df0

Browse files
committed
Improve python pin error messages
1 parent 4ac1586 commit 7e30df0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

crates/uv/src/commands/python/pin.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ pub(crate) async fn pin(
6060

6161
if rm {
6262
let Some(file) = version_file? else {
63+
if global {
64+
bail!("No global Python pin found");
65+
}
6366
bail!("No Python version file found");
6467
};
6568
fs_err::tokio::remove_file(file.path()).await?;
@@ -87,7 +90,7 @@ pub(crate) async fn pin(
8790
}
8891
return Ok(ExitStatus::Success);
8992
}
90-
bail!("No pinned Python version found")
93+
bail!("No Python version file found; specify a version to create one")
9194
};
9295
let request = PythonRequest::parse(&request);
9396

crates/uv/tests/it/python_pin.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ fn python_pin() {
1515
let context: TestContext = TestContext::new_with_versions(&["3.11", "3.12"]);
1616

1717
// Without arguments, we attempt to read the current pin (which does not exist yet)
18-
uv_snapshot!(context.filters(), context.python_pin(), @r###"
18+
uv_snapshot!(context.filters(), context.python_pin(), @r"
1919
success: false
2020
exit_code: 2
2121
----- stdout -----
2222
2323
----- stderr -----
24-
error: No pinned Python version found
25-
"###);
24+
error: No Python version file found; specify a version to create one
25+
");
2626

2727
// Given an argument, we pin to that version
2828
uv_snapshot!(context.filters(), context.python_pin().arg("any"), @r###"
@@ -209,14 +209,14 @@ fn python_pin_global_if_no_local() -> Result<()> {
209209
uv.create_dir_all()?;
210210

211211
// Without arguments, we attempt to read the current pin (which does not exist yet)
212-
uv_snapshot!(context.filters(), context.python_pin(), @r###"
212+
uv_snapshot!(context.filters(), context.python_pin(), @r"
213213
success: false
214214
exit_code: 2
215215
----- stdout -----
216216
217217
----- stderr -----
218-
error: No pinned Python version found
219-
"###);
218+
error: No Python version file found; specify a version to create one
219+
");
220220

221221
// Given an argument, we globally pin to that version
222222
uv_snapshot!(context.filters(), context.python_pin().arg("3.11").arg("--global"), @r"
@@ -846,7 +846,7 @@ fn python_pin_rm() {
846846
----- stdout -----
847847
848848
----- stderr -----
849-
error: No Python version file found
849+
error: No global Python pin found
850850
");
851851

852852
// Global does not detect the local pin
@@ -857,7 +857,7 @@ fn python_pin_rm() {
857857
----- stdout -----
858858
859859
----- stderr -----
860-
error: No Python version file found
860+
error: No global Python pin found
861861
");
862862

863863
context

0 commit comments

Comments
 (0)