ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

python-black

by thep0y ST4

Black formatter for Sublime Text

Labels formatter

Details

Installs

  • Total 6K
  • Win 2K
  • Mac 2K
  • Linux 1K
Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24
Windows 5 4 6 8 7 13 7 6 5 4 4 6 2 5 7 3 9 2 4 3 4 10 6 7 9 1 7 10 7 6 4 7 10 5 6 7 3 7 5 6 5 5 7 4 12 9
Mac 4 4 3 3 7 6 6 4 2 2 5 8 7 10 2 2 4 8 5 7 6 6 2 9 3 5 4 4 4 3 4 2 7 3 5 3 2 0 4 6 7 5 4 4 4 0
Linux 7 2 0 7 0 5 2 4 1 2 3 7 3 4 5 5 3 1 1 3 5 4 2 3 1 7 2 6 5 4 5 4 4 7 4 6 3 7 3 8 4 5 3 4 4 9

Readme

Source
raw.​githubusercontent.​com

python-black

Black formatter for Sublime Text.

It is recommended to use with LSP-pyright.

Installation

There is no need to install black, but if you install it, it will not affect this package.

You can install python-black with package control:

  1. Open your command pallete and type Package Control: Install Package.
  2. Find this project python-black and press Enter.

Local installation

This package has been uploaded to packagecontrol.io, so you do not need to choose local installation:

git clone https://github.com/thep0y/python-black.git

Copy or move the python-black folder to the packages directory of Sublime Text 4.

Usage

1 Key Binding

You can create custom key binding based on samplePreferences - Package Settings - Python Black - Key Bindings, such as:

{
     "keys": [
         "ctrl+super+l"
     ],
     "command": "black",
     "args": {
        "use_selection": true
     }
}

The optional use_selection boolean (defaults to true) controls whether to format the selected region, or the entire file.

:warning:Note: Do not duplicate the key binding of other packages

2 Settings

There is only one modifiable property in settings:

{
   // Whether to automatically format the entire document when saving
   "format_on_save": true
}

This can also be toggled via Preferences > Package Settings > Python Black > Format On Save.

3 Create Black Configuration File

You can quickly generate a black configuration file for the current project.

Command Description
python-black: Create Black Configuration File Creates a pyproject.toml file in the root of the project with basic options. Opens the configuration file if it already exists.

:warning: If you don't want to generate a pyproject.toml for each project, then you need to create a black global configuration file.

Refer to Black Documentation.

If you want to disable format_on_save in a project that does not use black code style #14, you need to add the configuration to *.sublime-project: json { ... "settings": { ... "python-black": { "format_on_save": false } } }

TODO

  • [ ] format all python files in the current project

If someone likes or gives feedback, some features may be added in the future.