Elaborate error message when a binary is missing.

This commit is contained in:
Pascal Getreuer 2025-04-04 20:33:13 -07:00 committed by Nick Brassel
parent cb46402a5f
commit 558cce683f
No known key found for this signature in database

View File

@ -176,16 +176,24 @@ def check_binaries():
"""Iterates through ESSENTIAL_BINARIES and tests them. """Iterates through ESSENTIAL_BINARIES and tests them.
""" """
ok = CheckStatus.OK ok = CheckStatus.OK
missing_from_path = []
for binary in sorted(ESSENTIAL_BINARIES): for binary in sorted(ESSENTIAL_BINARIES):
try: try:
if not is_executable(binary): if not is_in_path(binary):
ok = CheckStatus.ERROR
missing_from_path.append(binary)
elif not is_executable(binary):
ok = CheckStatus.ERROR ok = CheckStatus.ERROR
except TimeoutExpired: except TimeoutExpired:
cli.log.debug('Timeout checking %s', binary) cli.log.debug('Timeout checking %s', binary)
if ok != CheckStatus.ERROR: if ok != CheckStatus.ERROR:
ok = CheckStatus.WARNING ok = CheckStatus.WARNING
if missing_from_path:
location_noun = 'its location' if len(missing_from_path) == 1 else 'their locations'
cli.log.error('{fg_red}' + ', '.join(missing_from_path) + f' may need to be installed, or {location_noun} added to your path.')
return ok return ok
@ -228,15 +236,18 @@ def check_submodules():
return CheckStatus.OK return CheckStatus.OK
def is_executable(command): def is_in_path(command):
"""Returns True if command exists and can be executed. """Returns True if command is found in the path.
""" """
# Make sure the command is in the path. if shutil.which(command) is None:
res = shutil.which(command)
if res is None:
cli.log.error("{fg_red}Can't find %s in your path.", command) cli.log.error("{fg_red}Can't find %s in your path.", command)
return False return False
return True
def is_executable(command):
"""Returns True if command can be executed.
"""
# Make sure the command can be executed # Make sure the command can be executed
version_arg = ESSENTIAL_BINARIES[command].get('version_arg', '--version') version_arg = ESSENTIAL_BINARIES[command].get('version_arg', '--version')
check = cli.run([command, version_arg], combined_output=True, stdin=DEVNULL, timeout=5) check = cli.run([command, version_arg], combined_output=True, stdin=DEVNULL, timeout=5)