@@ -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 :
@@ -189,8 +191,10 @@ def process_modules(
189191
190192 # default values to apply for version specific config
191193 defaults = {
194+ "auth_patterns" : {},
192195 "base_url" : "" ,
193196 "manifest_filename" : "" ,
197+ "netrc" : "" ,
194198 "platforms" : {
195199 # The structure is as follows:
196200 # "platform_name": struct(
@@ -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 [
@@ -253,8 +259,10 @@ def process_modules(
253259 specific_config = versions .setdefault (
254260 last_version ,
255261 {
262+ "auth_patterns" : defaults ["auth_patterns" ],
256263 "base_url" : defaults ["base_url" ],
257264 "manifest_filename" : defaults ["manifest_filename" ],
265+ "netrc" : defaults ["netrc" ],
258266 # shallow copy is enough as the values are structs and will
259267 # be replaced on modification
260268 "platforms" : dict (defaults ["platforms" ]),
@@ -271,6 +279,8 @@ def process_modules(
271279 sha256 = tag .sha256 ,
272280 urls = tag .urls ,
273281 override = mod .is_root ,
282+ netrc = tag .netrc ,
283+ auth_patterns = tag .auth_patterns ,
274284 )
275285
276286 if not versions :
@@ -313,6 +323,10 @@ def process_modules(
313323 ),
314324 manifest_filename = config ["manifest_filename" ],
315325 platforms = sorted (platforms ),
326+ attr = struct (
327+ netrc = config ["netrc" ],
328+ auth_patterns = config ["auth_patterns" ],
329+ ),
316330 )
317331
318332 for platform_name , platform in platforms .items ():
@@ -327,6 +341,8 @@ def process_modules(
327341 platform = platform_name ,
328342 urls = urls [platform_name ].urls ,
329343 sha256 = urls [platform_name ].sha256 ,
344+ auth_patterns = config ["auth_patterns" ],
345+ netrc = config ["netrc" ],
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 , attr ):
367383 """Download the results about remote tool sources.
368384
369385 This relies on the tools using the cargo packaging to infer the actual
@@ -432,9 +448,11 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
432448 ]
433449 """
434450 dist_manifest = module_ctx .path (manifest_filename )
451+ urls = [base_url + "/" + manifest_filename ]
435452 result = module_ctx .download (
436- base_url + "/" + manifest_filename ,
453+ url = urls ,
437454 output = dist_manifest ,
455+ auth = get_auth (module_ctx , urls , ctx_attr = attr ),
438456 )
439457 if not result .success :
440458 fail (result )
@@ -454,11 +472,13 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
454472
455473 checksum_fname = checksum ["name" ]
456474 checksum_path = module_ctx .path (checksum_fname )
475+ urls = ["{}/{}" .format (base_url , checksum_fname )]
457476 downloads [checksum_path ] = struct (
458477 download = module_ctx .download (
459- "{}/{}" . format ( base_url , checksum_fname ) ,
478+ url = urls ,
460479 output = checksum_path ,
461480 block = False ,
481+ auth = get_auth (module_ctx , urls , ctx_attr = attr ),
462482 ),
463483 archive_fname = fname ,
464484 platforms = checksum ["target_triples" ],
0 commit comments