fix: tolerate absolute interpreter paths for lock update (#4384) Since #4029, 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.
diff --git a/python/uv/private/lock.bzl b/python/uv/private/lock.bzl index 84e4cbb..ddb60d0 100644 --- a/python/uv/private/lock.bzl +++ b/python/uv/private/lock.bzl
@@ -131,7 +131,7 @@ 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 f14d784..f1aee2f 100644 --- a/tests/uv/lock/lock_tests.bzl +++ b/tests/uv/lock/lock_tests.bzl
@@ -86,6 +86,20 @@ _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