@@ -85,15 +85,15 @@ def _locate(bazel_runfiles, file):
85
85
@click .command (context_settings = {"ignore_unknown_options" : True })
86
86
@click .option ("--src" , "srcs" , multiple = True , required = True )
87
87
@click .argument ("requirements_txt" )
88
- @click .argument ("update_target_label " )
88
+ @click .argument ("target_label_prefix " )
89
89
@click .option ("--requirements-linux" )
90
90
@click .option ("--requirements-darwin" )
91
91
@click .option ("--requirements-windows" )
92
92
@click .argument ("extra_args" , nargs = - 1 , type = click .UNPROCESSED )
93
93
def main (
94
94
srcs : Tuple [str , ...],
95
95
requirements_txt : str ,
96
- update_target_label : str ,
96
+ target_label_prefix : str ,
97
97
requirements_linux : Optional [str ],
98
98
requirements_darwin : Optional [str ],
99
99
requirements_windows : Optional [str ],
@@ -155,9 +155,10 @@ def main(
155
155
# or shutil.copyfile, as they will fail with OSError: [Errno 18] Invalid cross-device link.
156
156
shutil .copy (resolved_requirements_file , requirements_out )
157
157
158
- update_command = os . getenv ( "CUSTOM_COMPILE_COMMAND" ) or "bazel run %s" % (
159
- update_target_label ,
158
+ update_command = (
159
+ os . getenv ( "CUSTOM_COMPILE_COMMAND" ) or f"bazel run { target_label_prefix } .update"
160
160
)
161
+ test_command = f"bazel test { target_label_prefix } _test"
161
162
162
163
os .environ ["CUSTOM_COMPILE_COMMAND" ] = update_command
163
164
os .environ ["PIP_CONFIG_FILE" ] = os .getenv ("PIP_CONFIG_FILE" ) or os .devnull
@@ -198,15 +199,15 @@ def main(
198
199
absolute_output_file , requirements_file_tree
199
200
)
200
201
)
201
- _run_pip_compile ()
202
+ _run_pip_compile (verbose_command = f" { update_command } -- --verbose" )
202
203
requirements_file_relative_path = Path (requirements_file_relative )
203
204
content = requirements_file_relative_path .read_text ()
204
205
content = content .replace (absolute_path_prefix , "" )
205
206
requirements_file_relative_path .write_text (content )
206
207
else :
207
208
print ("Checking " + requirements_file )
208
209
sys .stdout .flush ()
209
- _run_pip_compile ()
210
+ _run_pip_compile (verbose_command = f" { test_command } --test_arg=--verbose" )
210
211
golden = open (_locate (bazel_runfiles , requirements_file )).readlines ()
211
212
out = open (requirements_out ).readlines ()
212
213
out = [line .replace (absolute_path_prefix , "" ) for line in out ]
@@ -215,7 +216,7 @@ def main(
215
216
216
217
print ("" .join (difflib .unified_diff (golden , out )), file = sys .stderr )
217
218
print (
218
- "Lock file out of date. Run '" + update_command + " ' to update." ,
219
+ f "Lock file out of date. Run '{ update_command } ' to update." ,
219
220
file = sys .stderr ,
220
221
)
221
222
sys .exit (1 )
@@ -225,6 +226,7 @@ def run_pip_compile(
225
226
args : List [str ],
226
227
* ,
227
228
srcs_relative : List [str ],
229
+ verbose_command : str ,
228
230
) -> None :
229
231
try :
230
232
cli (args , standalone_mode = False )
@@ -243,13 +245,17 @@ def run_pip_compile(
243
245
print (
244
246
"pip-compile exited with code 2. This means that pip-compile found "
245
247
"incompatible requirements or could not find a version that matches "
246
- f"the install requirement in one of { srcs_relative } ." ,
248
+ f"the install requirement in one of { srcs_relative } .\n "
249
+ "Try re-running with verbose:\n "
250
+ f" { verbose_command } " ,
247
251
file = sys .stderr ,
248
252
)
249
253
sys .exit (1 )
250
254
else :
251
255
print (
252
- f"pip-compile unexpectedly exited with code { e .code } ." ,
256
+ f"pip-compile unexpectedly exited with code { e .code } .\n "
257
+ "Try re-running with verbose:\n "
258
+ f" { verbose_command } " ,
253
259
file = sys .stderr ,
254
260
)
255
261
sys .exit (1 )
0 commit comments