Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

python-lsp-server plugin that adds support to black autoformatter, forked fromhttps://github.com/rupert/pyls-black/

License

NotificationsYou must be signed in to change notification settings

python-lsp/python-lsp-black

Repository files navigation

PyPICode style: blackPython

Black plugin for thePython LSP Server.

Install

In the samevirtualenv aspython-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'spyproject.toml if it has one.
  • python-lsp-black only officially supports the latest stable version ofblack. An effort is made to keep backwards-compatibilitybut older black versions will not be actively tested.
  • The plugin can cache the black configuration that applies to each Python file, thisimproves performance of the plugin. When configuration caching is enabled any changes toblack's configuration will need the LSP server to be restarted. Configuration cachingcan be disabled with thecache_config option, seeConfiguration below.

Configuration

The plugin followspython-lsp-server'sconfiguration. These arethe 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 (seeUsage).false by default.
  • pylsp.plugins.black.line_length: an integer that maps toblack'smax-line-lengthsetting. Defaults to 88 (same as black's default). This can also be set through black'sconfiguration files, which should be preferred for multi-user projects.
  • pylsp.plugins.black.preview: a boolean to enable or disableblack's--previewsetting.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'sskip-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/activatepip install -e .[dev]

This project usespre-commit hooks to control code quality,install them to run automatically when creating a git commit, thus avoiding seeing errorswhen you create a pull request:

pre-commit install

To run tests:

maketest

To run linters:

make lint# just a shortcut to pre-commit run -amake<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

About

python-lsp-server plugin that adds support to black autoformatter, forked fromhttps://github.com/rupert/pyls-black/

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors22


[8]ページ先頭

©2009-2025 Movatter.jp