示例#1
0
    def exec_with_wrapper(exec_with, install_dir, cmd_list):
        '''Wrapper function for inserting the execution wrapper, e.g., 'cabal exec' or 'stack exec'

        :returns: Process object from ProcHelper.
        '''

        proc_args = {}
        if exec_with is not None:
            if exec_with == 'cabal':
                cmd_list = ['cabal', 'exec'] + cmd_list
                cmd_list.insert(3, '--')
            elif exec_with == 'stack':
                cmd_list = ['stack', 'exec'] + cmd_list
                cmd_list.insert(3, '--')
            else:
                errmsg = 'HsDevBackend.exec_with_wrapper: Unknown execution prefix \'{0}\''.format(
                    exec_with)
                raise RuntimeError(errmsg)

            if install_dir is not None:
                proc_args['cwd'] = Utils.normalize_path(install_dir)
        else:
            cmd = Which.which(cmd_list[0],
                              ProcHelper.ProcHelper.get_extended_path())
            if cmd is not None:
                cmd_list[0] = cmd

        Logging.log('HsDevBackend.exec_with_wrapper: {0}'.format(cmd_list),
                    Logging.LOG_DEBUG)
        return ProcHelper.ProcHelper(cmd_list, **proc_args)
    def __init__(self, command, **popen_kwargs):
        """Open a pipe to a command or tool."""

        if ProcHelper.augmented_path is None:
            ProcHelper.augmented_path = ProcHelper.make_augmented_path()

        ## Necessary evil: Don't cache the environment, just update the PATH in the current environment.
        ## Why? Because someone could (like me) change os.environ via the ST console and those changes
        ## would never make it here. Use case: settting $http_proxy so that stack can fetch packages.
        proc_env = dict(os.environ)
        proc_env['PATH'] = ProcHelper.augmented_path + os.pathsep + proc_env.get('PATH', '')

        self.process = None
        self.process_err = None

        if Utils.is_windows():
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            popen_kwargs['startupinfo'] = startupinfo

        # Allow caller to specify something different for stdout or stderr -- provide
        # the default here if unspecified.
        popen_kwargs['stdout'] = popen_kwargs.get('stdout', subprocess.PIPE)
        popen_kwargs['stderr'] = popen_kwargs.get('stderr', subprocess.PIPE)

        try:
            normcmd = Which.which(command, proc_env['PATH'])
            if normcmd is not None:
                self.process = subprocess.Popen(normcmd, stdin=subprocess.PIPE, env=proc_env, **popen_kwargs)
            else:
                self.process = None
                self.process_err = "SublimeHaskell.ProcHelper: {0} was not found on PATH!".format(command[0])

        except OSError as os_exc:
            self.process_err = \
                '\n'.join(["SublimeHaskell: Problem executing '{0}'".format(' '.join(command))
                           , 'Operating system error: {0}'.format(os_exc)
                          ])

            if os_exc.errno == errno.EPIPE:
                # Most likely reason: subprocess output a usage message
                stdout, stderr = self.process.communicate()
                exit_code = self.process.wait()
                self.process_err = self.process_err + \
                    '\n'.join([''
                               , 'Process exit code: {0}'.format(exit_code)
                               , ''
                               , "output:"
                               , stdout if stdout else "--no output--"
                               , ''
                               , 'error:'
                               , stderr if stderr else "--no error output--"])
                self.process = None
            else:
                self.process = None
                raise os_exc
def exec_with_wrapper(exec_with, install_dir, cmd_list):
    '''Wrapper function for inserting the execution wrapper, e.g., 'cabal exec' or 'stack exec'

    :returns: Process object from ProcHelper.
    '''

    proc_args = {}
    if exec_with is not None:
        cmd_list = exec_wrapper_cmd(exec_with, cmd_list)
        if install_dir is not None:
            proc_args['cwd'] = Utils.normalize_path(install_dir)
        else:
            raise RuntimeError('ProcHelper.exec_with_wrapper: invalid install_dir (None)')
    else:
        cmd = Which.which(cmd_list[0], ProcHelper.get_extended_path())
        if cmd is not None:
            cmd_list[0] = cmd

    Logging.log('ProcHelper.exec_with_wrapper: {0} in {1}'.format(cmd_list, proc_args.get('cwd')), Logging.LOG_DEBUG)
    return ProcHelper(cmd_list, **proc_args)
示例#4
0
def exec_with_wrapper(exec_with, install_dir, cmd_list):
    '''Wrapper function for inserting the execution wrapper, e.g., 'cabal exec' or 'stack exec'

    :returns: Process object from ProcHelper.
    '''

    proc_args = {}
    if exec_with is not None:
        cmd_list = exec_wrapper_cmd(exec_with, cmd_list)
        if install_dir is not None:
            proc_args['cwd'] = Utils.normalize_path(install_dir)
    else:
        cmd = Which.which(cmd_list[0], ProcHelper.get_extended_path())
        if cmd is not None:
            cmd_list[0] = cmd

    Logging.log(
        'ProcHelper.exec_with_wrapper: {0} in {1}'.format(
            cmd_list, proc_args.get('cwd')), Logging.LOG_DEBUG)
    return ProcHelper(cmd_list, **proc_args)
示例#5
0
 def is_available(**_kwargs):
     return Which.which('ghc-mod',
                        ProcHelper.ProcHelper.get_extended_path())
示例#6
0
    def __init__(self, command, **popen_kwargs):
        """Open a pipe to a command or tool."""

        if ProcHelper.augmented_path is None:
            ProcHelper.augmented_path = ProcHelper.make_augmented_path()

        ## Necessary evil: Don't cache the environment, just update the PATH in the current environment.
        ## Why? Because someone could (like me) change os.environ via the ST console and those changes
        ## would never make it here. Use case: settting $http_proxy so that stack can fetch packages.
        proc_env = dict(os.environ)
        proc_env[
            'PATH'] = ProcHelper.augmented_path + os.pathsep + proc_env.get(
                'PATH', '')

        self.process = None
        self.process_err = None

        if Utils.is_windows():
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            popen_kwargs['startupinfo'] = startupinfo

        # Allow caller to specify something different for stdout or stderr -- provide
        # the default here if unspecified.
        popen_kwargs['stdout'] = popen_kwargs.get('stdout', subprocess.PIPE)
        popen_kwargs['stderr'] = popen_kwargs.get('stderr', subprocess.PIPE)

        try:
            normcmd = Which.which(command, proc_env['PATH'])
            if normcmd is not None:
                self.process = subprocess.Popen(normcmd,
                                                stdin=subprocess.PIPE,
                                                env=proc_env,
                                                **popen_kwargs)
            else:
                self.process = None
                self.process_err = "SublimeHaskell.ProcHelper: {0} was not found on PATH!".format(
                    command[0])

        except OSError as os_exc:
            self.process_err = \
                '\n'.join(["SublimeHaskell: Problem executing '{0}'".format(' '.join(command))
                           , 'Operating system error: {0}'.format(os_exc)
                          ])

            if os_exc.errno == errno.EPIPE:
                # Most likely reason: subprocess output a usage message
                stdout, stderr = self.process.communicate()
                exit_code = self.process.wait()
                self.process_err = self.process_err + \
                    '\n'.join([''
                               , 'Process exit code: {0}'.format(exit_code)
                               , ''
                               , "output:"
                               , stdout if stdout else "--no output--"
                               , ''
                               , 'error:'
                               , stderr if stderr else "--no error output--"])
                self.process = None
            else:
                self.process = None
                raise os_exc