@@ -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
249259def _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" ]
0 commit comments