From ae06205da0da5b694062d04882459a926ee74c8f Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 21 Aug 2024 12:35:35 -0500 Subject: [PATCH] Respect `.python-version` files in `uv run` outside projects --- crates/uv/src/commands/project/run.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 1f2a77bb03ee..68188ce0cd45 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -441,8 +441,18 @@ pub(crate) async fn run( .connectivity(connectivity) .native_tls(native_tls); + // (1) Explicit request from user + let python_request = if let Some(request) = python.as_deref() { + Some(PythonRequest::parse(request)) + // (2) Request from `.python-version` + } else if let Some(request) = request_from_version_file(&CWD).await? { + Some(request) + } else { + None + }; + let python = PythonInstallation::find_or_download( - python.as_deref().map(PythonRequest::parse), + python_request, // No opt-in is required for system environments, since we are not mutating it. EnvironmentPreference::Any, python_preference,