Skip to content

Commit a014b8a

Browse files
committed
fixup - add index_url handling to uv.lock
1 parent c1caf89 commit a014b8a

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

python/private/pypi/hub_builder.bzl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def _add_whl_library(self, *, python_version, whl, repo):
353353
if key in args and args[key] != None:
354354
deps_args[key] = args[key]
355355

356-
deps_args["whl_library"] = "@{}//:BUILD.bazel".format(whl_repo_name)
356+
deps_args["whl_library"] = "@{}//:BUILD.bazel".format(repo.whl_repo_name)
357357
repos_dict = self._whl_library_deps
358358

359359
repo_name = "{}_{}_{}".format(self.name, version_label(python_version), repo.repo_name)
@@ -379,13 +379,14 @@ def _add_library(self, *, repos_dict, name, args):
379379
if diff:
380380
self._logger.fail(lambda: (
381381
"Attempting to create a duplicate library {name} with different arguments. Already existing declaration has:\n".format(
382-
repo_name = name,
382+
name = name,
383383
) + "\n".join([
384384
" {}: {}".format(key, render.indent(render.dict(value)).lstrip())
385385
for key, value in diff.items()
386386
if value
387387
])
388388
))
389+
389390
return
390391
repos_dict[name] = args
391392

@@ -585,15 +586,7 @@ def _create_whl_repos(
585586
for src in whl.srcs:
586587
repo = _whl_repo(
587588
src = src,
588-
# TODO @aignas 2026-07-04: add a test to ensure that overriding the default
589-
# index url overrides the values here.
590-
index_url = (
591-
whl.index_url or
592-
"{}/{}".format(
593-
self._default_index_url[python_version],
594-
whl.name,
595-
)
596-
).rstrip("/"),
589+
index_url = whl.index_url.rstrip("/"),
597590
whl_library_args = whl_library_args,
598591
download_only = pip_attr.download_only,
599592
netrc = self._config.netrc or pip_attr.netrc,

python/private/pypi/parse_requirements.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p
176176
"versions": {},
177177
})
178178
entry["versions"][version] = None
179+
registry = pkg.get("source", {}).get("registry", "")
180+
if registry.rstrip("/").endswith("simple"):
181+
index_url = "{}/{}".format(registry, norm_name.replace("_", "-"))
182+
else:
183+
index_url = ""
184+
entry["index_url"] = index_url
179185

180186
pkg_extras = sorted(extras_map.get(name, []))
181187
extra_str = "[{}]".format(",".join(pkg_extras)) if pkg_extras else ""
@@ -287,7 +293,7 @@ def _parse_uv_lock_json(uv_lock, all_platforms, logger, extra_pip_args = None, p
287293
name = norm_name,
288294
is_exposed = True,
289295
is_multiple_versions = len(versions) > 1,
290-
index_url = "",
296+
index_url = info["index_url"],
291297
srcs = info["resolved_srcs"],
292298
)
293299
ret.append(item)

python/private/pypi/simpleapi_download.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ def _with_index_url(index_url, values):
291291
if not values:
292292
return values
293293

294+
if not index_url:
295+
fail("BUG: no index_url")
296+
294297
return struct(
295298
sdists = values.sdists,
296299
whls = values.whls,

tests/pypi/hub_builder/hub_builder_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ def _test_err_duplicate_repos(env):
14981498
env.expect.that_dict(logs).keys().contains_exactly(["rules_python:unit-test FAIL:"])
14991499
env.expect.that_collection(logs["rules_python:unit-test FAIL:"]).contains_exactly([
15001500
"""\
1501-
Attempting to create a duplicate library pypi_315_foo for foo with different arguments. Already existing declaration has:
1501+
Attempting to create a duplicate library pypi_315_foo with different arguments. Already existing declaration has:
15021502
common: {
15031503
"dep_template": "@pypi//{name}:{target}",
15041504
"config_load": "@pypi//:config.bzl",

0 commit comments

Comments
 (0)