@@ -18,6 +18,7 @@ EXPERIMENTAL: This is experimental and may be removed without notice
1818A module extension for working with uv.
1919"""
2020
21+ load ("//python/private:auth.bzl" , "AUTH_ATTRS" , "get_auth" )
2122load (":toolchain_types.bzl" , "UV_TOOLCHAIN_TYPE" )
2223load (":uv_repository.bzl" , "uv_repository" )
2324load (":uv_toolchains_repo.bzl" , "uv_toolchains_repo" )
@@ -77,7 +78,7 @@ The version of uv to configure the sources for. If this is not specified it will
7778last version used in the module or the default version set by `rules_python`.
7879""" ,
7980 ),
80- }
81+ } | AUTH_ATTRS
8182
8283default = tag_class (
8384 doc = """\
@@ -133,7 +134,7 @@ for a particular version.
133134 },
134135)
135136
136- def _configure (config , * , platform , compatible_with , target_settings , urls = [], sha256 = "" , override = False , ** values ):
137+ def _configure (config , * , platform , compatible_with , target_settings , auth_patterns , urls = [], sha256 = "" , override = False , ** values ):
137138 """Set the value in the config if the value is provided"""
138139 for key , value in values .items ():
139140 if not value :
@@ -144,6 +145,7 @@ def _configure(config, *, platform, compatible_with, target_settings, urls = [],
144145
145146 config [key ] = value
146147
148+ config .setdefault ("auth_patterns" , {}).update (auth_patterns )
147149 config .setdefault ("platforms" , {})
148150 if not platform :
149151 if compatible_with or target_settings or urls :
@@ -173,7 +175,8 @@ def process_modules(
173175 hub_name = "uv" ,
174176 uv_repository = uv_repository ,
175177 toolchain_type = str (UV_TOOLCHAIN_TYPE ),
176- hub_repo = uv_toolchains_repo ):
178+ hub_repo = uv_toolchains_repo ,
179+ get_auth = get_auth ):
177180 """Parse the modules to get the config for 'uv' toolchains.
178181
179182 Args:
@@ -182,6 +185,7 @@ def process_modules(
182185 uv_repository: the rule to create a uv_repository override.
183186 toolchain_type: the toolchain type to use here.
184187 hub_repo: the hub repo factory function to use.
188+ get_auth: the auth function to use.
185189
186190 Returns:
187191 the result of the hub_repo. Mainly used for tests.
@@ -216,6 +220,8 @@ def process_modules(
216220 compatible_with = tag .compatible_with ,
217221 target_settings = tag .target_settings ,
218222 override = mod .is_root ,
223+ netrc = tag .netrc ,
224+ auth_patterns = tag .auth_patterns ,
219225 )
220226
221227 for key in [
@@ -271,6 +277,8 @@ def process_modules(
271277 sha256 = tag .sha256 ,
272278 urls = tag .urls ,
273279 override = mod .is_root ,
280+ netrc = tag .netrc ,
281+ auth_patterns = tag .auth_patterns ,
274282 )
275283
276284 if not versions :
@@ -301,6 +309,11 @@ def process_modules(
301309 for platform , src in config .get ("urls" , {}).items ()
302310 if src .urls
303311 }
312+ auth = {
313+ "auth_patterns" : config .get ("auth_patterns" ),
314+ "netrc" : config .get ("netrc" ),
315+ }
316+ auth = {k : v for k , v in auth .items () if v }
304317
305318 # Or fallback to fetching them from GH manifest file
306319 # Example file: https://github.com/astral-sh/uv/releases/download/0.6.3/dist-manifest.json
@@ -313,6 +326,8 @@ def process_modules(
313326 ),
314327 manifest_filename = config ["manifest_filename" ],
315328 platforms = sorted (platforms ),
329+ get_auth = get_auth ,
330+ ** auth
316331 )
317332
318333 for platform_name , platform in platforms .items ():
@@ -327,6 +342,7 @@ def process_modules(
327342 platform = platform_name ,
328343 urls = urls [platform_name ].urls ,
329344 sha256 = urls [platform_name ].sha256 ,
345+ ** auth
330346 )
331347
332348 toolchain_names .append (toolchain_name )
@@ -363,7 +379,7 @@ def _overlap(first_collection, second_collection):
363379
364380 return False
365381
366- def _get_tool_urls_from_dist_manifest (module_ctx , * , base_url , manifest_filename , platforms ):
382+ def _get_tool_urls_from_dist_manifest (module_ctx , * , base_url , manifest_filename , platforms , get_auth = get_auth , ** auth_attrs ):
367383 """Download the results about remote tool sources.
368384
369385 This relies on the tools using the cargo packaging to infer the actual
@@ -431,10 +447,13 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
431447 "aarch64-apple-darwin"
432448 ]
433449 """
450+ auth_attr = struct (** auth_attrs )
434451 dist_manifest = module_ctx .path (manifest_filename )
452+ urls = [base_url + "/" + manifest_filename ]
435453 result = module_ctx .download (
436- base_url + "/" + manifest_filename ,
454+ url = urls ,
437455 output = dist_manifest ,
456+ auth = get_auth (module_ctx , urls , ctx_attr = auth_attr ),
438457 )
439458 if not result .success :
440459 fail (result )
@@ -454,11 +473,13 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
454473
455474 checksum_fname = checksum ["name" ]
456475 checksum_path = module_ctx .path (checksum_fname )
476+ urls = ["{}/{}" .format (base_url , checksum_fname )]
457477 downloads [checksum_path ] = struct (
458478 download = module_ctx .download (
459- "{}/{}" . format ( base_url , checksum_fname ) ,
479+ url = urls ,
460480 output = checksum_path ,
461481 block = False ,
482+ auth = get_auth (module_ctx , urls , ctx_attr = auth_attr ),
462483 ),
463484 archive_fname = fname ,
464485 platforms = checksum ["target_triples" ],
@@ -473,7 +494,7 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
473494
474495 sha256 , _ , checksummed_fname = module_ctx .read (checksum_path ).partition (" " )
475496 checksummed_fname = checksummed_fname .strip (" *\n " )
476- if archive_fname != checksummed_fname :
497+ if checksummed_fname and archive_fname != checksummed_fname :
477498 fail ("The checksum is for a different file, expected '{}' but got '{}'" .format (
478499 archive_fname ,
479500 checksummed_fname ,
0 commit comments