From 859391f823df9035935e2010a462fff7381f0907 Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Fri, 30 Oct 2026 09:47:15 -0400 Subject: [PATCH] fix: tolerate absolute interpreter paths for lock update Since commit 2d39a204 (feat(uv): add --directory support for locking (#4029), 2026-09-02), the `lock` macro defaults the `directory` to the package name, and attempts to resolve the path to the Python interpreter via relative path after `uv` changes into that directory. This is fine for hermetic Python, but it doesn't respect the case that `interpreter_path` is absolute. If we have an absolute path to an interpreter, it doesn't need to involve `--directory`, so avoid the prefix altogether. --- python/uv/private/lock.bzl | 2 +- tests/uv/lock/lock_tests.bzl | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/uv/private/lock.bzl b/python/uv/private/lock.bzl index 84e4cbbc12..ddb60d0006 100644 --- a/python/uv/private/lock.bzl +++ b/python/uv/private/lock.bzl @@ -131,7 +131,7 @@ def _up(x, directory, short_path = False): elif hasattr(x, "path"): x = x.path - if not directory: + if not directory or paths.is_absolute(x): return x prefix = "/".join([".."] * len(directory.split("/"))) diff --git a/tests/uv/lock/lock_tests.bzl b/tests/uv/lock/lock_tests.bzl index f14d784ebf..f1aee2fdb1 100644 --- a/tests/uv/lock/lock_tests.bzl +++ b/tests/uv/lock/lock_tests.bzl @@ -86,6 +86,20 @@ def _test_up(env): _basic_tests.append(_test_up) +def _test_up_absolute(env): + up = lock_testing.up + env.expect.that_str( + up("/usr/bin/python3", "dev"), + ).equals("/usr/bin/python3") + env.expect.that_str( + up("/usr/bin/python3", "a/b/c"), + ).equals("/usr/bin/python3") + env.expect.that_str( + up("C:/Python312/python.exe", "dev"), + ).equals("C:/Python312/python.exe") + +_basic_tests.append(_test_up_absolute) + def lock_test_suite(name): """The test suite with various lock-related integration tests