Skip to content

Commit 10e1f7c

Browse files
authored
fix(pypi): do not fail on indexes without root index (bazel-contrib#3799)
With this PR we are changing the strategy of assuming that all of the packages that we have here will be available through the index and we stop calling the root index if only a single index is specified. This will improve the performance for public-only hubs (like the twine deps) and should in generally reflect better the pre-2.0 behaviour. Fixes bazel-contrib#3769 Closes bazel-contrib#3770
1 parent 733f240 commit 10e1f7c

4 files changed

Lines changed: 14 additions & 58 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ END_UNRELEASED_TEMPLATE
9696
* Fix the forwarding of `target_compatible_with` from `compile_pip_requirements`
9797
towards the underlying `*.update` target.
9898
([#3787](https://github.com/bazel-contrib/rules_python/pull/3787))
99+
* (pypi) Assume that all of the packages are available on a particular hub if
100+
there is only a single PyPI compatible index to be used. This saves us an expensive
101+
PyPI download and supports PyPI mirror implementations that do not support the root
102+
index functionality. Fixes
103+
([#3769](https://github.com/bazel-contrib/rules_python/pull/3769)).
99104

100105
{#v0-0-0-added}
101106
### Added

python/private/pypi/simpleapi_download.bzl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ def simpleapi_download(
131131
return contents
132132

133133
def _get_dist_urls(ctx, *, default_index, index_urls, index_url_overrides, sources, read_simpleapi, attr, block, _fail = fail, **kwargs):
134-
if index_url_overrides:
134+
# Ensure the value is not frozen
135+
index_urls = [] + (index_urls or [])
136+
if default_index not in index_urls:
137+
index_urls.append(default_index)
138+
139+
index_url_overrides = index_url_overrides or {}
140+
if index_url_overrides or len(index_urls) == 1:
135141
# Let's not call the index at all and just assume that all of the overrides have been
136-
# specified.
142+
# specified or there is only a single index and there is no need to download anything
137143
return {
138144
pkg: _normalize_url("{}/{}/".format(
139145
index_url_overrides.get(pkg, default_index),
@@ -145,11 +151,6 @@ def _get_dist_urls(ctx, *, default_index, index_urls, index_url_overrides, sourc
145151
downloads = {}
146152
results = {}
147153

148-
# Ensure the value is not frozen
149-
index_urls = [] + (index_urls or [])
150-
if default_index not in index_urls:
151-
index_urls.append(default_index)
152-
153154
for index_url in index_urls:
154155
download = read_simpleapi(
155156
ctx = ctx,

tests/integration/bzlmod_lockfile/MODULE.bazel.lock

Lines changed: 1 addition & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/pypi/simpleapi_download/simpleapi_download_tests.bzl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ _tests.append(_test_index_overrides)
169169
def _test_download_url(env):
170170
downloads = {}
171171
reads = [
172-
# The first read is the index which seeds the downloads later
173-
"""
174-
<a href="/main/simple/bar/">bar</a>
175-
<a href="/main/simple/baz/">baz</a>
176-
<a href="/main/simple/foo/">foo</a>
177-
""",
178172
"",
179173
"",
180174
"",
@@ -208,7 +202,6 @@ def _test_download_url(env):
208202
)
209203

210204
env.expect.that_dict(downloads).contains_exactly({
211-
"https://example.com/main/simple/": "path/for/https___example_com_main_simple.html",
212205
"https://example.com/main/simple/bar/": "path/for/https___example_com_main_simple_bar.html",
213206
"https://example.com/main/simple/baz/": "path/for/https___example_com_main_simple_baz.html",
214207
"https://example.com/main/simple/foo/": "path/for/https___example_com_main_simple_foo.html",
@@ -316,12 +309,6 @@ _tests.append(_test_download_url_parallel_with_overrides)
316309
def _test_download_envsubst_url(env):
317310
downloads = {}
318311
reads = [
319-
# The first read is the index which seeds the downloads later
320-
"""
321-
<a href="/main/simple/bar/">bar</a>
322-
<a href="/main/simple/baz/">baz</a>
323-
<a href="/main/simple/foo/">foo</a>
324-
""",
325312
"",
326313
"",
327314
"",
@@ -355,7 +342,6 @@ def _test_download_envsubst_url(env):
355342
)
356343

357344
env.expect.that_dict(downloads).contains_exactly({
358-
"https://example.com/main/simple/": "path/for/~index_url~.html",
359345
"https://example.com/main/simple/bar/": "path/for/~index_url~_bar.html",
360346
"https://example.com/main/simple/baz/": "path/for/~index_url~_baz.html",
361347
"https://example.com/main/simple/foo/": "path/for/~index_url~_foo.html",

0 commit comments

Comments
 (0)