Skip to content

fix: add explicit data attribute to compile_pip_requirements and forward it to the generated py_binary#3865

Draft
granatam wants to merge 1 commit into
bazel-contrib:mainfrom
granatam:forward-data-to-compile-req-binary
Draft

fix: add explicit data attribute to compile_pip_requirements and forward it to the generated py_binary#3865
granatam wants to merge 1 commit into
bazel-contrib:mainfrom
granatam:forward-data-to-compile-req-binary

Conversation

@granatam

Copy link
Copy Markdown

As stated in #3858, the compile_pip_requirements macro accepts a data attribute, but this attribute is not forwarded to the internal py_binary target generated for the .update target.

As a result, using $(location :pip_cert) inside extra_args fails during analysis because the generated py_binary does not declare :pip_cert as a prerequisite.

Before:

ERROR: /.../BUILD.bazel:8:25: in args attribute of py_binary rule //:requirements.update: label '//:pip_cert' in $(location) expression is not a declared prerequisite of this rule. Since this rule was created by the macro 'pip_compile', the error might have been caused by the macro implementation
ERROR: /.../BUILD.bazel:8:25: Analysis of target '//:requirements.update' (config: 7f8856b) failed
ERROR: Analysis of target '//:requirements.update' failed; build aborted

After:

INFO: Analyzed target //:requirements.update (87 packages loaded, 4078 targets configured).
INFO: Found 1 target...
Target //:requirements.update up-to-date:
  bazel-bin/requirements.update
INFO: Elapsed time: 6.240s, Critical Path: 0.11s
INFO: 1 process: 11 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/requirements.update '--src=rules_python_pip_parse_example/requirements.in' rules_python_pip_parse_example/requirements_lock.txt //:requirements '--resolver=backtracking' --allow-unsafe --generate-hashes '--cert=./pip.cert'

Closes #3858

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds an explicit data attribute to the pip_compile macro and forwards it to the generated py_binary. The review feedback suggests defensively normalizing the data parameter to an empty list if it is falsy or None to prevent potential TypeError crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 103 to +109
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To ensure defensive programming and prevent potential TypeError crashes if data is explicitly passed as None (which is a common pattern when programmatically constructing macro arguments), we should normalize data to an empty list if it is falsy/None. This is also consistent with how tags is handled later in this function (tags = tags or []).

Suggested change
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
data = data or []
native.filegroup(
name = name,
srcs = data + [requirements_txt],
visibility = visibility,
)
data = data + [name, requirements_txt] + srcs + [f for f in (requirements_linux, requirements_darwin, requirements_windows) if f != None] + constraints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compile_pip_requirements does not forward data attribute to the generated py_binary

1 participant