-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(uv): fix UV_BIN usage with current_toolchain (#2074)
Before this PR the `uv` toolchain could not be used in a `genrule` it seems because the `//python/uv:toolchain` does not have the necessary providers for using the make variables and the re-exporting of the make variables from the `toolchain` in the `current_toolchain` rule did not seem to work. This PR removes the provider construction in the `toolchain` and does that only in the `current_toolchain`. This better mirrors how the Python toolchains are setup (grepping `PYTHON3` is sufficient to get examples). This also splits out work done in #2059 to decrease its scope, so that this can be discussed separately. Work towards #1975
- Loading branch information
Showing
7 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//python:py_test.bzl", "py_test") | ||
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility | ||
|
||
# We only test this feature when `bzlmod` is enabled. | ||
_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"] | ||
|
||
genrule( | ||
name = "uv_help", | ||
outs = ["uv_help.txt"], | ||
cmd = "$(UV_BIN) --python-fetch manual --help >$@", | ||
target_compatible_with = _TARGET_COMPATIBLE_WITH, | ||
toolchains = ["//python/uv:current_toolchain"], | ||
) | ||
|
||
py_test( | ||
name = "uv_help_test", | ||
srcs = ["uv_help_test.py"], | ||
data = [":uv_help"], | ||
env = {"DATA": "$(rlocationpath :uv_help)"}, | ||
target_compatible_with = _TARGET_COMPATIBLE_WITH, | ||
deps = ["//python/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import unittest | ||
from pathlib import Path | ||
|
||
from python.runfiles import runfiles | ||
|
||
|
||
class TestUV(unittest.TestCase): | ||
def test_uv_help(self): | ||
rfiles = runfiles.Create() | ||
assert rfiles is not None, "rfiles creation failed" | ||
|
||
data_rpath = os.environ["DATA"] | ||
uv_help_path = rfiles.Rlocation(data_rpath) | ||
assert ( | ||
uv_help_path is not None | ||
), f"the rlocation path was not found: {data_rpath}" | ||
|
||
uv_help = Path(uv_help_path).read_text() | ||
|
||
self.assertIn("Usage: uv [OPTIONS] <COMMAND>", uv_help) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |