diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 79d2dfbc30..abb3e119c1 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -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'" + integration_compile_pip_requirements_test_from_external_repo_ubuntu_min_workspace: <<: *minimum_supported_version <<: *common_workspace_flags_min_bazel diff --git a/news/3858.fixed.md b/news/3858.fixed.md new file mode 100644 index 0000000000..5cb1d029a2 --- /dev/null +++ b/news/3858.fixed.md @@ -0,0 +1,2 @@ +(compile_pip_requirements) Add the explicit `data` attribute and forward it to +the generated `py_binary`. diff --git a/python/private/pypi/pip_compile.bzl b/python/private/pypi/pip_compile.bzl index 3ef2cdb39c..eed7d7e735 100644 --- a/python/private/pypi/pip_compile.bzl +++ b/python/private/pypi/pip_compile.bzl @@ -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). @@ -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: @@ -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 # Use the Label constructor so this is expanded in the context of the file # where it appears, which is to say, in @rules_python