summaryrefslogtreecommitdiffstats
path: root/qa/shell.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:35 +0000
commit4fee3e091a8d79a40f70ff9c1f87b29b9340049a (patch)
tree465ad9629a8ee56548bd6c51c3fc710907564911 /qa/shell.py
parentReleasing debian version 0.14.0-1. (diff)
downloadgitlint-4fee3e091a8d79a40f70ff9c1f87b29b9340049a.tar.xz
gitlint-4fee3e091a8d79a40f70ff9c1f87b29b9340049a.zip
Merging upstream version 0.15.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/shell.py')
-rw-r--r--qa/shell.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/qa/shell.py b/qa/shell.py
index 43e5bbd..97dcd2c 100644
--- a/qa/shell.py
+++ b/qa/shell.py
@@ -3,10 +3,11 @@
# on gitlint internals for our integration testing framework.
import subprocess
-from qa.utils import ustr, USE_SH_LIB, IS_PY2
+from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
if USE_SH_LIB:
from sh import git, echo, gitlint # pylint: disable=unused-import,no-name-in-module,import-error
+ gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True) # pylint: disable=invalid-name
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
from sh import CommandNotFound, ErrorReturnCode, RunningCommand # pylint: disable=import-error
@@ -16,7 +17,7 @@ else:
""" Exception indicating a command was not found during execution """
pass
- class RunningCommand(object):
+ class RunningCommand:
pass
class ShResult(RunningCommand):
@@ -27,7 +28,7 @@ else:
self.full_cmd = full_cmd
# TODO(jorisroovers): The 'sh' library by default will merge stdout and stderr. We mimic this behavior
# for now until we fully remove the 'sh' library.
- self.stdout = stdout + ustr(stderr)
+ self.stdout = stdout + stderr.decode(DEFAULT_ENCODING)
self.stderr = stderr
self.exit_code = exitcode
@@ -55,14 +56,9 @@ else:
# a non-zero exit code -> just return the entire result
if hasattr(result, 'exit_code') and result.exit_code > 0:
return result
- return ustr(result)
+ return str(result)
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:
@@ -73,11 +69,11 @@ else:
try:
p = subprocess.Popen(args, **popen_kwargs)
result = p.communicate()
- except no_command_error:
- raise CommandNotFound
+ except FileNotFoundError as exc:
+ raise CommandNotFound from exc
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)