# Path: qa/utils.py
# USE_SH_LIB = use_sh_library()
# 
# DEFAULT_ENCODING = getpreferredencoding()


import subprocess
from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
    from sh import git, echo, gitlint  # pylint: disable=unused-import,no-name-in-module,import-error
    from sh import CommandNotFound, ErrorReturnCode, RunningCommand  # pylint: disable=import-error
        return run_command("echo", *command_parts, **kwargs)

    def gitlint(*command_parts, **kwargs):
        return run_command("gitlint", *command_parts, **kwargs)

    def run_command(command, *args, **kwargs):
        args = [command] + list(args)
        result = _exec(*args, **kwargs)
        # If we reach this point and the result has an exit_code that is larger than 0, this means that we didn't
        # get an exception (which is the default sh behavior for non-zero exit codes) and so the user is expecting
        # a non-zero exit code -> just return the entire result
        if hasattr(result, 'exit_code') and result.exit_code > 0:
            return result
        return str(result)

    def _exec(*args, **kwargs):
        pipe = subprocess.PIPE
        popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)}
        if '_cwd' in kwargs:
            popen_kwargs['cwd'] = kwargs['_cwd']
        if '_env' in kwargs:
            popen_kwargs['env'] = kwargs['_env']

        try:
            with subprocess.Popen(args, **popen_kwargs) as p:
                result = p.communicate()
        except FileNotFoundError as exc:
            raise CommandNotFound from exc

        exit_code = p.returncode

# Path: qa/utils.py
# USE_SH_LIB = use_sh_library()
# 
# DEFAULT_ENCODING = getpreferredencoding()


# Path: qa/shell.py
import subprocess
from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
    from sh import git, echo, gitlint  # pylint: disable=unused-import,no-name-in-module,import-error
    from sh import CommandNotFound, ErrorReturnCode, RunningCommand  # pylint: disable=import-error

        return run_command("echo", *command_parts, **kwargs)

    def gitlint(*command_parts, **kwargs):
        return run_command("gitlint", *command_parts, **kwargs)

    def run_command(command, *args, **kwargs):
        args = [command] + list(args)
        result = _exec(*args, **kwargs)
        # If we reach this point and the result has an exit_code that is larger than 0, this means that we didn't
        # get an exception (which is the default sh behavior for non-zero exit codes) and so the user is expecting
        # a non-zero exit code -> just return the entire result
        if hasattr(result, 'exit_code') and result.exit_code > 0:
            return result
        return str(result)

    def _exec(*args, **kwargs):
        pipe = subprocess.PIPE
        popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)}
        if '_cwd' in kwargs:
            popen_kwargs['cwd'] = kwargs['_cwd']
        if '_env' in kwargs:
            popen_kwargs['env'] = kwargs['_env']

        try:
            with subprocess.Popen(args, **popen_kwargs) as p:
                result = p.communicate()
        except FileNotFoundError as exc:
            raise CommandNotFound from exc

        exit_code = p.returncode

        stdout = result[0].decode(DEFAULT_ENCODING)