Lsp: How to set flake8 configurationSources in pyls?

Created on 11 Jan 2018  Â·  3Comments  Â·  Source: sublimelsp/LSP

The python-language-server says:

The default configuration source is pycodestyle. Change the pyls.configurationSources setting to ['flake8'] in order to respect flake8 configuration instead.

How do you set pyls.configurationSources from Sublime Text?

I've tried various different settings e.g:

    "clients": {
        "pyls": {
            "command": [
                "~/.local/bin/pyls",
            ],
            "scopes": ["source.python"],
            "syntaxes": ["Packages/Python/Python.sublime-syntax"],
            "languageId": "python",
            "settings": {
            },
            "initializationOptions": {
                "configurationSources": ["flake8"]
            },
        },
    }

Most helpful comment

For anybody who hits this issue, this is how you configure it:

            "settings": {
                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }

The above says use flake8 configurations, else use pycodestyle configations.

If you interested in the code of those configurations:

You don't have to define both, you can just define one if you like:

            "settings": {
                "pyls": {
                    "configurationSources": ["flake8"],
                }

If you want to debug the python-language-server, you can set verbose flags like this:

        "pyls": {
            "command": [
                "~/.local/bin/pyls",
                "-vvv"
            ],
            "scopes": ["source.python"],
            "syntaxes": ["Packages/Python/Python.sublime-syntax"],
            "languageId": "python",
            "settings": {
                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }
            },
        },

That'll give you extra debug messages from pyls (mine is located in ~/.local/bin/pyls, yours may not be).

There is a bug in pyl where some user configurations are not recognised, but that's not much to do with sublime/LSP and will be fixed, so I'm going to close this issue.

All 3 comments

I think I must be expecting behaviour that python-language-server just doesn't provide.

pyls can be debugged with configs something like:

    "clients": {
        "pyls": {
            "command": [
                "~/.local/bin/pyls",
                "-vvv"
            ],
            "scopes": ["source.python"],
            "syntaxes": ["Packages/Python/Python.sublime-syntax"],
            "languageId": "python",
            "settings": {
                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }
            },
        },
}

As you can probably see, I discovered that if you pass:

                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }

pyls seems to recognise it. It even looks like it might be loading the project configuration as specified by the flake8 configs above: a .flake8 file in the root of the project:

[flake8]
max-line-length = 120

ignore = D100,D101,D102,D103,D104,D105,D107

But in the diagnostics panel I get:

 ◌ lib/file.py:
       14:1     pycodestyle     warning     E302 expected 2 blank lines, found 1
       25:1     pycodestyle     warning     E303 too many blank lines (4)
        1:1     pydocstyle      warning     D100: Missing docstring in public module
       11:1     pydocstyle      warning     D103: Missing docstring in public function
       14:1     pydocstyle      warning     D103: Missing docstring in public function
       18:1     pydocstyle      warning     D103: Missing docstring in public function
      108:1     pydocstyle      warning     D103: Missing docstring in public function
      114:1     pydocstyle      warning     D103: Missing docstring in public function

D100 and D103 should be ignored.

But besides that, I'm expecting flake8 to be used, not pycodestyle or pydocstyle.

For anybody who hits this issue, this is how you configure it:

            "settings": {
                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }

The above says use flake8 configurations, else use pycodestyle configations.

If you interested in the code of those configurations:

You don't have to define both, you can just define one if you like:

            "settings": {
                "pyls": {
                    "configurationSources": ["flake8"],
                }

If you want to debug the python-language-server, you can set verbose flags like this:

        "pyls": {
            "command": [
                "~/.local/bin/pyls",
                "-vvv"
            ],
            "scopes": ["source.python"],
            "syntaxes": ["Packages/Python/Python.sublime-syntax"],
            "languageId": "python",
            "settings": {
                "pyls": {
                    "configurationSources": ["flake8", "pycodestyle"],
                }
            },
        },

That'll give you extra debug messages from pyls (mine is located in ~/.local/bin/pyls, yours may not be).

There is a bug in pyl where some user configurations are not recognised, but that's not much to do with sublime/LSP and will be fixed, so I'm going to close this issue.

Thanks for the research and documentation!

I'm not envious of pyls's need to support so many different linters and respective configurations :)

Was this page helpful?
0 / 5 - 0 ratings