Skip to content

Commit f29c585

Browse files
committed
wip
1 parent 49b586b commit f29c585

File tree

3 files changed

+353
-21
lines changed

3 files changed

+353
-21
lines changed

python/uv/private/uv.bzl

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ similarly how `rules_python` is doing it itself.
115115
},
116116
)
117117

118-
def parse_modules(module_ctx):
118+
def parse_modules(module_ctx, uv_repositories = uv_repositories):
119119
"""Parse the modules to get the config for 'uv' toolchains.
120120
121121
Args:
122122
module_ctx: the context.
123+
uv_repositories: the rule to create uv_repositories.
123124
124125
Returns:
125126
A dictionary for each version of the `uv` to configure.
@@ -180,33 +181,30 @@ def parse_modules(module_ctx):
180181
if config_attr.manifest_filename:
181182
config["manifest_filename"] = config_attr.manifest_filename
182183

183-
return versions
184-
185-
def _uv_toolchain_extension(module_ctx):
186-
uv_versions = parse_modules(module_ctx)
187-
188-
if not uv_versions:
189-
uv_toolchains_repo(
190-
name = "uv",
191-
toolchain_type = str(UV_TOOLCHAIN_TYPE),
192-
toolchain_names = ["none"],
193-
toolchain_labels = {
184+
versions = {
185+
v: config
186+
for v, config in versions.items()
187+
if config["platforms"]
188+
}
189+
if not versions:
190+
return struct(
191+
names = ["none"],
192+
labels = {
194193
# NOTE @aignas 2025-02-24: the label to the toolchain can be anything
195194
"none": str(Label("//python:none")),
196195
},
197-
toolchain_compatible_with = {
196+
compatible_with = {
198197
"none": ["@platforms//:incompatible"],
199198
},
200-
toolchain_target_settings = {},
199+
target_settings = {},
201200
)
202-
return
203201

204202
toolchain_names = []
205203
toolchain_labels_by_toolchain = {}
206204
toolchain_compatible_with_by_toolchain = {}
207205
toolchain_target_settings = {}
208206

209-
for version, config in uv_versions.items():
207+
for version, config in versions.items():
210208
config["urls"] = _get_tool_urls_from_dist_manifest(
211209
module_ctx,
212210
base_url = "{base_url}/{version}".format(
@@ -237,13 +235,25 @@ def _uv_toolchain_extension(module_ctx):
237235
for label in platform.target_settings
238236
]
239237

238+
return struct(
239+
names = toolchain_names,
240+
labels = toolchain_labels_by_toolchain,
241+
compatible_with = toolchain_compatible_with_by_toolchain,
242+
target_settings = toolchain_target_settings,
243+
)
244+
245+
def _uv_toolchain_extension(module_ctx):
246+
toolchain = parse_modules(
247+
module_ctx,
248+
)
249+
240250
uv_toolchains_repo(
241251
name = "uv",
242252
toolchain_type = str(UV_TOOLCHAIN_TYPE),
243-
toolchain_names = toolchain_names,
244-
toolchain_labels = toolchain_labels_by_toolchain,
245-
toolchain_compatible_with = toolchain_compatible_with_by_toolchain,
246-
toolchain_target_settings = toolchain_target_settings,
253+
toolchain_names = toolchain.names,
254+
toolchain_labels = toolchain.labels,
255+
toolchain_compatible_with = toolchain.compatible_with,
256+
toolchain_target_settings = toolchain.target_settings,
247257
)
248258

249259
def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename):
@@ -253,7 +263,12 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
253263
sha256 values for each binary.
254264
"""
255265
dist_manifest = module_ctx.path(manifest_filename)
256-
module_ctx.download(base_url + "/" + manifest_filename, output = dist_manifest)
266+
result = module_ctx.download(
267+
base_url + "/" + manifest_filename,
268+
output = dist_manifest,
269+
)
270+
if not result.success:
271+
fail(result)
257272
dist_manifest = json.decode(module_ctx.read(dist_manifest))
258273

259274
artifacts = dist_manifest["artifacts"]

tests/uv/uv/BUILD.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load(":uv_tests.bzl", "uv_test_suite")
16+
17+
uv_test_suite(name = "uv_tests")

0 commit comments

Comments
 (0)