Skip to content

Commit c6afc11

Browse files
committed
fix unit tests
1 parent 7637558 commit c6afc11

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

python/uv/private/uv.bzl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def process_modules(
175175
hub_name = "uv",
176176
uv_repository = uv_repository,
177177
toolchain_type = str(UV_TOOLCHAIN_TYPE),
178-
hub_repo = uv_toolchains_repo):
178+
hub_repo = uv_toolchains_repo,
179+
get_auth = get_auth):
179180
"""Parse the modules to get the config for 'uv' toolchains.
180181
181182
Args:
@@ -184,17 +185,16 @@ def process_modules(
184185
uv_repository: the rule to create a uv_repository override.
185186
toolchain_type: the toolchain type to use here.
186187
hub_repo: the hub repo factory function to use.
188+
get_auth: the auth function to use.
187189
188190
Returns:
189191
the result of the hub_repo. Mainly used for tests.
190192
"""
191193

192194
# default values to apply for version specific config
193195
defaults = {
194-
"auth_patterns": {},
195196
"base_url": "",
196197
"manifest_filename": "",
197-
"netrc": "",
198198
"platforms": {
199199
# The structure is as follows:
200200
# "platform_name": struct(
@@ -259,10 +259,8 @@ def process_modules(
259259
specific_config = versions.setdefault(
260260
last_version,
261261
{
262-
"auth_patterns": defaults["auth_patterns"],
263262
"base_url": defaults["base_url"],
264263
"manifest_filename": defaults["manifest_filename"],
265-
"netrc": defaults["netrc"],
266264
# shallow copy is enough as the values are structs and will
267265
# be replaced on modification
268266
"platforms": dict(defaults["platforms"]),
@@ -311,6 +309,11 @@ def process_modules(
311309
for platform, src in config.get("urls", {}).items()
312310
if src.urls
313311
}
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}
314317

315318
# Or fallback to fetching them from GH manifest file
316319
# Example file: https://github.com/astral-sh/uv/releases/download/0.6.3/dist-manifest.json
@@ -323,10 +326,8 @@ def process_modules(
323326
),
324327
manifest_filename = config["manifest_filename"],
325328
platforms = sorted(platforms),
326-
attr = struct(
327-
netrc = config["netrc"],
328-
auth_patterns = config["auth_patterns"],
329-
),
329+
attr = struct(**auth),
330+
get_auth = get_auth,
330331
)
331332

332333
for platform_name, platform in platforms.items():
@@ -341,8 +342,7 @@ def process_modules(
341342
platform = platform_name,
342343
urls = urls[platform_name].urls,
343344
sha256 = urls[platform_name].sha256,
344-
auth_patterns = config["auth_patterns"],
345-
netrc = config["netrc"],
345+
**auth
346346
)
347347

348348
toolchain_names.append(toolchain_name)
@@ -379,7 +379,7 @@ def _overlap(first_collection, second_collection):
379379

380380
return False
381381

382-
def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename, platforms, attr):
382+
def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename, platforms, attr, get_auth = get_auth):
383383
"""Download the results about remote tool sources.
384384
385385
This relies on the tools using the cargo packaging to infer the actual

tests/uv/uv/uv_tests.bzl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _mod(*, name = None, default = [], configure = [], is_root = True):
100100
)
101101

102102
def _process_modules(env, **kwargs):
103-
result = process_modules(hub_repo = struct, **kwargs)
103+
result = process_modules(hub_repo = struct, get_auth = lambda *_, **__: None, **kwargs)
104104

105105
return env.expect.that_struct(
106106
struct(
@@ -124,6 +124,8 @@ def _default(
124124
platform = None,
125125
target_settings = None,
126126
version = None,
127+
netrc = None,
128+
auth_patterns = None,
127129
**kwargs):
128130
return struct(
129131
base_url = base_url,
@@ -132,6 +134,8 @@ def _default(
132134
platform = platform,
133135
target_settings = [] + (target_settings or []), # ensure that the type is correct
134136
version = version,
137+
netrc = netrc,
138+
auth_patterns = {} | (auth_patterns or {}), # ensure that the type is correct
135139
**kwargs
136140
)
137141

@@ -377,6 +381,11 @@ def _test_complex_configuring(env):
377381
platform = "linux",
378382
compatible_with = ["@platforms//os:linux"],
379383
),
384+
_configure(
385+
version = "1.0.4",
386+
netrc = "~/.my_netrc",
387+
auth_patterns = {"foo": "bar"},
388+
), # use auth
380389
],
381390
),
382391
),
@@ -388,18 +397,21 @@ def _test_complex_configuring(env):
388397
"1_0_1_osx",
389398
"1_0_2_osx",
390399
"1_0_3_linux",
400+
"1_0_4_osx",
391401
])
392402
uv.implementations().contains_exactly({
393403
"1_0_0_osx": "@uv_1_0_0_osx//:uv_toolchain",
394404
"1_0_1_osx": "@uv_1_0_1_osx//:uv_toolchain",
395405
"1_0_2_osx": "@uv_1_0_2_osx//:uv_toolchain",
396406
"1_0_3_linux": "@uv_1_0_3_linux//:uv_toolchain",
407+
"1_0_4_osx": "@uv_1_0_4_osx//:uv_toolchain",
397408
})
398409
uv.compatible_with().contains_exactly({
399410
"1_0_0_osx": ["@platforms//os:os"],
400411
"1_0_1_osx": ["@platforms//os:os"],
401412
"1_0_2_osx": ["@platforms//os:different"],
402413
"1_0_3_linux": ["@platforms//os:linux"],
414+
"1_0_4_osx": ["@platforms//os:os"],
403415
})
404416
uv.target_settings().contains_exactly({})
405417
env.expect.that_collection(calls).contains_exactly([
@@ -431,6 +443,15 @@ def _test_complex_configuring(env):
431443
"urls": ["https://example.org/1.0.3/linux"],
432444
"version": "1.0.3",
433445
},
446+
{
447+
"auth_patterns": {"foo": "bar"},
448+
"name": "uv_1_0_4_osx",
449+
"netrc": "~/.my_netrc",
450+
"platform": "osx",
451+
"sha256": "deadb00f",
452+
"urls": ["https://example.org/1.0.4/osx"],
453+
"version": "1.0.4",
454+
},
434455
])
435456

436457
_tests.append(_test_complex_configuring)

0 commit comments

Comments
 (0)