Skip to main content

python-lsp-black

PyPI Code style: black Python

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's max-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. false by default.
  • pylsp.plugins.black.skip_string_normalization: a boolean to enable or disable black's --skip-string-normalization setting. false by default.
  • pylsp.plugins.black.skip_magic_trailing_comma: a boolean to enable or disable black's skip-magic-trailing-comma setting. false by default.

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

Release files for python-lsp-black 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-lsp-black 2.0.0
File Size Uploaded
python-lsp-black-2.0.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-lsp-black 2.0.0
File Interpreter ABI Platform
python_lsp_black-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / python-lsp-black-2.0.0.tar.gz

Download URL python-lsp-black-2.0.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8286d2d310c566844b3c116b824ada6fccfa6ba228b1a09a0526b74c04e0805f
BLAKE2b-256 checksum
How to use checksums
c04806edc947f711fb076b564ee97bbecb5ae877816ccc0edf4347f57cd9d6b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / python_lsp_black-2.0.0-py3-none-any.whl

Download URL python_lsp_black-2.0.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5efdee45f5fa9e5241f5d4d396cd46127f45c85817916b1fd92c2986652bf7e
BLAKE2b-256 checksum
How to use checksums
7844fef9b4d027b3d6321e6f30b6b5946bef18cd84a96e1d81012ac0f69ea53c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page