Skip to content

Commit de85c81

Browse files
Provide a better error message if the required dev-tool cannot be found []
1 parent 134bc5e commit de85c81

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎.git-hooks/pre-push.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ def _is_excluded_file_path(path_str: str) -> bool:
107107

108108
TOOL_PATH_GIT = shutil.which('git')
109109

110+
def find_dev_tool(name):
111+
'''Return the path of the dev tool called name on PATH, or exit with an
112+
error if the environment lacks it (e.g., direnv isn't applied).'''
113+
tool_path = shutil.which(name)
114+
if tool_path is None:
115+
print(
116+
f"error: the environment is missing the required tool '{name}'; "
117+
'put dev_tools/bin on PATH (e.g., via direnv) and push again.',
118+
file = sys.stderr
119+
)
120+
sys.exit(1)
121+
return tool_path
122+
110123
def run_git(args, *, check = True, text = True):
111124
'''Run a git command and return the completed process.'''
112125
return subprocess.run(
@@ -287,7 +300,7 @@ def check_changed_files(self, first_new_commit):
287300
if use_docker:
288301
file_change_check_proc = subprocess.run(
289302
[
290-
shutil.which('edg-exec'),
303+
find_dev_tool('edg-exec'),
291304
'--',
292305
'edg-check-file-changes',
293306
str(input_file.relative_to(mono_repo_dir).as_posix()),
@@ -299,7 +312,7 @@ def check_changed_files(self, first_new_commit):
299312
else:
300313
file_change_check_proc = subprocess.run(
301314
[
302-
shutil.which('edg-check-file-changes'),
315+
find_dev_tool('edg-check-file-changes'),
303316
str(input_file),
304317
str(output_file)
305318
],

0 commit comments

Comments
 (0)