@@ -119,26 +119,40 @@ package(default_visibility = ["//visibility:public"])
119
119
exports_files(["requirements.bzl"])
120
120
"""
121
121
122
+ def _locked_requirements (rctx ):
123
+ os = rctx .os .name .lower ()
124
+ requirements_txt = rctx .attr .requirements_lock
125
+ if os .startswith ("mac os" ) and rctx .attr .requirements_darwin != None :
126
+ requirements_txt = rctx .attr .requirements_darwin
127
+ elif os .startswith ("linux" ) and rctx .attr .requirements_linux != None :
128
+ requirements_txt = rctx .attr .requirements_linux
129
+ elif "win" in os :
130
+ requirements_txt = rctx .attr .requirements_windows
131
+ if not requirements_txt :
132
+ fail ("""\
133
+ Incremental mode requires a requirements_lock attribute be specified,
134
+ or a platform-specific lockfile using one of the requirements_* attributes.
135
+ """ )
136
+ return requirements_txt
137
+
122
138
def _pip_repository_impl (rctx ):
123
139
python_interpreter = _resolve_python_interpreter (rctx )
124
140
125
- if rctx .attr .incremental and not rctx .attr .requirements_lock :
126
- fail ("Incremental mode requires a requirements_lock attribute be specified." )
127
-
128
141
# Write the annotations file to pass to the wheel maker
129
142
annotations = {package : json .decode (data ) for (package , data ) in rctx .attr .annotations .items ()}
130
143
annotations_file = rctx .path ("annotations.json" )
131
144
rctx .file (annotations_file , json .encode_indent (annotations , indent = " " * 4 ))
132
145
133
146
if rctx .attr .incremental :
147
+ requirements_txt = _locked_requirements (rctx )
134
148
args = [
135
149
python_interpreter ,
136
150
"-m" ,
137
151
"python.pip_install.parse_requirements_to_bzl" ,
138
152
"--requirements_lock" ,
139
- rctx .path (rctx . attr . requirements_lock ),
153
+ rctx .path (requirements_txt ),
140
154
"--requirements_lock_label" ,
141
- str (rctx . attr . requirements_lock ),
155
+ str (requirements_txt ),
142
156
# pass quiet and timeout args through to child repos.
143
157
"--quiet" ,
144
158
str (rctx .attr .quiet ),
@@ -282,6 +296,14 @@ pip_repository_attrs = {
282
296
allow_single_file = True ,
283
297
doc = "A 'requirements.txt' pip requirements file." ,
284
298
),
299
+ "requirements_darwin" : attr .label (
300
+ allow_single_file = True ,
301
+ doc = "Override the requirements_lock attribute when the host platform is Mac OS" ,
302
+ ),
303
+ "requirements_linux" : attr .label (
304
+ allow_single_file = True ,
305
+ doc = "Override the requirements_lock attribute when the host platform is Linux" ,
306
+ ),
285
307
"requirements_lock" : attr .label (
286
308
allow_single_file = True ,
287
309
doc = """
@@ -290,6 +312,10 @@ of 'requirements' no resolve will take place and pip_repository will create indi
290
312
wheels are fetched/built only for the targets specified by 'build/run/test'.
291
313
""" ,
292
314
),
315
+ "requirements_windows" : attr .label (
316
+ allow_single_file = True ,
317
+ doc = "Override the requirements_lock attribute when the host platform is Windows" ,
318
+ ),
293
319
}
294
320
295
321
pip_repository_attrs .update (** common_attrs )
0 commit comments