@@ -22,6 +22,14 @@ 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+ def _dedupe (data ):
26+ res = []
27+ for d in data :
28+ if d not in res :
29+ res .append (d )
30+ return res
31+
32+
2533def pip_compile (
2634 name ,
2735 srcs = None ,
@@ -39,6 +47,7 @@ def pip_compile(
3947 visibility = ["//visibility:private" ],
4048 tags = None ,
4149 constraints = [],
50+ data = [],
4251 ** kwargs ):
4352 """Generates targets for managing pip dependencies with pip-compile (piptools).
4453
@@ -81,6 +90,7 @@ def pip_compile(
8190 tags: tagging attribute common to all build rules, passed to both the _test and .update rules.
8291 visibility: passed to both the _test and .update rules.
8392 constraints: a list of files containing constraints to pass to pip-compile with `--constraint`.
93+ data: A list of labels to include as part of the `data` attribute in the generated `py_binary`.
8494 **kwargs: other bazel attributes passed to the "_test" rule.
8595 """
8696 if len ([x for x in [srcs , src , requirements_in ] if x != None ]) > 1 :
@@ -95,16 +105,18 @@ def pip_compile(
95105
96106 requirements_txt = name + ".txt" if requirements_txt == None else requirements_txt
97107
108+ data = data or []
109+
98110 # "Default" target produced by this macro
99111 # Allow a compile_pip_requirements rule to include another one in the data
100112 # for a requirements file that does `-r ../other/requirements.txt`
101113 native .filegroup (
102114 name = name ,
103- srcs = kwargs . pop ( " data" , []) + [requirements_txt ],
115+ srcs = data + [requirements_txt ],
104116 visibility = visibility ,
105117 )
106118
107- data = [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ] + constraints
119+ data = _dedupe ( data + [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ] + constraints )
108120
109121 # Use the Label constructor so this is expanded in the context of the file
110122 # where it appears, which is to say, in @rules_python
0 commit comments