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

sublack

by jgirardet ST3

Black integration in SublimeText

Details

Installs

  • Total 8K
  • Win 2K
  • Mac 4K
  • Linux 2K
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 Jun 23 Jun 22 Jun 21
Windows 3 3 3 4 3 3 5 3 6 3 1 3 4 2 8 4 2 0 2 4 6 6 5 3 1 1 5 3 2 3 3 3 4 1 3 0 2 5 1 3 3 4 3 7 4 1
Mac 4 13 11 0 0 4 9 7 5 5 3 0 6 9 5 7 6 5 1 7 3 4 4 6 1 2 8 4 4 6 4 5 5 5 5 2 5 7 5 2 9 9 13 13 4 7
Linux 2 5 2 3 4 2 1 3 1 6 3 1 3 4 10 6 5 3 0 4 2 5 5 0 3 1 10 5 11 3 5 1 1 9 5 9 6 8 7 3 3 5 4 4 8 2

Readme

Source
raw.​githubusercontent.​com
/readmes/img/83e009b6139b4e15b8734f5e9b24c0891f5ae44c.svg /readmes/img/9c24e3c6721e16f48702503d6759873a061495e1.svg

sublack

Black integration for SublimeText

Table Of content

Installation | Usage | Blackd mode | Pre-commit integration | Settings | Code folding | Sublime Linter integration | Issues | Thanks | Changelog | Contributing | Authors

Installation

  1. Install Black min (19.3b0) (if you haven't already):

    pip install black # Requires python 3.6
    or pip install black[d] # for blackd support
    
  2. In PackageControl just find sublack, and that's it!

or

Without PackageControl install manually by navigating to Sublime's Packages folder and cloning this repository:

git clone https://github.com/jgirardet/sublack.git

Usage

  • Run Black on the current file:

    Press Ctrl-Alt-B to format the entire file. You can also Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Format file.

  • Run Black with --diff:

    Press Ctrl-Alt-Shift-B will show diff in a new tab. You can also Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Diff file.

  • Toggle Black on save for current view :

    Press Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Toggle black on save for current view.

  • run Black Format All :

    Press Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Format All. Run black against each root folder in a standard way (without taking care of sublack options and configuration). Same thing as running black . being in the folder.

  • Start Blackd Server :

    Press Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Start BlackdServer.

  • Stop Blackd Server :

    Press Ctrl-Shift-P (Mac: Cmd-Shift-P) and select Sublack: Stop BlackdServer.

Blackd Mode

Sublack supports blackd. If option black_use_blackd is to true, Sublack will use blackd (and not black) according to the 'host' and 'port' configuration.

You can run blackd from SublimeText manually via Start Blackd Server command or automatically at SublimeText start via setting black_blackd_autostart to true.

Blackd server started via SublimeText can be stopped manually via the Stop Blackd Server command or automatically at sublime's exit.

Unlike "standalone" blackd, using sublack with blackd will continue to take care of the pyproject file.

Using standard mode ou blackd mode in sublack should always have the same result...or it's a bug :-)

Blackd is faster than Black.

Diff is always run with black.

Pre-commit integration

You can choose to run Black via pre-commit by setting black_use_precommit to true. Sublack settings will be ignored.

Settings

Sublack will always look for settings in the following order:
  • First in a pyproject.toml file
  • Second in the project file: first with sublack prefix then in a subsetting (see Project settings).
  • Then in Users global settings
  • Finally in Sublack's default settings

Global settings

Preferences -> Package Settings -> sublack -> settings :

Black specifics options

  • black_line_length:

    Set custom line length option used by Black. Default = null which lets black default.

  • black_fast:

    Black fast mode. default is false.

  • black_skip_string_normalization:

    Don't normalize string quotes or prefixes. Default = false.

  • black_py36[Deprecated]:

    Force use of python 3.6 only syntax. The default is Black-s default.

  • black_target_version:

    Python versions that should be supported by Black's output. You should enter it as a list ex : ["py37"]

Sublack specifics options

  • black_command:

    Set custom location. Default = "black".

  • black_on_save:

    Black is always run before saving the file. Default = false.

  • black_log:

    Show non error messages in console. Default = info.

  • black_default_encoding:

    Should not be changed. Only needed on some OSX platforms.

  • black_use_blackd:

    Use blackd instead of black. Default = false.

  • black_blackd_server_host:

    default = "localhost",

  • black_blackd_port:

    default = "45484"

  • black_blackd_autostart:

    Automatically run blackd in the background wen sublime starts. default is false.

  • black_use_precommit:

    run black via pre-commit hook.

  • black_confirm_formatall:

    Popup confirmation dialog before format_all command. default = true.

Project settings

Just add sublack as prefix (recommended):

{
    "settings": {
        "sublack.black_on_save": true
    }
}

A sublack subsettings is still possible:

{
    "settings": {
        "sublack": {
            "black_on_save": true
        }
    }
}

pyproject.toml settings

Sublack supports the use of black configuration in pyproject.toml. Be aware that global/project settings will BE OVERRIDDEN by pyproject.toml's settings. Sublack will look for this file in your project directory then in your root folder(s). See black about pyproject.toml .

Code folding

Sublack tries to keep code folding as before reformatting. SublimeText only supports python3.3 syntax. For newer syntax (ex await/async), you have to set the python_interpreter setting.

{
    "settings": {
        "python_interpreter": "/path/to/my/python/virtualenv/bin/python"
    }
}

Sublime Linter integration

You can install SublimeLinter-addon-black-for-flake. The plugin will auto-configure flake8 and mute all warnings black can actually fix.

Issues

If there is something wrong with this plugin, add an issue on GitHub and I'll try to address it.

Thanks

This plugin is very inspired by the very good PyYapf Plugin. Thanks to Jason Kane.

Changelog

see install.txt

Contributing

  • remove sublack via Package Control.
  • fork sublack
  • clone your sublack fork to your Packages folder (Preferences --> Browse Packages...).
  • Package Control: Satisfy Dependencies (install requests)
  • install UnitTesting in Package Control
  • adding a test for new features or bugfix is really nice if you can.
  • add your name to Authors in the readme.

Authors

Laboriously coded by Jimmy Girardet

Contributions by:

Todo

  • cors
  • refactor popen