summaryrefslogtreecommitdiffstats
path: root/qa/shell.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-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)