@@ -22,6 +22,16 @@ make it possible to have multiple tools inside the `pypi` directory
2222load ("//python:py_binary.bzl" , _py_binary = "py_binary" )
2323load ("//python:py_test.bzl" , _py_test = "py_test" )
2424
25+ # The `data` attribute does not allow duplicate labels, but user-provided `data`
26+ # can overlap with labels added from attributes like `src`.
27+ def _dedupe_data (data ):
28+ res = []
29+ for d in data :
30+ if d not in res :
31+ res .append (d )
32+ return res
33+
34+
2535def pip_compile (
2636 name ,
2737 srcs = None ,
@@ -39,6 +49,7 @@ def pip_compile(
3949 visibility = ["//visibility:private" ],
4050 tags = None ,
4151 constraints = [],
52+ data = [],
4253 ** kwargs ):
4354 """Generates targets for managing pip dependencies with pip-compile (piptools).
4455
@@ -81,6 +92,7 @@ def pip_compile(
8192 tags: tagging attribute common to all build rules, passed to both the _test and .update rules.
8293 visibility: passed to both the _test and .update rules.
8394 constraints: a list of files containing constraints to pass to pip-compile with `--constraint`.
95+ data: A list of labels to include as part of the `data` attribute in the generated `py_binary`.
8496 **kwargs: other bazel attributes passed to the "_test" rule.
8597 """
8698 if len ([x for x in [srcs , src , requirements_in ] if x != None ]) > 1 :
@@ -95,16 +107,18 @@ def pip_compile(
95107
96108 requirements_txt = name + ".txt" if requirements_txt == None else requirements_txt
97109
110+ data = data or []
111+
98112 # "Default" target produced by this macro
99113 # Allow a compile_pip_requirements rule to include another one in the data
100114 # for a requirements file that does `-r ../other/requirements.txt`
101115 native .filegroup (
102116 name = name ,
103- srcs = kwargs . pop ( " data" , []) + [requirements_txt ],
117+ srcs = data + [requirements_txt ],
104118 visibility = visibility ,
105119 )
106120
107- data = [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ] + constraints
121+ data = _dedupe_data ( data + [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ] + constraints )
108122
109123 # Use the Label constructor so this is expanded in the context of the file
110124 # where it appears, which is to say, in @rules_python
0 commit comments