in bot/code_coverage_bot/utils.py [0:0]
def run_check(command, **kwargs):
"""
Run a command through subprocess and check for output
"""
assert isinstance(command, list)
if len(command) == 0:
raise Exception("Can't run an empty command.")
_kwargs = dict(
stdin=subprocess.DEVNULL, # no interactions
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_kwargs.update(kwargs)
log.info("Running command", command=" ".join(command), kwargs=_kwargs)
with subprocess.Popen(command, **_kwargs) as proc:
output, error = proc.communicate()
if proc.returncode != 0:
output = output and output.decode("utf-8") or ""
error = error and error.decode("utf-8") or ""
# Use error to send log to sentry
log.error(
f"Command failed with code: {proc.returncode}",
exit=proc.returncode,
command=" ".join(command),
output=output.split("\n")[-1],
error=error.split("\n")[-1],
)
print(f"Output:\n{output}")
print(f"Error:\n{error}")
raise Exception(f"`{command[0]}` failed with code: {proc.returncode}.")
return output