rupert / pyls-black

Black plugin for the Python Language Server
MIT License
72 stars 8 forks source link

Sublime text support #14

Open guillaumerenault opened 5 years ago

guillaumerenault commented 5 years ago

How can I install it in sublime text using the following LSP + pyls setup:

Thank you.

oskaritimperi commented 4 years ago

These instructions are for Windows environment, but you should be able to use them without too much difficulty on other platforms.

Use pipx (https://pipxproject.github.io/pipx/) to install python-language-server:

pipx install python-language-server

Use pipx to install additional packages in the same virtualenv as python-language-server:

pipx inject python-language-server black pyls-black

Make sure the %USERPROFILE%\.local\bin is in PATH so that pyls command can be found by the LSP plugin.

Install the LSP Sublime plugin.

Open project settings (Project -> Edit Project). Make sure you have something like this in there to make pyls aware of your project specific virtual environment:

{
    "settings":
    {
        "LSP":
        {
            "pyls":
            {
                "enabled": true,
                "env": {
                    "VIRTUAL_ENV": "C:\\path\\to\\your\\project\\venv"
                }
            }
        }
    }
}

The key is to have python-language-server and pyls-black in the same virtual environment. I also have pyls-isort installed in the same environment so that imports are automatically sorted when formatting.