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 4K
  • Win 2K
  • Mac 1K
  • Linux 1K
May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1
Windows 7 7 3 13 8 3 8 7 4 4 3 7 9 7 3 4 2 8 14 5 7 7 2 3 3 5 5 5 9 5 6 9 5 10 8 9 4 6 11 4 5 10 6 8 6 5
Mac 3 1 2 7 4 8 5 4 2 4 5 4 7 2 2 0 1 2 4 4 5 2 3 2 3 9 7 3 3 3 2 2 6 5 8 4 3 9 4 5 6 8 3 4 6 1
Linux 2 4 3 8 4 3 4 5 4 2 4 6 7 8 7 3 7 1 5 2 6 6 2 4 8 8 2 5 5 4 6 3 6 7 4 6 5 2 3 5 3 5 1 3 3 7

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.