Skip to content

Commit ff98687

Browse files
committed
more fixes
1 parent db49396 commit ff98687

File tree

14 files changed

+123
-46
lines changed

14 files changed

+123
-46
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ Unreleased changes template.
5757
* (rules) deprecation warnings for deprecated symbols have been turned off by
5858
default for now and can be enabled with `RULES_PYTHON_DEPRECATION_WARNINGS`
5959
env var.
60+
* (uv) Now the extension can be fully configured via `bzlmod` APIs without the
61+
need to patch `rules_python`. The documentation has been added to `rules_python`
62+
docs but usage of the extension may result in your setup breaking without any
63+
notice. What is more, the URLs and SHA256 values will be retrieved from the
64+
GitHub releases page metadata published by the `uv` project.
6065

6166
{#v0-0-0-fixed}
6267
### Fixed

MODULE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ uv_dev = use_extension(
249249
dev_dependency = True,
250250
)
251251
uv_dev.toolchain(
252-
name = "uv_0_5_24",
252+
name = "uv_toolchains",
253253
version = "0.5.24",
254254
)
255-
use_repo(uv_dev, "uv_0_5_24")
255+
use_repo(uv_dev, "uv_toolchains")
256256

257257
register_toolchains(
258-
"@uv_0_5_24//:all",
258+
"@uv_toolchains//:all",
259259
dev_dependency = True,
260260
)

docs/BUILD.bazel

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1616
load("@dev_pip//:requirements.bzl", "requirement")
1717
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
1818
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
19-
load("//python/uv/private:lock.bzl", "lock") # buildifier: disable=bzl-visibility
19+
load("//python/uv:uv_lock.bzl", "uv_lock")
2020
load("//sphinxdocs:readthedocs.bzl", "readthedocs_install")
2121
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
2222
load("//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
@@ -105,6 +105,10 @@ sphinx_stardocs(
105105
"//python/private/api:py_common_api_bzl",
106106
"//python/private/pypi:config_settings_bzl",
107107
"//python/private/pypi:pkg_aliases_bzl",
108+
"//python/uv:extensions_bzl",
109+
"//python/uv:uv_lock_bzl",
110+
"//python/uv:uv_toolchain_bzl",
111+
"//python/uv:uv_toolchain_info_bzl",
108112
] + ([
109113
# Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension
110114
"//python/extensions:python_bzl",
@@ -155,7 +159,7 @@ sphinx_build_binary(
155159
)
156160

157161
# Run bazel run //docs:requirements.update
158-
lock(
162+
uv_lock(
159163
name = "requirements",
160164
srcs = ["pyproject.toml"],
161165
out = "requirements.txt",

python/uv/BUILD.bazel

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,39 @@ current_toolchain(
4545
)
4646

4747
bzl_library(
48-
name = "extensions",
48+
name = "extensions_bzl",
4949
srcs = ["extensions.bzl"],
5050
# EXPERIMENTAL: Visibility is restricted to allow for changes.
5151
visibility = ["//:__subpackages__"],
52-
deps = ["//python/uv/private:uv"],
52+
deps = ["//python/uv/private:uv_bzl"],
5353
)
5454

5555
bzl_library(
56-
name = "repositories",
57-
srcs = ["repositories.bzl"],
56+
name = "uv_lock_bzl",
57+
srcs = ["uv_lock.bzl"],
5858
# EXPERIMENTAL: Visibility is restricted to allow for changes.
5959
visibility = ["//:__subpackages__"],
6060
deps = [
61-
"//python/uv/private:toolchains_repo",
62-
"//python/uv/private:versions",
61+
"//python/uv/private:lock_bzl",
6362
],
6463
)
6564

6665
bzl_library(
67-
name = "uv_toolchain",
66+
name = "uv_toolchain_bzl",
6867
srcs = ["uv_toolchain.bzl"],
6968
# EXPERIMENTAL: Visibility is restricted to allow for changes.
7069
visibility = ["//:__subpackages__"],
7170
deps = [
72-
"//python/uv/private:uv_toolchain",
71+
"//python/uv/private:uv_toolchain_bzl",
72+
],
73+
)
74+
75+
bzl_library(
76+
name = "uv_toolchain_info_bzl",
77+
srcs = ["uv_toolchain_info.bzl"],
78+
# EXPERIMENTAL: Visibility is restricted to allow for changes.
79+
visibility = ["//:__subpackages__"],
80+
deps = [
81+
"//python/uv/private:uv_toolchain_info_bzl",
7382
],
7483
)

python/uv/extensions.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ EXPERIMENTAL: This is experimental and may be removed without notice
1818
A module extension for working with uv.
1919
"""
2020

21-
load("//python/uv/private:extension.bzl", _uv = "uv")
21+
load("//python/uv/private:uv.bzl", _uv = "uv")
2222

2323
uv = _uv

python/uv/private/BUILD.bazel

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,70 @@ filegroup(
2121
)
2222

2323
bzl_library(
24-
name = "current_toolchain",
24+
name = "current_toolchain_bzl",
2525
srcs = ["current_toolchain.bzl"],
2626
visibility = ["//python/uv:__subpackages__"],
27+
deps = [
28+
":toolchain_types_bzl",
29+
],
2730
)
2831

2932
bzl_library(
30-
name = "extensions",
31-
srcs = ["extensions.bzl"],
33+
name = "uv_bzl",
34+
srcs = ["uv.bzl"],
3235
visibility = ["//python/uv:__subpackages__"],
36+
deps = [
37+
":uv_repositories_bzl",
38+
],
3339
)
3440

3541
bzl_library(
36-
name = "toolchain_types",
42+
name = "lock_bzl",
43+
srcs = ["lock.bzl"],
44+
visibility = ["//python/uv:__subpackages__"],
45+
deps = [
46+
"//python:py_binary_bzl",
47+
"//python/private:bzlmod_enabled_bzl",
48+
"@bazel_skylib//rules:write_file",
49+
],
50+
)
51+
52+
bzl_library(
53+
name = "toolchain_types_bzl",
3754
srcs = ["toolchain_types.bzl"],
3855
visibility = ["//python/uv:__subpackages__"],
3956
)
4057

4158
bzl_library(
42-
name = "toolchains_repo",
43-
srcs = ["toolchains_repo.bzl"],
59+
name = "uv_toolchain_bzl",
60+
srcs = ["uv_toolchain.bzl"],
61+
visibility = ["//python/uv:__subpackages__"],
62+
deps = [
63+
":uv_toolchain_info_bzl",
64+
],
65+
)
66+
67+
bzl_library(
68+
name = "uv_toolchain_info_bzl",
69+
srcs = ["uv_toolchain_info.bzl"],
70+
visibility = ["//python/uv:__subpackages__"],
71+
)
72+
73+
bzl_library(
74+
name = "uv_toolchains_repo_bzl",
75+
srcs = ["uv_toolchains_repo.bzl"],
4476
visibility = ["//python/uv:__subpackages__"],
4577
deps = [
4678
"//python/private:text_util_bzl",
4779
],
4880
)
4981

5082
bzl_library(
51-
name = "versions",
52-
srcs = ["versions.bzl"],
83+
name = "uv_repositories_bzl",
84+
srcs = ["uv_repositories.bzl"],
5385
visibility = ["//python/uv:__subpackages__"],
86+
deps = [
87+
":toolchain_types_bzl",
88+
":uv_toolchains_repo_bzl",
89+
],
5490
)

python/uv/private/lock.bzl

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ _REQUIREMENTS_TARGET_COMPATIBLE_WITH = select({
2626
"//conditions:default": [],
2727
}) if BZLMOD_ENABLED else ["@platforms//:incompatible"]
2828

29-
def lock(*, name, srcs, out, upgrade = False, universal = True, python_version = None, args = [], **kwargs):
29+
def lock(*, name, srcs, out, upgrade = False, universal = True, args = [], **kwargs):
3030
"""Pin the requirements based on the src files.
3131
32+
Differences with the current {obj}`compile_pip_requirements` rule:
33+
- This is implemented in shell and `uv`.
34+
- This does not error out if the output file does not exist yet.
35+
- Supports transitions out of the box.
36+
- The execution of the lock file generation is happening inside of a build
37+
action in a `genrule`.
38+
3239
Args:
3340
name: The name of the target to run for updating the requirements.
3441
srcs: The srcs to use as inputs.
3542
out: The output file.
3643
upgrade: Tell `uv` to always upgrade the dependencies instead of
3744
keeping them as they are.
3845
universal: Tell `uv` to generate a universal lock file.
39-
python_version: Tell `rules_python` to use a particular version.
40-
Defaults to the default py toolchain.
4146
args: Extra args to pass to the rule.
4247
**kwargs: Extra kwargs passed to the binary rule.
43-
44-
Differences with the current pip-compile rule:
45-
- This is implemented in shell and uv.
46-
- This does not error out if the output file does not exist yet.
47-
- Supports transitions out of the box.
4848
"""
4949
pkg = native.package_name()
5050
update_target = name + ".update"
@@ -92,10 +92,6 @@ def lock(*, name, srcs, out, upgrade = False, universal = True, python_version =
9292
Label("//python:current_py_toolchain"),
9393
],
9494
)
95-
if python_version:
96-
py_binary_rule = lambda *args, **kwargs: py_binary(python_version = python_version, *args, **kwargs)
97-
else:
98-
py_binary_rule = py_binary
9995

10096
# Write a script that can be used for updating the in-tree version of the
10197
# requirements file
@@ -116,7 +112,7 @@ def lock(*, name, srcs, out, upgrade = False, universal = True, python_version =
116112
],
117113
)
118114

119-
py_binary_rule(
115+
py_binary(
120116
name = update_target,
121117
srcs = [update_target + ".py"],
122118
main = update_target + ".py",

python/uv/private/extension.bzl renamed to python/uv/private/uv.bzl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,32 @@ EXPERIMENTAL: This is experimental and may be removed without notice
1818
A module extension for working with uv.
1919
"""
2020

21-
load(":repositories.bzl", "uv_register_toolchains")
21+
load(":uv_repositories.bzl", "uv_repositories")
2222

2323
_DOC = """\
2424
A module extension for working with uv.
25+
26+
Use it in your own setup by:
27+
```starlark
28+
uv = use_extension(
29+
"@rules_python//python/uv:extensions.bzl",
30+
"uv",
31+
dev_dependency = True,
32+
)
33+
uv.toolchain(
34+
name = "uv_toolchains",
35+
version = "0.5.24",
36+
)
37+
use_repo(uv, "uv_toolchains")
38+
39+
register_toolchains(
40+
"@uv_toolchains//:all",
41+
dev_dependency = True,
42+
)
43+
```
44+
45+
Since this is only for locking the requirements files, it should be always
46+
marked as a `dev_dependency`.
2547
"""
2648

2749
_DIST_MANIFEST_JSON = "dist-manifest.json"
@@ -100,7 +122,7 @@ def _uv_toolchain_extension(module_ctx):
100122
module_ctx,
101123
base_url = "{base_url}/{version}".format(**config),
102124
)
103-
uv_register_toolchains(
125+
uv_repositories(
104126
name = config["name"],
105127
platforms = config["platforms"],
106128
urls = config["urls"],

python/uv/private/repositories.bzl renamed to python/uv/private/uv_repositories.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Create repositories for uv toolchain dependencies
1919
"""
2020

2121
load(":toolchain_types.bzl", "UV_TOOLCHAIN_TYPE")
22-
load(":toolchains_repo.bzl", "uv_toolchains_repo")
22+
load(":uv_toolchains_repo.bzl", "uv_toolchains_repo")
2323

2424
UV_BUILD_TMPL = """\
2525
# Generated by repositories.bzl
@@ -76,7 +76,7 @@ uv_repository = repository_rule(
7676
},
7777
)
7878

79-
def uv_register_toolchains(*, name, version, platforms, urls):
79+
def uv_repositories(*, name, version, platforms, urls):
8080
"""Convenience macro which does typical toolchain setup
8181
8282
Skip this macro if you need more control over the toolchain setup.

python/uv/private/uv_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ EXPERIMENTAL: This is experimental and may be removed without notice
1818
This module implements the uv toolchain rule
1919
"""
2020

21-
load("//python/uv/private:providers.bzl", "UvToolchainInfo")
21+
load(":uv_toolchain_info.bzl", "UvToolchainInfo")
2222

2323
def _uv_toolchain_impl(ctx):
2424
uv = ctx.attr.uv

0 commit comments

Comments
 (0)