From 630394476eb30abb025bd4b1d1e42ea37771614d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 30 Jul 2025 11:00:16 -0500 Subject: [PATCH] Copy entrypoints that have a shebang that differs in `python` vs `python3` (#14970) In https://github.com/astral-sh/uv/issues/14919 it was reported that uv's behavior differed after the first invocation. I noticed we weren't copying entrypoints after the first invocation. It turns out the shebangs were written with `.../python` but on a subsequent invocation the `sys.executable` was `.../python3` so we didn't detect these as matching. This is a pretty naive fix, but it seems much easier than ensuring the entry point path exactly matches the subsequent `sys.executable` we find. I guess we should fix this in reverse too? but I think we might always prefer `python3` when loading interpreters from environments. See #14790 for more background. --- crates/uv/src/commands/project/run.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 65fb62ef7..be9ac3783 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -1806,8 +1806,15 @@ fn copy_entrypoint( ' ''' "#, ) - // Or an absolute path shebang + // Or, an absolute path shebang .or_else(|| contents.strip_prefix(&format!("#!{}\n", previous_executable.display()))) + // If the previous executable ends with `python3`, check for a shebang with `python` too + .or_else(|| { + previous_executable + .to_str() + .and_then(|path| path.strip_suffix("3")) + .and_then(|path| contents.strip_prefix(&format!("#!{path}\n"))) + }) else { // If it's not a Python shebang, we'll skip it trace!(