Skip to content
Open
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 @@ -561,6 +561,15 @@ tasks:
- "bazel run //:os_specific_requirements.update"
- "git diff --exit-code"

integration_test_compile_pip_requirements_update_data:
<<: *reusable_build_test_all
name: "compile_pip_requirements: .update data forwarding"
working_directory: tests/integration/compile_pip_requirements
platform: ubuntu2204
shell_commands:
- "bazel query 'labels(data, //:requirements.update)' | grep -Fx '//:requirements.in'"
- "bazel query 'labels(data, //:requirements.update)' | grep -Fx '//:requirements_extra.in'"
Comment on lines +570 to +571

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use genquery for this target and not have the integration test at all?


integration_compile_pip_requirements_test_from_external_repo_ubuntu_min_workspace:
<<: *minimum_supported_version
<<: *common_workspace_flags_min_bazel
Expand Down
2 changes: 2 additions & 0 deletions news/3858.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(compile_pip_requirements) Add the explicit `data` attribute and forward it to
the generated `py_binary`.
8 changes: 6 additions & 2 deletions python/private/pypi/pip_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def pip_compile(
visibility = ["//visibility:private"],
tags = None,
constraints = [],
data = [],
**kwargs):
"""Generates targets for managing pip dependencies with pip-compile (piptools).

Expand Down Expand Up @@ -81,6 +82,7 @@ def pip_compile(
tags: tagging attribute common to all build rules, passed to both the _test and .update rules.
visibility: passed to both the _test and .update rules.
constraints: a list of files containing constraints to pass to pip-compile with `--constraint`.
data: A list of labels to include as part of the `data` attribute in the generated `py_binary`.
**kwargs: other bazel attributes passed to the "_test" rule.
"""
if len([x for x in [srcs, src, requirements_in] if x != None]) > 1:
Expand All @@ -95,16 +97,18 @@ def pip_compile(

requirements_txt = name + ".txt" if requirements_txt == None else requirements_txt

data = data or []

# "Default" target produced by this macro
# Allow a compile_pip_requirements rule to include another one in the data
# for a requirements file that does `-r ../other/requirements.txt`
native.filegroup(
name = name,
srcs = kwargs.pop("data", []) + [requirements_txt],
srcs = data + [requirements_txt],
visibility = visibility,
)

data = [name, requirements_txt] + srcs + [f for f in (requirements_linux, requirements_darwin, requirements_windows) if f != None] + constraints
data = data + [name, requirements_txt] + srcs + [f for f in (requirements_linux, requirements_darwin, requirements_windows) if f != None] + constraints
Comment thread
aignas marked this conversation as resolved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to better understand how this was not working previously was because we were including the data via the filegroup target via [name, ...] and not directly via files via data?

Out of curiosity, would the usecase have worked if the parameters did not use $(location)?. I would have thought that the files would have been included but the $(location) function in the args would not have worked correctly.

If my analysis is correct, please update the news file to hint about why thee fix was done.


# Use the Label constructor so this is expanded in the context of the file
# where it appears, which is to say, in @rules_python
Expand Down