Exemplo n.º 1
0
    def __init__(self, parent):
        QObject.__init__(self)
        self.main = parent

        self.clients = {}
        self.requests = {}
        self.register_queue = {}
        self.python_config = PYTHON_CONFIG.copy()

        # Register languages to create clients for
        for language in self.get_languages():
            self.clients[language] = {
                'status': self.STOPPED,
                'config': self.get_language_config(language),
                'instance': None
            }
            self.register_queue[language] = []
Exemplo n.º 2
0
    def generate_python_config(self):
        """
        Update Python server configuration with the options saved in our
        config system.
        """
        python_config = PYTHON_CONFIG.copy()

        # Server options
        cmd = self.get_option('advanced/module')
        host = self.get_option('advanced/host')
        port = self.get_option('advanced/port')

        # Pycodestyle
        cs_exclude = self.get_option('pycodestyle/exclude').split(',')
        cs_filename = self.get_option('pycodestyle/filename').split(',')
        cs_select = self.get_option('pycodestyle/select').split(',')
        cs_ignore = self.get_option('pycodestyle/ignore').split(',')
        cs_max_line_length = self.get_option('pycodestyle/max_line_length')

        pycodestyle = {
            'enabled': self.get_option('pycodestyle'),
            'exclude': [exclude.strip() for exclude in cs_exclude if exclude],
            'filename':
            [filename.strip() for filename in cs_filename if filename],
            'select': [select.strip() for select in cs_select if select],
            'ignore': [ignore.strip() for ignore in cs_ignore if ignore],
            'hangClosing': False,
            'maxLineLength': cs_max_line_length
        }

        # Linting - Pyflakes
        pyflakes = {'enabled': self.get_option('pyflakes')}

        # Pydocstyle
        convention = self.get_option('pydocstyle/convention')

        if convention == 'Custom':
            ds_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_select = self.get_option('pydocstyle/select').split(',')
            ds_add_ignore = []
            ds_add_select = []
        else:
            ds_ignore = []
            ds_select = []
            ds_add_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_add_select = self.get_option('pydocstyle/select').split(',')

        pydocstyle = {
            'enabled': self.get_option('pydocstyle'),
            'convention': convention,
            'addIgnore':
            [ignore.strip() for ignore in ds_add_ignore if ignore],
            'addSelect':
            [select.strip() for select in ds_add_select if select],
            'ignore': [ignore.strip() for ignore in ds_ignore if ignore],
            'select': [select.strip() for select in ds_select if select],
            'match': self.get_option('pydocstyle/match'),
            'matchDir': self.get_option('pydocstyle/match_dir')
        }

        # Jedi configuration
        if self.get_option('default', section='main_interpreter'):
            environment = None
        else:
            environment = self.get_option('custom_interpreter',
                                          section='main_interpreter')
        jedi = {
            'environment':
            environment,
            'extra_paths':
            self.get_option('spyder_pythonpath', section='main', default=[]),
        }
        jedi_completion = {
            'enabled': self.get_option('code_completion'),
            'include_params': self.get_option('code_snippets')
        }
        jedi_signature_help = {
            'enabled': self.get_option('jedi_signature_help')
        }
        jedi_definition = {
            'enabled': self.get_option('jedi_definition'),
            'follow_imports': self.get_option('jedi_definition/follow_imports')
        }

        # Advanced
        external_server = self.get_option('advanced/external')
        stdio = self.get_option('advanced/stdio')

        # Setup options in json
        python_config['cmd'] = cmd
        if host in self.LOCALHOST and not stdio:
            python_config['args'] = ('--host {host} --port {port} --tcp '
                                     '--check-parent-process')
        else:
            python_config['args'] = '--check-parent-process'
        python_config['external'] = external_server
        python_config['stdio'] = stdio
        python_config['host'] = host
        python_config['port'] = port

        plugins = python_config['configurations']['pyls']['plugins']
        plugins['pycodestyle'].update(pycodestyle)
        plugins['pyflakes'].update(pyflakes)
        plugins['pydocstyle'].update(pydocstyle)
        plugins['jedi'].update(jedi)
        plugins['jedi_completion'].update(jedi_completion)
        plugins['jedi_signature_help'].update(jedi_signature_help)
        plugins['jedi_definition'].update(jedi_definition)
        plugins['preload']['modules'] = self.get_option('preload_modules')

        return python_config
Exemplo n.º 3
0
    def generate_python_config(self):
        """
        Update Python server configuration with the options saved in our
        config system.
        """
        python_config = PYTHON_CONFIG.copy()

        # Server options
        cmd = self.get_option('advanced/command_launch')
        host = self.get_option('advanced/host')
        port = self.get_option('advanced/port')

        # Pycodestyle
        cs_exclude = self.get_option('pycodestyle/exclude').split(',')
        cs_filename = self.get_option('pycodestyle/filename').split(',')
        cs_select = self.get_option('pycodestyle/select').split(',')
        cs_ignore = self.get_option('pycodestyle/ignore').split(',')
        cs_max_line_length = self.get_option('pycodestyle/max_line_length')

        pycodestyle = {
            'enabled': self.get_option('pycodestyle'),
            'exclude': [exclude.strip() for exclude in cs_exclude if exclude],
            'filename':
            [filename.strip() for filename in cs_filename if filename],
            'select': [select.strip() for select in cs_select if select],
            'ignore': [ignore.strip() for ignore in cs_ignore if ignore],
            'hangClosing': False,
            'maxLineLength': cs_max_line_length
        }

        # Linting - Pyflakes
        pyflakes = {'enabled': self.get_option('pyflakes')}

        # Pydocstyle
        convention = self.get_option('pydocstyle/convention')

        if convention == 'Custom':
            ds_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_select = self.get_option('pydocstyle/select').split(',')
            ds_add_ignore = []
            ds_add_select = []
        else:
            ds_ignore = []
            ds_select = []
            ds_add_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_add_select = self.get_option('pydocstyle/select').split(',')

        pydocstyle = {
            'enabled': self.get_option('pydocstyle'),
            'convention': convention,
            'addIgnore':
            [ignore.strip() for ignore in ds_add_ignore if ignore],
            'addSelect':
            [select.strip() for select in ds_add_select if select],
            'ignore': [ignore.strip() for ignore in ds_ignore if ignore],
            'select': [select.strip() for select in ds_select if select],
            'match': self.get_option('pydocstyle/match'),
            'matchDir': self.get_option('pydocstyle/match_dir')
        }

        # Code completion
        jedi_completion = {
            'enabled': self.get_option('code_completion'),
            'include_params': False
        }

        jedi_signature_help = {
            'enabled': self.get_option('jedi_signature_help')
        }

        jedi_definition = {
            'enabled': self.get_option('jedi_definition'),
            'follow_imports': self.get_option('jedi_definition/follow_imports')
        }

        # Advanced
        external_server = self.get_option('advanced/external')
        stdio = self.get_option('advanced/stdio')

        # Setup options in json
        python_config['cmd'] = cmd
        if host in self.LOCALHOST and not stdio:
            python_config['args'] = '--host {host} --port {port} --tcp'
        else:
            python_config['args'] = ''
        python_config['external'] = external_server
        python_config['stdio'] = stdio
        python_config['host'] = host
        python_config['port'] = port

        plugins = python_config['configurations']['pyls']['plugins']
        plugins['pycodestyle'] = pycodestyle
        plugins['pyflakes'] = pyflakes
        plugins['pydocstyle'] = pydocstyle
        plugins['jedi_completion'] = jedi_completion
        plugins['jedi_signature_help'] = jedi_signature_help
        plugins['preload']['modules'] = self.get_option('preload_modules')
        plugins['jedi_definition'] = jedi_definition

        return python_config
Exemplo n.º 4
0
    def generate_python_config(self):
        """
        Update Python server configuration with the options saved in our
        config system.
        """
        python_config = PYTHON_CONFIG.copy()

        # Server options
        cmd = self.get_conf('advanced/module', 'pylsp')
        host = self.get_conf('advanced/host', '127.0.0.1')
        port = self.get_conf('advanced/port', 2087)

        # Pycodestyle
        cs_exclude = self.get_conf('pycodestyle/exclude', '').split(',')
        cs_filename = self.get_conf('pycodestyle/filename', '').split(',')
        cs_select = self.get_conf('pycodestyle/select', '').split(',')
        cs_ignore = self.get_conf('pycodestyle/ignore', '').split(',')
        cs_max_line_length = self.get_conf('pycodestyle/max_line_length', 79)

        pycodestyle = {
            'enabled': self.get_conf('pycodestyle'),
            'exclude': [exclude.strip() for exclude in cs_exclude if exclude],
            'filename':
            [filename.strip() for filename in cs_filename if filename],
            'select': [select.strip() for select in cs_select if select],
            'ignore': [ignore.strip() for ignore in cs_ignore if ignore],
            'hangClosing': False,
            'maxLineLength': cs_max_line_length
        }

        # Linting - Pyflakes
        pyflakes = {'enabled': self.get_conf('pyflakes')}

        # Pydocstyle
        convention = self.get_conf('pydocstyle/convention')

        if convention == 'Custom':
            ds_ignore = self.get_conf('pydocstyle/ignore', '').split(',')
            ds_select = self.get_conf('pydocstyle/select', '').split(',')
            ds_add_ignore = []
            ds_add_select = []
        else:
            ds_ignore = []
            ds_select = []
            ds_add_ignore = self.get_conf('pydocstyle/ignore', '').split(',')
            ds_add_select = self.get_conf('pydocstyle/select', '').split(',')

        pydocstyle = {
            'enabled': self.get_conf('pydocstyle'),
            'convention': convention,
            'addIgnore':
            [ignore.strip() for ignore in ds_add_ignore if ignore],
            'addSelect':
            [select.strip() for select in ds_add_select if select],
            'ignore': [ignore.strip() for ignore in ds_ignore if ignore],
            'select': [select.strip() for select in ds_select if select],
            'match': self.get_conf('pydocstyle/match'),
            'matchDir': self.get_conf('pydocstyle/match_dir')
        }

        # Autoformatting configuration
        formatter = self.get_conf('formatting')
        formatter = 'pyls_black' if formatter == 'black' else formatter
        formatters = ['autopep8', 'yapf', 'pyls_black']
        formatter_options = {
            fmt: {
                'enabled': fmt == formatter
            }
            for fmt in formatters
        }

        if formatter == 'pyls_black':
            formatter_options['pyls_black']['line_length'] = cs_max_line_length

        # PyLS-Spyder configuration
        group_cells = self.get_conf('group_cells', section='outline_explorer')
        display_block_comments = self.get_conf('show_comments',
                                               section='outline_explorer')
        pyls_spyder_options = {
            'enable_block_comments': display_block_comments,
            'group_cells': group_cells
        }

        # Jedi configuration
        if self.get_conf('default', section='main_interpreter'):
            environment = None
            env_vars = None
        else:
            environment = self.get_conf('custom_interpreter',
                                        section='main_interpreter')
            env_vars = os.environ.copy()
            # external interpreter should not use internal PYTHONPATH
            env_vars.pop('PYTHONPATH', None)
            if running_in_mac_app():
                env_vars.pop('PYTHONHOME', None)

        jedi = {
            'environment':
            environment,
            'extra_paths':
            self.get_conf('spyder_pythonpath', section='main', default=[]),
            'env_vars':
            env_vars,
        }
        jedi_completion = {
            'enabled':
            self.get_conf('code_completion'),
            'include_params':
            self.get_conf('enable_code_snippets', section='completions')
        }
        jedi_signature_help = {'enabled': self.get_conf('jedi_signature_help')}
        jedi_definition = {
            'enabled': self.get_conf('jedi_definition'),
            'follow_imports': self.get_conf('jedi_definition/follow_imports')
        }

        # Advanced
        external_server = self.get_conf('advanced/external')
        stdio = self.get_conf('advanced/stdio')

        # Setup options in json
        python_config['cmd'] = cmd
        if host in self.LOCALHOST and not stdio:
            python_config['args'] = ('--host {host} --port {port} --tcp '
                                     '--check-parent-process')
        else:
            python_config['args'] = '--check-parent-process'
        python_config['external'] = external_server
        python_config['stdio'] = stdio
        python_config['host'] = host
        python_config['port'] = port

        plugins = python_config['configurations']['pylsp']['plugins']
        plugins['pycodestyle'].update(pycodestyle)
        plugins['pyflakes'].update(pyflakes)
        plugins['pydocstyle'].update(pydocstyle)
        plugins['pyls_spyder'].update(pyls_spyder_options)
        plugins['jedi'].update(jedi)
        plugins['jedi_completion'].update(jedi_completion)
        plugins['jedi_signature_help'].update(jedi_signature_help)
        plugins['jedi_definition'].update(jedi_definition)
        plugins['preload']['modules'] = self.get_conf('preload_modules')

        for formatter in formatters:
            plugins[formatter] = formatter_options[formatter]

        return python_config
Exemplo n.º 5
0
    def generate_python_config(self):
        """
        Update Python server configuration with the options saved in our
        config system.
        """
        python_config = PYTHON_CONFIG.copy()

        # Server options
        cmd = self.get_option('advanced/command_launch')
        host = self.get_option('advanced/host')
        port = self.get_option('advanced/port')

        # Pycodestyle
        cs_exclude = self.get_option('pycodestyle/exclude').split(',')
        cs_filename = self.get_option('pycodestyle/filename').split(',')
        cs_select = self.get_option('pycodestyle/select').split(',')
        cs_ignore = self.get_option('pycodestyle/ignore').split(',')
        cs_max_line_length = self.get_option('pycodestyle/max_line_length')

        pycodestyle = {
            'enabled': self.get_option('pycodestyle'),
            'exclude': [exclude.strip() for exclude in cs_exclude],
            'filename': [filename.strip() for filename in cs_filename],
            'select': [select.strip() for select in cs_select],
            'ignore': [ignore.strip() for ignore in cs_ignore],
            'hangClosing': False,
            'maxLineLength': cs_max_line_length
        }

        # Linting - Pyflakes
        pyflakes = {
            'enabled': self.get_option('pyflakes')
        }

        # Pydocstyle
        convention = self.get_option('pydocstyle/convention')

        if convention == 'Custom':
            ds_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_select = self.get_option('pydocstyle/select').split(',')
            ds_add_ignore = []
            ds_add_select = []
        else:
            ds_ignore = []
            ds_select = []
            ds_add_ignore = self.get_option('pydocstyle/ignore').split(',')
            ds_add_select = self.get_option('pydocstyle/select').split(',')

        pydocstyle = {
            'enabled': self.get_option('pydocstyle'),
            'convention': convention,
            'addIgnore': [ignore.strip() for ignore in ds_add_ignore],
            'addSelect': [select.strip() for select in ds_add_select],
            'ignore': [ignore.strip() for ignore in ds_ignore],
            'select': [select.strip() for select in ds_select],
            'match': self.get_option('pydocstyle/match'),
            'matchDir': self.get_option('pydocstyle/match_dir')
        }

        # Code completion
        jedi_completion = {
            'enabled': self.get_option('code_completion'),
            'include_params': False
        }

        jedi_signature_help = {
            'enabled': self.get_option('jedi_signature_help')
        }

        jedi_definition = {
            'enabled': self.get_option('jedi_definition'),
            'follow_imports': self.get_option('jedi_definition/follow_imports')
        }

        # Advanced
        external_server = self.get_option('advanced/external')

        # Setup options in json
        python_config['cmd'] = cmd
        if host in self.LOCALHOST:
            python_config['args'] = '--host {host} --port {port} --tcp'
        else:
            python_config['args'] = ''
        python_config['external'] = external_server
        python_config['host'] = host
        python_config['port'] = port

        plugins = python_config['configurations']['pyls']['plugins']
        plugins['pycodestyle'] = pycodestyle
        plugins['pyflakes'] = pyflakes
        plugins['pydocstyle'] = pydocstyle
        plugins['jedi_completion'] = jedi_completion
        plugins['jedi_signature_help'] = jedi_signature_help
        plugins['preload']['modules'] = self.get_option('preload_modules')
        plugins['jedi_definition'] = jedi_definition

        return python_config
Exemplo n.º 6
0
    def generate_python_config(self):
        """
        Update Python server configuration with the options saved in our
        config system.
        """
        python_config = PYTHON_CONFIG.copy()

        # Server options
        cmd = self.get_conf('advanced/module', 'pylsp')
        host = self.get_conf('advanced/host', '127.0.0.1')
        port = self.get_conf('advanced/port', 2087)

        # Pycodestyle
        cs_exclude = self.get_conf('pycodestyle/exclude', '').split(',')
        cs_filename = self.get_conf('pycodestyle/filename', '').split(',')
        cs_select = self.get_conf('pycodestyle/select', '').split(',')
        cs_ignore = self.get_conf('pycodestyle/ignore', '').split(',')
        cs_max_line_length = self.get_conf('pycodestyle/max_line_length', 79)

        pycodestyle = {
            'enabled': self.get_conf('pycodestyle'),
            'exclude': [exclude.strip() for exclude in cs_exclude if exclude],
            'filename':
            [filename.strip() for filename in cs_filename if filename],
            'select': [select.strip() for select in cs_select if select],
            'ignore': [ignore.strip() for ignore in cs_ignore if ignore],
            'hangClosing': False,
            'maxLineLength': cs_max_line_length
        }

        # Linting - Pyflakes
        pyflakes = {'enabled': self.get_conf('pyflakes')}

        # Pydocstyle
        convention = self.get_conf('pydocstyle/convention')

        if convention == 'Custom':
            ds_ignore = self.get_conf('pydocstyle/ignore', '').split(',')
            ds_select = self.get_conf('pydocstyle/select', '').split(',')
            ds_add_ignore = []
            ds_add_select = []
        else:
            ds_ignore = []
            ds_select = []
            ds_add_ignore = self.get_conf('pydocstyle/ignore', '').split(',')
            ds_add_select = self.get_conf('pydocstyle/select', '').split(',')

        pydocstyle = {
            'enabled': self.get_conf('pydocstyle'),
            'convention': convention,
            'addIgnore':
            [ignore.strip() for ignore in ds_add_ignore if ignore],
            'addSelect':
            [select.strip() for select in ds_add_select if select],
            'ignore': [ignore.strip() for ignore in ds_ignore if ignore],
            'select': [select.strip() for select in ds_select if select],
            'match': self.get_conf('pydocstyle/match'),
            'matchDir': self.get_conf('pydocstyle/match_dir')
        }

        # Autoformatting configuration
        formatter = self.get_conf('formatting')

        # This is necessary because PyLSP third-party plugins can only be
        # disabled with their module name.
        formatter = 'pylsp_black' if formatter == 'black' else formatter

        # Enabling/disabling formatters
        formatters = ['autopep8', 'yapf', 'pylsp_black']
        formatter_options = {
            fmt: {
                'enabled': fmt == formatter
            }
            for fmt in formatters
        }

        # Setting max line length for formatters
        # The autopep8 plugin shares the same maxLineLength value with the
        # pycodestyle one. That's why it's not necessary to set it here.
        # NOTE: We need to use `black` and not `pylsp_black` because that's
        # the options' namespace of that plugin.
        formatter_options['black'] = {'line_length': cs_max_line_length}

        # PyLS-Spyder configuration
        group_cells = self.get_conf('group_cells', section='outline_explorer')
        display_block_comments = self.get_conf('show_comments',
                                               section='outline_explorer')
        pyls_spyder_options = {
            'enable_block_comments': display_block_comments,
            'group_cells': group_cells
        }

        # Jedi configuration
        env_vars = os.environ.copy()  # Ensure env is indepependent of PyLSP's
        env_vars.pop('PYTHONPATH', None)
        if self.get_conf('default', section='main_interpreter'):
            # If not explicitly set, jedi uses PyLSP's sys.path instead of
            # sys.executable's sys.path. This may be a bug in jedi.
            environment = sys.executable
        else:
            environment = self.get_conf('executable',
                                        section='main_interpreter')
            # External interpreter cannot have PYTHONHOME
            if running_in_mac_app():
                env_vars.pop('PYTHONHOME', None)

        jedi = {
            'environment':
            environment,
            'extra_paths':
            self.get_conf('spyder_pythonpath', section='main', default=[]),
            'env_vars':
            env_vars,
        }
        jedi_completion = {
            'enabled':
            self.get_conf('code_completion'),
            'include_params':
            self.get_conf('enable_code_snippets', section='completions')
        }
        jedi_signature_help = {'enabled': self.get_conf('jedi_signature_help')}
        jedi_definition = {
            'enabled': self.get_conf('jedi_definition'),
            'follow_imports': self.get_conf('jedi_definition/follow_imports')
        }

        # Advanced
        external_server = self.get_conf('advanced/external')
        stdio = self.get_conf('advanced/stdio')

        # Setup options in json
        python_config['cmd'] = cmd
        if host in self.LOCALHOST and not stdio:
            python_config['args'] = ('--host {host} --port {port} --tcp '
                                     '--check-parent-process')
        else:
            python_config['args'] = '--check-parent-process'
        python_config['external'] = external_server
        python_config['stdio'] = stdio
        python_config['host'] = host
        python_config['port'] = port

        # Updating options
        plugins = python_config['configurations']['pylsp']['plugins']
        plugins['pycodestyle'].update(pycodestyle)
        plugins['pyflakes'].update(pyflakes)
        plugins['pydocstyle'].update(pydocstyle)
        plugins['pyls_spyder'].update(pyls_spyder_options)
        plugins['jedi'].update(jedi)
        plugins['jedi_completion'].update(jedi_completion)
        plugins['jedi_signature_help'].update(jedi_signature_help)
        plugins['jedi_definition'].update(jedi_definition)
        plugins['preload']['modules'] = self.get_conf('preload_modules')
        plugins.update(formatter_options)

        return python_config