@@ -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 :
@@ -189,8 +191,10 @@ def process_modules(
189
191
190
192
# default values to apply for version specific config
191
193
defaults = {
194
+ "auth_patterns" : {},
192
195
"base_url" : "" ,
193
196
"manifest_filename" : "" ,
197
+ "netrc" : "" ,
194
198
"platforms" : {
195
199
# The structure is as follows:
196
200
# "platform_name": struct(
@@ -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 [
@@ -253,8 +259,10 @@ def process_modules(
253
259
specific_config = versions .setdefault (
254
260
last_version ,
255
261
{
262
+ "auth_patterns" : defaults ["auth_patterns" ],
256
263
"base_url" : defaults ["base_url" ],
257
264
"manifest_filename" : defaults ["manifest_filename" ],
265
+ "netrc" : defaults ["netrc" ],
258
266
# shallow copy is enough as the values are structs and will
259
267
# be replaced on modification
260
268
"platforms" : dict (defaults ["platforms" ]),
@@ -271,6 +279,8 @@ def process_modules(
271
279
sha256 = tag .sha256 ,
272
280
urls = tag .urls ,
273
281
override = mod .is_root ,
282
+ netrc = tag .netrc ,
283
+ auth_patterns = tag .auth_patterns ,
274
284
)
275
285
276
286
if not versions :
@@ -313,6 +323,10 @@ def process_modules(
313
323
),
314
324
manifest_filename = config ["manifest_filename" ],
315
325
platforms = sorted (platforms ),
326
+ attr = struct (
327
+ netrc = config ["netrc" ],
328
+ auth_patterns = config ["auth_patterns" ],
329
+ ),
316
330
)
317
331
318
332
for platform_name , platform in platforms .items ():
@@ -327,6 +341,8 @@ def process_modules(
327
341
platform = platform_name ,
328
342
urls = urls [platform_name ].urls ,
329
343
sha256 = urls [platform_name ].sha256 ,
344
+ auth_patterns = config ["auth_patterns" ],
345
+ netrc = config ["netrc" ],
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 , attr ):
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
@@ -432,9 +448,11 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
432
448
]
433
449
"""
434
450
dist_manifest = module_ctx .path (manifest_filename )
451
+ urls = [base_url + "/" + manifest_filename ]
435
452
result = module_ctx .download (
436
- base_url + "/" + manifest_filename ,
453
+ url = urls ,
437
454
output = dist_manifest ,
455
+ auth = get_auth (module_ctx , urls , ctx_attr = attr ),
438
456
)
439
457
if not result .success :
440
458
fail (result )
@@ -454,11 +472,13 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
454
472
455
473
checksum_fname = checksum ["name" ]
456
474
checksum_path = module_ctx .path (checksum_fname )
475
+ urls = ["{}/{}" .format (base_url , checksum_fname )]
457
476
downloads [checksum_path ] = struct (
458
477
download = module_ctx .download (
459
- "{}/{}" . format ( base_url , checksum_fname ) ,
478
+ url = urls ,
460
479
output = checksum_path ,
461
480
block = False ,
481
+ auth = get_auth (module_ctx , urls , ctx_attr = attr ),
462
482
),
463
483
archive_fname = fname ,
464
484
platforms = checksum ["target_triples" ],
0 commit comments