@@ -18,6 +18,7 @@ EXPERIMENTAL: This is experimental and may be removed without notice
18
18
A module extension for working with uv.
19
19
"""
20
20
21
+ load ("//python/private:auth.bzl" , "AUTH_ATTRS" , "get_auth" )
21
22
load (":toolchain_types.bzl" , "UV_TOOLCHAIN_TYPE" )
22
23
load (":uv_repository.bzl" , "uv_repository" )
23
24
load (":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
77
78
last version used in the module or the default version set by `rules_python`.
78
79
""" ,
79
80
),
80
- }
81
+ } | AUTH_ATTRS
81
82
82
83
default = tag_class (
83
84
doc = """\
@@ -133,7 +134,7 @@ for a particular version.
133
134
},
134
135
)
135
136
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 ):
137
138
"""Set the value in the config if the value is provided"""
138
139
for key , value in values .items ():
139
140
if not value :
@@ -144,6 +145,7 @@ def _configure(config, *, platform, compatible_with, target_settings, urls = [],
144
145
145
146
config [key ] = value
146
147
148
+ config .setdefault ("auth_patterns" , {}).update (auth_patterns )
147
149
config .setdefault ("platforms" , {})
148
150
if not platform :
149
151
if compatible_with or target_settings or urls :
@@ -173,7 +175,8 @@ def process_modules(
173
175
hub_name = "uv" ,
174
176
uv_repository = uv_repository ,
175
177
toolchain_type = str (UV_TOOLCHAIN_TYPE ),
176
- hub_repo = uv_toolchains_repo ):
178
+ hub_repo = uv_toolchains_repo ,
179
+ get_auth = get_auth ):
177
180
"""Parse the modules to get the config for 'uv' toolchains.
178
181
179
182
Args:
@@ -182,6 +185,7 @@ def process_modules(
182
185
uv_repository: the rule to create a uv_repository override.
183
186
toolchain_type: the toolchain type to use here.
184
187
hub_repo: the hub repo factory function to use.
188
+ get_auth: the auth function to use.
185
189
186
190
Returns:
187
191
the result of the hub_repo. Mainly used for tests.
@@ -216,6 +220,8 @@ def process_modules(
216
220
compatible_with = tag .compatible_with ,
217
221
target_settings = tag .target_settings ,
218
222
override = mod .is_root ,
223
+ netrc = tag .netrc ,
224
+ auth_patterns = tag .auth_patterns ,
219
225
)
220
226
221
227
for key in [
@@ -271,6 +277,8 @@ def process_modules(
271
277
sha256 = tag .sha256 ,
272
278
urls = tag .urls ,
273
279
override = mod .is_root ,
280
+ netrc = tag .netrc ,
281
+ auth_patterns = tag .auth_patterns ,
274
282
)
275
283
276
284
if not versions :
@@ -301,6 +309,11 @@ def process_modules(
301
309
for platform , src in config .get ("urls" , {}).items ()
302
310
if src .urls
303
311
}
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 }
304
317
305
318
# Or fallback to fetching them from GH manifest file
306
319
# Example file: https://github.com/astral-sh/uv/releases/download/0.6.3/dist-manifest.json
@@ -313,6 +326,8 @@ def process_modules(
313
326
),
314
327
manifest_filename = config ["manifest_filename" ],
315
328
platforms = sorted (platforms ),
329
+ get_auth = get_auth ,
330
+ ** auth
316
331
)
317
332
318
333
for platform_name , platform in platforms .items ():
@@ -327,6 +342,7 @@ def process_modules(
327
342
platform = platform_name ,
328
343
urls = urls [platform_name ].urls ,
329
344
sha256 = urls [platform_name ].sha256 ,
345
+ ** auth
330
346
)
331
347
332
348
toolchain_names .append (toolchain_name )
@@ -363,7 +379,7 @@ def _overlap(first_collection, second_collection):
363
379
364
380
return False
365
381
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 ):
367
383
"""Download the results about remote tool sources.
368
384
369
385
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
431
447
"aarch64-apple-darwin"
432
448
]
433
449
"""
450
+ auth_attr = struct (** auth_attrs )
434
451
dist_manifest = module_ctx .path (manifest_filename )
452
+ urls = [base_url + "/" + manifest_filename ]
435
453
result = module_ctx .download (
436
- base_url + "/" + manifest_filename ,
454
+ url = urls ,
437
455
output = dist_manifest ,
456
+ auth = get_auth (module_ctx , urls , ctx_attr = auth_attr ),
438
457
)
439
458
if not result .success :
440
459
fail (result )
@@ -454,11 +473,13 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
454
473
455
474
checksum_fname = checksum ["name" ]
456
475
checksum_path = module_ctx .path (checksum_fname )
476
+ urls = ["{}/{}" .format (base_url , checksum_fname )]
457
477
downloads [checksum_path ] = struct (
458
478
download = module_ctx .download (
459
- "{}/{}" . format ( base_url , checksum_fname ) ,
479
+ url = urls ,
460
480
output = checksum_path ,
461
481
block = False ,
482
+ auth = get_auth (module_ctx , urls , ctx_attr = auth_attr ),
462
483
),
463
484
archive_fname = fname ,
464
485
platforms = checksum ["target_triples" ],
@@ -473,7 +494,7 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
473
494
474
495
sha256 , _ , checksummed_fname = module_ctx .read (checksum_path ).partition (" " )
475
496
checksummed_fname = checksummed_fname .strip (" *\n " )
476
- if archive_fname != checksummed_fname :
497
+ if checksummed_fname and archive_fname != checksummed_fname :
477
498
fail ("The checksum is for a different file, expected '{}' but got '{}'" .format (
478
499
archive_fname ,
479
500
checksummed_fname ,
0 commit comments