@@ -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
@@ -196,15 +197,15 @@ def main(
196
197
atexit .register (
197
198
lambda : shutil .copy (absolute_output_file , requirements_file_tree )
198
199
)
199
- _run_pip_compile ()
200
+ _run_pip_compile (verbose_command = f" { update_command } -- --verbose" )
200
201
requirements_file_relative_path = Path (requirements_file_relative )
201
202
content = requirements_file_relative_path .read_text ()
202
203
content = content .replace (absolute_path_prefix , "" )
203
204
requirements_file_relative_path .write_text (content )
204
205
else :
205
206
print ("Checking " + requirements_file )
206
207
sys .stdout .flush ()
207
- _run_pip_compile ()
208
+ _run_pip_compile (verbose_command = f" { test_command } --test_arg=--verbose" )
208
209
golden = open (_locate (bazel_runfiles , requirements_file )).readlines ()
209
210
out = open (requirements_out ).readlines ()
210
211
out = [line .replace (absolute_path_prefix , "" ) for line in out ]
@@ -213,7 +214,7 @@ def main(
213
214
214
215
print ("" .join (difflib .unified_diff (golden , out )), file = sys .stderr )
215
216
print (
216
- "Lock file out of date. Run '" + update_command + " ' to update." ,
217
+ f "Lock file out of date. Run '{ update_command } ' to update." ,
217
218
file = sys .stderr ,
218
219
)
219
220
sys .exit (1 )
@@ -223,6 +224,7 @@ def run_pip_compile(
223
224
args : List [str ],
224
225
* ,
225
226
srcs_relative : List [str ],
227
+ verbose_command : str ,
226
228
) -> None :
227
229
try :
228
230
cli (args , standalone_mode = False )
@@ -241,13 +243,17 @@ def run_pip_compile(
241
243
print (
242
244
"pip-compile exited with code 2. This means that pip-compile found "
243
245
"incompatible requirements or could not find a version that matches "
244
- f"the install requirement in one of { srcs_relative } ." ,
246
+ f"the install requirement in one of { srcs_relative } .\n "
247
+ "Try re-running with verbose:\n "
248
+ f" { verbose_command } " ,
245
249
file = sys .stderr ,
246
250
)
247
251
sys .exit (1 )
248
252
else :
249
253
print (
250
- f"pip-compile unexpectedly exited with code { e .code } ." ,
254
+ f"pip-compile unexpectedly exited with code { e .code } .\n "
255
+ "Try re-running with verbose:\n "
256
+ f" { verbose_command } " ,
251
257
file = sys .stderr ,
252
258
)
253
259
sys .exit (1 )
0 commit comments