# 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

# This code is mostly duplicated from the `gitlint.shell` module. We consciously duplicate this code as to not depend
# on gitlint internals for our integration testing framework.


if USE_SH_LIB:
    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
else:

    class CommandNotFound(Exception):
        """ Exception indicating a command was not found during execution """
        pass

    class RunningCommand:
        pass

    class ShResult(RunningCommand):
        """ Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using
        the builtin subprocess module. """

        def __init__(self, full_cmd, stdout, stderr='', exitcode=0):
            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 + stderr.decode(DEFAULT_ENCODING)
            self.stderr = stderr
            self.exit_code = exitcode


# 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


# This code is mostly duplicated from the `gitlint.shell` module. We consciously duplicate this code as to not depend
# on gitlint internals for our integration testing framework.


if USE_SH_LIB:
    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
else:

    class CommandNotFound(Exception):
        """ Exception indicating a command was not found during execution """
        pass

    class RunningCommand:
        pass

    class ShResult(RunningCommand):
        """ Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using
        the builtin subprocess module. """

        def __init__(self, full_cmd, stdout, stderr='', exitcode=0):
            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 + stderr.decode(DEFAULT_ENCODING)
            self.stderr = stderr
            self.exit_code = exitcode


        def __str__(self):