diff options
Diffstat (limited to 'gitlint/shell.py')
-rw-r--r-- | gitlint/shell.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/gitlint/shell.py b/gitlint/shell.py index 2601b04..7f598ae 100644 --- a/gitlint/shell.py +++ b/gitlint/shell.py @@ -6,7 +6,7 @@ capabilities wrt dealing with more edge-case environments on *nix systems that a """ import subprocess -from gitlint.utils import ustr, IS_PY2, USE_SH_LIB +from gitlint.utils import USE_SH_LIB, DEFAULT_ENCODING def shell(cmd): @@ -25,7 +25,7 @@ else: """ Exception indicating a command was not found during execution """ pass - class ShResult(object): + class ShResult: """ Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using the builtin subprocess module """ @@ -51,11 +51,6 @@ else: return _exec(*args, **kwargs) def _exec(*args, **kwargs): - if IS_PY2: - no_command_error = OSError # noqa pylint: disable=undefined-variable,invalid-name - else: - no_command_error = FileNotFoundError # noqa pylint: disable=undefined-variable - pipe = subprocess.PIPE popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)} if '_cwd' in kwargs: @@ -64,11 +59,11 @@ else: try: p = subprocess.Popen(args, **popen_kwargs) result = p.communicate() - except no_command_error: - raise CommandNotFound + except FileNotFoundError as e: + raise CommandNotFound from e exit_code = p.returncode - stdout = ustr(result[0]) + stdout = result[0].decode(DEFAULT_ENCODING) stderr = result[1] # 'sh' does not decode the stderr bytes to unicode full_cmd = '' if args is None else ' '.join(args) |