summaryrefslogtreecommitdiffstats
path: root/gitlint/shell.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:07:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:07:45 +0000
commit5f208e04c159791e668031a7fa83f98724ec8d24 (patch)
tree4b58b42fd2a91a14871010e2dd39369a839ae383 /gitlint/shell.py
parentAdding upstream version 0.13.1. (diff)
downloadgitlint-222ef16bc3e4db460c53d260b1af09254a55002f.tar.xz
gitlint-222ef16bc3e4db460c53d260b1af09254a55002f.zip
Adding upstream version 0.14.0.upstream/0.14.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint/shell.py')
-rw-r--r--gitlint/shell.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/gitlint/shell.py b/gitlint/shell.py
index 965f492..2601b04 100644
--- a/gitlint/shell.py
+++ b/gitlint/shell.py
@@ -2,12 +2,18 @@
"""
This module implements a shim for the 'sh' library, mainly for use on Windows (sh is not supported on Windows).
We might consider removing the 'sh' dependency alltogether in the future, but 'sh' does provide a few
-capabilities wrt dealing with more edge-case environments on *nix systems that might be useful.
+capabilities wrt dealing with more edge-case environments on *nix systems that are useful.
"""
import subprocess
-import sys
-from gitlint.utils import ustr, USE_SH_LIB
+from gitlint.utils import ustr, IS_PY2, USE_SH_LIB
+
+
+def shell(cmd):
+ """ Convenience function that opens a given command in a shell. Does not use 'sh' library. """
+ p = subprocess.Popen(cmd, shell=True)
+ p.communicate()
+
if USE_SH_LIB:
from sh import git # pylint: disable=unused-import,import-error
@@ -21,7 +27,7 @@ else:
class ShResult(object):
""" Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using
- the builtin subprocess. module """
+ the builtin subprocess module """
def __init__(self, full_cmd, stdout, stderr='', exitcode=0):
self.full_cmd = full_cmd
@@ -45,13 +51,13 @@ else:
return _exec(*args, **kwargs)
def _exec(*args, **kwargs):
- if sys.version_info[0] == 2:
+ 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['_tty_out']}
+ popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)}
if '_cwd' in kwargs:
popen_kwargs['cwd'] = kwargs['_cwd']