@@ -105,8 +105,33 @@ def _is_excluded_file_path(path_str: str) -> bool:
105105 path_str .startswith (prefix ) for prefix in EXCLUDES_PATH_PREFIXES
106106 )
107107
108+ def pause_delegate_window () -> None :
109+ '''When running as a relaunch delegate, wait for the user before the
110+ standalone console window closes so that failure output can be read.'''
111+ if os .environ .get ('EDG_PREPUSH_DELEGATE' ) != '1' :
112+ return
113+
114+ try :
115+ input ('Push checks failed; press Enter to close this window. ' )
116+ except EOFError :
117+ pass
118+
108119TOOL_PATH_GIT = shutil .which ('git' )
109120
121+ def find_dev_tool (name ):
122+ '''Return the path of the dev tool called name on PATH, or exit with an
123+ error if the environment lacks it (e.g., direnv isn't applied).'''
124+ tool_path = shutil .which (name )
125+ if tool_path is None :
126+ print (
127+ f"error: the environment is missing the required tool '{ name } '; "
128+ 'put dev_tools/bin on PATH (e.g., via direnv) and push again.' ,
129+ file = sys .stderr
130+ )
131+ pause_delegate_window ()
132+ sys .exit (1 )
133+ return tool_path
134+
110135def run_git (args , * , check = True , text = True ):
111136 '''Run a git command and return the completed process.'''
112137 return subprocess .run (
@@ -292,7 +317,7 @@ def check_changed_files(self, first_new_commit):
292317 if use_docker :
293318 file_change_check_proc = subprocess .run (
294319 [
295- shutil . which ('edg-exec' ),
320+ find_dev_tool ('edg-exec' ),
296321 '--' ,
297322 'edg-check-file-changes' ,
298323 str (input_file .relative_to (mono_repo_dir ).as_posix ()),
@@ -304,7 +329,7 @@ def check_changed_files(self, first_new_commit):
304329 else :
305330 file_change_check_proc = subprocess .run (
306331 [
307- shutil . which ('edg-check-file-changes' ),
332+ find_dev_tool ('edg-check-file-changes' ),
308333 str (input_file ),
309334 str (output_file )
310335 ],
@@ -418,16 +443,12 @@ def run(self) -> int:
418443
419444 return 0 if (self .errors == 0 and not self .abort ) else 1
420445
421- def pause_delegate_window () -> None :
422- '''When running as a relaunch delegate, wait for the user before the
423- standalone console window closes so that failure output can be read.'''
424- if os .environ .get ('EDG_PREPUSH_DELEGATE' ) != '1' :
425- return
426-
427- try :
428- input ('Push checks failed; press Enter to close this window. ' )
429- except EOFError :
430- pass
446+ def wait_for_minimum_run_time () -> None :
447+ '''Sleep until the hook has been running for MIN_RUN_SECONDS.'''
448+ remaining = MIN_RUN_SECONDS - (time .monotonic () - START_TIME )
449+ if remaining > 0 :
450+ print (f"Pushing in { remaining :.0f} s (Ctrl-C to cancel)..." )
451+ time .sleep (remaining )
431452
432453def main ():
433454 checker = PrePushChecker ()
0 commit comments