@@ -85,15 +85,15 @@ def _locate(bazel_runfiles, file):
8585@click .command (context_settings = {"ignore_unknown_options" : True })
8686@click .option ("--src" , "srcs" , multiple = True , required = True )
8787@click .argument ("requirements_txt" )
88- @click .argument ("update_target_label " )
88+ @click .argument ("target_label_prefix " )
8989@click .option ("--requirements-linux" )
9090@click .option ("--requirements-darwin" )
9191@click .option ("--requirements-windows" )
9292@click .argument ("extra_args" , nargs = - 1 , type = click .UNPROCESSED )
9393def main (
9494 srcs : Tuple [str , ...],
9595 requirements_txt : str ,
96- update_target_label : str ,
96+ target_label_prefix : str ,
9797 requirements_linux : Optional [str ],
9898 requirements_darwin : Optional [str ],
9999 requirements_windows : Optional [str ],
@@ -155,9 +155,10 @@ def main(
155155 # or shutil.copyfile, as they will fail with OSError: [Errno 18] Invalid cross-device link.
156156 shutil .copy (resolved_requirements_file , requirements_out )
157157
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"
160160 )
161+ test_command = f"bazel test { target_label_prefix } _test"
161162
162163 os .environ ["CUSTOM_COMPILE_COMMAND" ] = update_command
163164 os .environ ["PIP_CONFIG_FILE" ] = os .getenv ("PIP_CONFIG_FILE" ) or os .devnull
@@ -198,15 +199,15 @@ def main(
198199 absolute_output_file , requirements_file_tree
199200 )
200201 )
201- _run_pip_compile ()
202+ _run_pip_compile (verbose_command = f" { update_command } -- --verbose" )
202203 requirements_file_relative_path = Path (requirements_file_relative )
203204 content = requirements_file_relative_path .read_text ()
204205 content = content .replace (absolute_path_prefix , "" )
205206 requirements_file_relative_path .write_text (content )
206207 else :
207208 print ("Checking " + requirements_file )
208209 sys .stdout .flush ()
209- _run_pip_compile ()
210+ _run_pip_compile (verbose_command = f" { test_command } --test_arg=--verbose" )
210211 golden = open (_locate (bazel_runfiles , requirements_file )).readlines ()
211212 out = open (requirements_out ).readlines ()
212213 out = [line .replace (absolute_path_prefix , "" ) for line in out ]
@@ -215,7 +216,7 @@ def main(
215216
216217 print ("" .join (difflib .unified_diff (golden , out )), file = sys .stderr )
217218 print (
218- "Lock file out of date. Run '" + update_command + " ' to update." ,
219+ f "Lock file out of date. Run '{ update_command } ' to update." ,
219220 file = sys .stderr ,
220221 )
221222 sys .exit (1 )
@@ -225,6 +226,7 @@ def run_pip_compile(
225226 args : List [str ],
226227 * ,
227228 srcs_relative : List [str ],
229+ verbose_command : str ,
228230) -> None :
229231 try :
230232 cli (args , standalone_mode = False )
@@ -243,13 +245,17 @@ def run_pip_compile(
243245 print (
244246 "pip-compile exited with code 2. This means that pip-compile found "
245247 "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 } " ,
247251 file = sys .stderr ,
248252 )
249253 sys .exit (1 )
250254 else :
251255 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 } " ,
253259 file = sys .stderr ,
254260 )
255261 sys .exit (1 )
0 commit comments