Skip to content

Commit 13ec6e6

Browse files
committed
Revert "fix(pypi): change the parallelisation scheme for querying SimpleAPI (bazel-contrib#2531)"
bazel-contrib#2622 (comment) This reverts commit 475a99e.
1 parent fa88281 commit 13ec6e6

File tree

5 files changed

+39
-312
lines changed

5 files changed

+39
-312
lines changed

CHANGELOG.md

-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ Unreleased changes template.
127127
* Bazel 6 support is dropped and Bazel 7.4.1 is the minimum supported
128128
version, per our Bazel support matrix. Earlier versions are not
129129
tested by CI, so functionality cannot be guaranteed.
130-
* ({bzl:obj}`pip.parse`) From now we will make fewer calls to indexes when
131-
fetching the metadata from SimpleAPI. The calls will be done in parallel to
132-
each index separately, so the extension evaluation time might slow down if
133-
not using {bzl:obj}`pip.parse.experimental_index_url_overrides`.
134130
* ({bzl:obj}`pip.parse`) Only query SimpleAPI for packages that have
135131
sha values in the `requirements.txt` file.
136132
* (rules) The version-aware rules have been folded into the base rules and

python/private/pypi/extension.bzl

-5
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,6 @@ The indexes must support Simple API as described here:
659659
https://packaging.python.org/en/latest/specifications/simple-repository-api/
660660
661661
This is equivalent to `--extra-index-urls` `pip` option.
662-
663-
:::{versionchanged} 1.1.0
664-
Starting with this version we will iterate over each index specified until
665-
we find metadata for all references distributions.
666-
:::
667662
""",
668663
default = [],
669664
),

python/private/pypi/simpleapi_download.bzl

+39-53
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load("@bazel_features//:features.bzl", "bazel_features")
2020
load("//python/private:auth.bzl", _get_auth = "get_auth")
2121
load("//python/private:envsubst.bzl", "envsubst")
2222
load("//python/private:normalize_name.bzl", "normalize_name")
23-
load("//python/private:text_util.bzl", "render")
2423
load(":parse_simpleapi_html.bzl", "parse_simpleapi_html")
2524

2625
def simpleapi_download(
@@ -29,9 +28,7 @@ def simpleapi_download(
2928
attr,
3029
cache,
3130
parallel_download = True,
32-
read_simpleapi = None,
33-
get_auth = None,
34-
_fail = fail):
31+
get_auth = None):
3532
"""Download Simple API HTML.
3633
3734
Args:
@@ -61,7 +58,6 @@ def simpleapi_download(
6158
read_simpleapi: a function for reading and parsing of the SimpleAPI contents.
6259
Used in tests.
6360
get_auth: A function to get auth information passed to read_simpleapi. Used in tests.
64-
_fail: a function to print a failure. Used in tests.
6561
6662
Returns:
6763
dict of pkg name to the parsed HTML contents - a list of structs.
@@ -77,22 +73,15 @@ def simpleapi_download(
7773

7874
# NOTE @aignas 2024-03-31: we are not merging results from multiple indexes
7975
# to replicate how `pip` would handle this case.
76+
async_downloads = {}
8077
contents = {}
8178
index_urls = [attr.index_url] + attr.extra_index_urls
82-
read_simpleapi = read_simpleapi or _read_simpleapi
83-
84-
found_on_index = {}
85-
warn_overrides = False
86-
for i, index_url in enumerate(index_urls):
87-
if i != 0:
88-
# Warn the user about a potential fix for the overrides
89-
warn_overrides = True
90-
91-
async_downloads = {}
92-
sources = [pkg for pkg in attr.sources if pkg not in found_on_index]
93-
for pkg in sources:
94-
pkg_normalized = normalize_name(pkg)
95-
result = read_simpleapi(
79+
for pkg in attr.sources:
80+
pkg_normalized = normalize_name(pkg)
81+
82+
success = False
83+
for index_url in index_urls:
84+
result = _read_simpleapi(
9685
ctx = ctx,
9786
url = "{}/{}/".format(
9887
index_url_overrides.get(pkg_normalized, index_url).rstrip("/"),
@@ -105,45 +94,42 @@ def simpleapi_download(
10594
)
10695
if hasattr(result, "wait"):
10796
# We will process it in a separate loop:
108-
async_downloads[pkg] = struct(
109-
pkg_normalized = pkg_normalized,
110-
wait = result.wait,
97+
async_downloads.setdefault(pkg_normalized, []).append(
98+
struct(
99+
pkg_normalized = pkg_normalized,
100+
wait = result.wait,
101+
),
111102
)
112-
elif result.success:
113-
contents[pkg_normalized] = result.output
114-
found_on_index[pkg] = index_url
103+
continue
115104

116-
if not async_downloads:
117-
continue
118-
119-
# If we use `block` == False, then we need to have a second loop that is
120-
# collecting all of the results as they were being downloaded in parallel.
121-
for pkg, download in async_downloads.items():
105+
if result.success:
106+
contents[pkg_normalized] = result.output
107+
success = True
108+
break
109+
110+
if not async_downloads and not success:
111+
fail("Failed to download metadata from urls: {}".format(
112+
", ".join(index_urls),
113+
))
114+
115+
if not async_downloads:
116+
return contents
117+
118+
# If we use `block` == False, then we need to have a second loop that is
119+
# collecting all of the results as they were being downloaded in parallel.
120+
for pkg, downloads in async_downloads.items():
121+
success = False
122+
for download in downloads:
122123
result = download.wait()
123124

124-
if result.success:
125+
if result.success and download.pkg_normalized not in contents:
125126
contents[download.pkg_normalized] = result.output
126-
found_on_index[pkg] = index_url
127-
128-
failed_sources = [pkg for pkg in attr.sources if pkg not in found_on_index]
129-
if failed_sources:
130-
_fail("Failed to download metadata for {} for from urls: {}".format(
131-
failed_sources,
132-
index_urls,
133-
))
134-
return None
135-
136-
if warn_overrides:
137-
index_url_overrides = {
138-
pkg: found_on_index[pkg]
139-
for pkg in attr.sources
140-
if found_on_index[pkg] != attr.index_url
141-
}
142-
143-
# buildifier: disable=print
144-
print("You can use the following `index_url_overrides` to avoid the 404 warnings:\n{}".format(
145-
render.dict(index_url_overrides),
146-
))
127+
success = True
128+
129+
if not success:
130+
fail("Failed to download metadata from urls: {}".format(
131+
", ".join(index_urls),
132+
))
147133

148134
return contents
149135

tests/pypi/simpleapi_download/BUILD.bazel

-5
This file was deleted.

0 commit comments

Comments
 (0)