Skip to content

fix: Fix bazel vendor support for requirements with environment markers #2997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ tasks:
working_directory: examples/bzlmod
platform: debian11
bazel: 7.x
integration_test_bzlmod_ubuntu_vendor:
<<: *reusable_build_test_all
name: "examples/bzlmod: bazel vendor"
working_directory: examples/bzlmod
platform: ubuntu2004
shell_commands:
- "bazel vendor --vendor_dir=./vendor //..."
- "bazel build --vendor_dir=./vendor //..."
- "rm -rf ./vendor"
integration_test_bzlmod_macos:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ END_UNRELEASED_TEMPLATE

{#v0-0-0-fixed}
### Fixed
* Nothing fixed.
* (pypi) Fixes an issue where builds using a `bazel vendor` vendor directory
would fail if the constraints file contained environment markers. Fixes
[#2996](https://github.com/bazel-contrib/rules_python/issues/2996).

{#v0-0-0-added}
### Added
Expand Down
1 change: 1 addition & 0 deletions examples/bzlmod/.bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
other_module
py_proto_library/foo_external
vendor
1 change: 1 addition & 0 deletions examples/bzlmod/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bazel-*
vendor/
13 changes: 8 additions & 5 deletions python/private/pypi/evaluate_markers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ def evaluate_markers_py(mrctx, *, requirements, python_interpreter, python_inter
out_file = mrctx.path("requirements_with_markers.out.json")
mrctx.file(in_file, json.encode(requirements))

interpreter = pypi_repo_utils.resolve_python_interpreter(
mrctx,
python_interpreter = python_interpreter,
python_interpreter_target = python_interpreter_target,
)

pypi_repo_utils.execute_checked(
mrctx,
op = "ResolveRequirementEnvMarkers({})".format(in_file),
python = pypi_repo_utils.resolve_python_interpreter(
mrctx,
python_interpreter = python_interpreter,
python_interpreter_target = python_interpreter_target,
),
python = interpreter,
arguments = [
"-m",
"python.private.pypi.requirements_parser.resolve_target_platforms",
Expand All @@ -94,6 +96,7 @@ def evaluate_markers_py(mrctx, *, requirements, python_interpreter, python_inter
],
srcs = srcs,
environment = {
"PYTHONHOME": str(interpreter.dirname),
"PYTHONPATH": [
Label("@pypi__packaging//:BUILD.bazel"),
Label("//:BUILD.bazel"),
Expand Down
Loading