Skip to content

Commit 9a638ea

Browse files
authored
feat(bzlmod): add a flag to control if the parallel downloading is used (#1854)
I have found this to be useful when debugging auth issues when using a private repo and I thought that having it configurable from the user's MODULE.bazel is a better user experience. Ammending #1827.
1 parent e3e8af8 commit 9a638ea

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ A brief description of the categories of changes:
7070
`experimental_index_url_overrides` to `pip.parse` for using the bazel
7171
downloader. If you see any issues, report in
7272
[#1357](https://github.com/bazelbuild/rules_python/issues/1357). The URLs for
73-
the whl and sdist files will be written to the lock file.
73+
the whl and sdist files will be written to the lock file. Controlling whether
74+
the downloading of metadata is done in parallel can be done using
75+
`parallel_download` attribute.
7476

7577
[0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0
7678
[python_default_visibility]: gazelle/README.md#directive-python_default_visibility

python/private/bzlmod/pip.bzl

+18
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, simpleapi_ca
199199
auth_patterns = pip_attr.auth_patterns,
200200
),
201201
cache = simpleapi_cache,
202+
parallel_download = pip_attr.parallel_download,
202203
)
203204

204205
major_minor = _major_minor_version(pip_attr.python_version)
@@ -539,6 +540,23 @@ hubs can be created, and each program can use its respective hub's targets.
539540
Targets from different hubs should not be used together.
540541
""",
541542
),
543+
"parallel_download": attr.bool(
544+
doc = """\
545+
The flag allows to make use of parallel downloading feature in bazel 7.1 and above
546+
when the bazel downloader is used. This is by default enabled as it improves the
547+
performance by a lot, but in case the queries to the simple API are very expensive
548+
or when debugging authentication issues one may want to disable this feature.
549+
550+
NOTE, This will download (potentially duplicate) data for multiple packages if
551+
there is more than one index available, but in general this should be negligible
552+
because the simple API calls are very cheap and the user should not notice any
553+
extra overhead.
554+
555+
If we are in synchronous mode, then we will use the first result that we
556+
find in case extra indexes are specified.
557+
""",
558+
default = True,
559+
),
542560
"python_version": attr.string(
543561
mandatory = True,
544562
doc = """

python/private/pypi_index.bzl

+4-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ load(":auth.bzl", "get_auth")
2323
load(":envsubst.bzl", "envsubst")
2424
load(":normalize_name.bzl", "normalize_name")
2525

26-
def simpleapi_download(ctx, *, attr, cache):
26+
def simpleapi_download(ctx, *, attr, cache, parallel_download = True):
2727
"""Download Simple API HTML.
2828
2929
Args:
@@ -49,6 +49,7 @@ def simpleapi_download(ctx, *, attr, cache):
4949
undesirable because additions to the PyPI index would not be
5050
reflected when re-evaluating the extension unless we do
5151
`bazel clean --expunge`.
52+
parallel_download: A boolean to enable usage of bazel 7.1 non-blocking downloads.
5253
5354
Returns:
5455
dict of pkg name to the parsed HTML contents - a list of structs.
@@ -60,17 +61,8 @@ def simpleapi_download(ctx, *, attr, cache):
6061

6162
download_kwargs = {}
6263
if bazel_features.external_deps.download_has_block_param:
63-
download_kwargs["block"] = False
64-
65-
# Download in parallel if possible. This will download (potentially
66-
# duplicate) data for multiple packages if there is more than one index
67-
# available, but that is the price of convenience. However, that price
68-
# should be mostly negligible because the simple API calls are very cheap
69-
# and the user should not notice any extra overhead.
70-
#
71-
# If we are in synchronous mode, then we will use the first result that we
72-
# find.
73-
#
64+
download_kwargs["block"] = not parallel_download
65+
7466
# NOTE @aignas 2024-03-31: we are not merging results from multiple indexes
7567
# to replicate how `pip` would handle this case.
7668
async_downloads = {}

0 commit comments

Comments
 (0)