From 00fb6d054314c0edfe47731464ea80ace61c0e4d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 7 Nov 2024 13:37:01 -0600 Subject: [PATCH] Create `.python-version` files in projects even if one exists outside of it (#8896) --- crates/uv/src/commands/project/init.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/commands/project/init.rs b/crates/uv/src/commands/project/init.rs index d6eaf5880e4d..b7ccfe0cee3a 100644 --- a/crates/uv/src/commands/project/init.rs +++ b/crates/uv/src/commands/project/init.rs @@ -716,10 +716,12 @@ impl InitProjectKind { } fs_err::write(path.join("pyproject.toml"), pyproject)?; - // Write .python-version if it doesn't exist. + // Write .python-version if it doesn't exist in the target or is empty. if let Some(python_request) = python_request { if PythonVersionFile::discover(path, &VersionFileDiscoveryOptions::default()) .await? + .filter(|file| file.version().is_some()) + .filter(|file| file.path().parent().is_some_and(|parent| parent == path)) .is_none() { PythonVersionFile::new(path.join(".python-version"))