summaryrefslogtreecommitdiffstats
path: root/gitlint/shell.py
diff options
context:
space:
mode:
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']