Skip to content

Commit 34e1d44

Browse files
Ensure python pin --global creates parent directories if missing (#12180)
## Summary Closes #12178 ## Test Plan Added new test. Manually tested on Windows and Linux. --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent 83271f0 commit 34e1d44

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub(crate) async fn pin(
144144
let Some(config_dir) = user_uv_config_dir() else {
145145
return Err(anyhow::anyhow!("No user-level config directory found."));
146146
};
147+
fs_err::tokio::create_dir_all(&config_dir).await?;
147148
PythonVersionFile::new(config_dir.join(PYTHON_VERSION_FILENAME))
148149
.with_versions(vec![request])
149150
} else {

crates/uv/tests/it/python_pin.rs

+25
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,31 @@ fn python_pin_global_use_local_if_available() -> Result<()> {
328328
Ok(())
329329
}
330330

331+
#[test]
332+
fn python_pin_global_creates_parent_dirs() {
333+
let context: TestContext = TestContext::new_with_versions(&["3.12"]);
334+
let uv_global_config_dir = context.user_config_dir.child("uv");
335+
336+
assert!(
337+
!uv_global_config_dir.exists(),
338+
"Global config directory should not exist yet."
339+
);
340+
341+
uv_snapshot!(context.filters(), context.python_pin().arg("3.12").arg("--global"), @r"
342+
success: true
343+
exit_code: 0
344+
----- stdout -----
345+
Pinned `[UV_USER_CONFIG_DIR]/.python-version` to `3.12`
346+
347+
----- stderr -----
348+
");
349+
350+
assert!(
351+
uv_global_config_dir.exists(),
352+
"Global config directory should be automatically created (if missing) after global pin."
353+
);
354+
}
355+
331356
/// We do not need a Python interpreter to pin without `--resolved`
332357
/// (skip on Windows because the snapshot is different and the behavior is not platform dependent)
333358
#[cfg(unix)]

0 commit comments

Comments
 (0)