Black plugin for the Python LSP Server
Project description
python-lsp-black
Black plugin for the Python LSP Server.
Install
In the same virtualenv
as python-lsp-server
:
pip install python-lsp-black
Usage
This plugin will disable the yapf and autopep8 plugins if installed.
python-lsp-black
can either format an entire file or just the selected text.- The code will only be formatted if it is syntactically valid Python.
- Text selections are treated as if they were a separate Python file. Unfortunately this means you can't format an indented block of code.
python-lsp-black
will use your project's pyproject.toml if it has one.python-lsp-black
only officially supports the latest stable version of black. An effort is made to keep backwards-compatibility but older black versions will not be actively tested.- The plugin can cache the black configuration that applies to each Python file, this
improves performance of the plugin. When configuration caching is enabled any changes to
black's configuration will need the LSP server to be restarted. Configuration caching
can be disabled with the
cache_config
option, see Configuration below.
Configuration
The plugin follows python-lsp-server's configuration. These are the valid configuration keys:
pylsp.plugins.black.enabled
: boolean to enable/disable the plugin.pylsp.plugins.black.cache_config
: a boolean to enable black configuration caching (see Usage).false
by default.pylsp.plugins.black.line_length
: an integer that maps to black'smax-line-length
setting. Defaults to 88 (same as black's default). This can also be set through black's configuration files, which should be preferred for multi-user projects.pylsp.plugins.black.preview
: a boolean to enable or disable black's--preview
setting.
Development
To install the project for development you need to specify the dev optional dependencies:
python -m venv .venv
. .venv/bin/activate
pip install -e .[dev]
This project uses pre-commit hooks to control code quality, install them to run automatically when creating a git commit, thus avoiding seeing errors when you create a pull request:
pre-commit install
To run tests:
make test
To run linters:
make lint # just a shortcut to pre-commit run -a
make <linter_name> # black, flake8, isort, mypy
To upgrade the version of the pre-commit hooks:
pre-commit autoupdate
# check and git commit changes to .pre-commit-config.yaml
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-lsp-black-1.3.0.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for python_lsp_black-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f583b4395d8d048885974095088ab81e36e501de369cc49a621a82473bb9070 |
|
MD5 | 58aa5661b91db56bc39955ad568ff214 |
|
BLAKE2b-256 | b040a9d58ff8ed0fc202ea488675eba8179e4a895c408d4289c919f759122635 |