コード例 #1
0
ファイル: server.py プロジェクト: kan-bayashi/deoplete-jedi
    def restart(self):
        """Start or restart the server

        If a server is already running, shut it down.
        """
        with self.restarting:
            self.shutdown()
            log.debug('Starting server process: %s' % (self.cmd_string, ))
            self._server = subprocess.Popen(self.cmd,
                                            stdin=subprocess.PIPE,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE,
                                            env=self.env)
            # Might result in "pyenv: version `foo' is not installed (set by
            # /cwd/.python-version)" on stderr.
            try:
                self.version = stream_read(self._server.stdout)
            except Exception:
                import traceback
                from deoplete.exceptions import SourceInitError
                out, err = self._server.communicate()
                raise SourceInitError(
                    'Server exited with {}. stderr=[{}], cmd={!r}.\n{}'.format(
                        self._server.returncode, err.decode(),
                        ' '.join(self.cmd), traceback.format_exc()))
            self._count = 0
コード例 #2
0
    def __init__(self,
                 desc_len=0,
                 short_types=False,
                 show_docstring=False,
                 debug=False,
                 python_path=None):
        self._server = None
        self.restarting = threading.Lock()
        self.version = (0, 0, 0, 'final', 0)
        self.env = os.environ.copy()
        self.env.update({'PYTHONPATH': self._make_pythonpath()})

        if 'VIRTUAL_ENV' in os.environ:
            prog = os.path.join(self.env['VIRTUAL_ENV'], 'bin', 'python')
        elif python_path:
            prog = python_path
        else:
            prog = 'python'

        self.cmd = [prog, '-u', __file__, '--desc-length', str(desc_len)]
        if short_types:
            self.cmd.append('--short-types')
        if show_docstring:
            self.cmd.append('--docstrings')
        if debug:
            self.cmd.extend(
                ('--debug', debug[0], '--debug-level', str(debug[1])))

        try:
            self.restart()
        except Exception as exc:
            from deoplete.exceptions import SourceInitError
            raise SourceInitError('Failed to start server ({}): {}'.format(
                ' '.join(self.cmd), exc))
コード例 #3
0
ファイル: server.py プロジェクト: kan-bayashi/deoplete-jedi
    def __init__(self,
                 python_path,
                 desc_len=0,
                 short_types=False,
                 show_docstring=False,
                 debug=False):
        self._server = None
        self.restarting = threading.Lock()
        self.version = (0, 0, 0, 'final', 0)
        self.env = os.environ.copy()
        self.env.update({'PYTHONPATH': self._make_pythonpath()})

        self.cmd = [
            python_path, '-u',
            os.path.normpath(__file__), '--desc-length',
            str(desc_len)
        ]
        if short_types:
            self.cmd.append('--short-types')
        if show_docstring:
            self.cmd.append('--docstrings')
        if debug:
            self.cmd.extend(
                ('--debug', debug[0], '--debug-level', str(debug[1])))

        # Handle any exceptions from the first server startup, which might
        # include PermissionDenied for an invalid python_path.
        try:
            self.restart()
        except Exception as exc:
            from deoplete.exceptions import SourceInitError
            raise SourceInitError('Failed to start server ({}): {}'.format(
                self.cmd_string, exc))