This repository has been archived by the owner on Dec 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from ermakov-oleg/exit-code
feat: output with a non-zero output code in case of a dependency resolution error
- Loading branch information
Showing
5 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
import subprocess | ||
from typing import List | ||
|
||
|
||
class CommandError(Exception): | ||
def __init__(self, cmd: str, return_code: int) -> None: | ||
self.cmd = cmd | ||
self.return_code = return_code | ||
|
||
|
||
def cmd_run(cmd: List) -> str: | ||
"""Run command with subprocess | ||
Args: | ||
cmd: The command to run | ||
Returns: | ||
The output from the command | ||
Raises: | ||
CommandError when command exists with non-zero exit code | ||
""" | ||
|
||
logging.debug(f"Run command: '{' '.join(cmd)}'") | ||
process = subprocess.run( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
) | ||
if process.returncode != 0: | ||
logging.debug( | ||
f"Command '{' '.join(cmd)}' exited with non-zero" | ||
f"exit code '{process.return_code}'" | ||
) | ||
raise CommandError(cmd="".join(cmd), return_code=process.returncode) | ||
return process.stdout.decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters