Skip to content

Commit b99bb61

Browse files
ewiandaaignas
andauthored
fix(whl_library): remove --no-index and add --no-build-isolation when build sdist (#2126)
Building sdist results in `Could not find a version that satisfies the requirement setuptool` this regressed when a fix in parameter handling got introduced in #2091. Before this change the building from sdist when using `experimental_index_url` would break because `--no-index` is passed to `pip`. This means that `pip` would fail to locate build time dependencies needed for the packages and would just not work. In `whl_library` we setup `PYTHONPATH` to have some build dependencies available (like `setuptools`) and we could use them during building from `sdist` and to do so we need to add `--no-build-isolation` flag. However, for some cases we need to also add other build-time dependencies (e.g. `flit_core`) so that the building of the wheel in the `repository_rule` context is successfuly. Removing `--no-index` allows `pip` to silently fetch the needed build dependencies from PyPI if they are missing and continue with the build. This is not a perfect solution, but it does unblock users to use the `sdist` distributions with the experimental feature enabled by using `experimental_index_url` (see #260 for tracking of the completion). Fixes #2118 Fixes #2152 --------- Co-authored-by: aignas <[email protected]>
1 parent b679a79 commit b99bb61

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ A brief description of the categories of changes:
2828
* (gazelle): Update error messages when unable to resolve a dependency to be more human-friendly.
2929

3030
### Fixed
31+
* (whl_library): Remove `--no-index` and add `--no-build-isolation` to the
32+
`pip install` command when installing a wheel from a local file, which happens
33+
when `experimental_index_url` flag is used.
3134
* (bzlmod) get the path to the host python interpreter in a way that results in
3235
platform non-dependent hashes in the lock file when the requirement markers need
3336
to be evaluated.

examples/bzlmod/MODULE.bazel.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/pypi/whl_library.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ def _whl_library_impl(rctx):
227227
whl_path = rctx.path(rctx.attr.filename)
228228
else:
229229
# It is an sdist and we need to tell PyPI to use a file in this directory
230-
# and not use any indexes.
231-
extra_pip_args.extend(["--no-index", "--find-links", "."])
230+
# and, allow getting build dependencies from PYTHONPATH, which we
231+
# setup in this repository rule, but still download any necessary
232+
# build deps from PyPI (e.g. `flit_core`) if they are missing.
233+
extra_pip_args.extend(["--no-build-isolation", "--find-links", "."])
232234

233235
args = _parse_optional_attrs(rctx, args, extra_pip_args)
234236

tests/pypi/evaluate_markers/BUILD.bazel

-7
This file was deleted.

tests/pypi/integration/BUILD.bazel

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("@dev_pip//:requirements.bzl", "all_requirements")
3+
load(":transitions.bzl", "transition_rule")
4+
5+
build_test(
6+
name = "all_requirements_build_test",
7+
targets = all_requirements,
8+
)
9+
10+
# Rule that transitions dependencies to be built from sdist
11+
transition_rule(
12+
name = "all_requirements_from_sdist",
13+
testonly = True,
14+
deps = all_requirements,
15+
)
16+
17+
build_test(
18+
name = "all_requirements_from_sdist_build_test",
19+
targets = ["all_requirements_from_sdist"],
20+
)
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
""" Define a custom transition that sets the pip_whl flag to no """
2+
3+
def _flag_transition_impl(_settings, _ctx):
4+
return {"//python/config_settings:pip_whl": "no"}
5+
6+
flag_transition = transition(
7+
implementation = _flag_transition_impl,
8+
inputs = [],
9+
outputs = ["//python/config_settings:pip_whl"],
10+
)
11+
12+
# Define a rule that applies the transition to dependencies
13+
def _transition_rule_impl(_ctx):
14+
return [DefaultInfo()]
15+
16+
transition_rule = rule(
17+
implementation = _transition_rule_impl,
18+
attrs = {
19+
"deps": attr.label_list(cfg = flag_transition),
20+
"_allowlist_function_transition": attr.label(
21+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
22+
),
23+
},
24+
)

0 commit comments

Comments
 (0)