@@ -38,6 +38,7 @@ def pip_compile(
3838 requirements_windows = None ,
3939 visibility = ["//visibility:private" ],
4040 tags = None ,
41+ constraints = [],
4142 ** kwargs ):
4243 """Generates targets for managing pip dependencies with pip-compile.
4344
@@ -77,6 +78,7 @@ def pip_compile(
7778 requirements_windows: File of windows specific resolve output to check validate if requirement.in has changes.
7879 tags: tagging attribute common to all build rules, passed to both the _test and .update rules.
7980 visibility: passed to both the _test and .update rules.
81+ constraints: a list of files containing constraints to pass to pip-compile with `--constraint`.
8082 **kwargs: other bazel attributes passed to the "_test" rule.
8183 """
8284 if len ([x for x in [srcs , src , requirements_in ] if x != None ]) > 1 :
@@ -100,7 +102,7 @@ def pip_compile(
100102 visibility = visibility ,
101103 )
102104
103- data = [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ]
105+ data = [name , requirements_txt ] + srcs + [f for f in (requirements_linux , requirements_darwin , requirements_windows ) if f != None ] + constraints
104106
105107 # Use the Label constructor so this is expanded in the context of the file
106108 # where it appears, which is to say, in @rules_python
@@ -122,6 +124,8 @@ def pip_compile(
122124 args .append ("--requirements-darwin={}" .format (loc .format (requirements_darwin )))
123125 if requirements_windows :
124126 args .append ("--requirements-windows={}" .format (loc .format (requirements_windows )))
127+ for constraint in constraints :
128+ args .append ("--constraint=$(location {})" .format (constraint ))
125129 args .extend (extra_args )
126130
127131 deps = [
0 commit comments