Skip to main content

Black plugin for the Python LSP Server

Project description

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

To avoid unexpected results you should make sure yapf and autopep8 are not 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.

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.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

python_lsp_black-1.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file python-lsp-black-1.2.0.tar.gz.

File metadata

  • Download URL: python-lsp-black-1.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for python-lsp-black-1.2.0.tar.gz
Algorithm Hash digest
SHA256 135ed1af3a14463cf5b6bb5fff4f95c6da5a030e9192ab042ca63febcb0af9d4
MD5 b4423b760997fd74f3f96a152af7a3a1
BLAKE2b-256 16bc823a9261e3d5e27aa863b0d22108b17424694521a724cbe66d20d6be975e

See more details on using hashes here.

Provenance

File details

Details for the file python_lsp_black-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_lsp_black-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for python_lsp_black-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db96cf962685f33c6e026e67050c4a2f9ae8a970dd4b21e144d0c716d069044c
MD5 ac28b694af732783aae9fb6058443127
BLAKE2b-256 40f3fc0caa4cd6f2d6f3cab656f6063230b38da9747e8f025b494247fa9ad89c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page