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

sublack

by jgirardet ST3

Black integration in SublimeText

Details

Installs

  • Total 881
  • Win 185
  • OS X 442
  • Linux 254
Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31
Windows 2 2 2 3 3 1 0 1 1 0 6 1 2 3 5 3 0 2 6 7 4 6 1 1 2 0 3 1 1 3 2 1 2 1 1 3 1 1 5 0 1 1 0 1 0 0
OS X 0 3 10 4 1 6 3 3 2 1 4 3 3 4 4 5 3 9 6 8 13 9 4 3 3 1 1 6 6 2 3 2 3 3 5 7 1 1 1 6 5 6 2 1 1 2
Linux 1 0 3 1 5 6 4 5 1 1 2 5 4 6 4 0 1 2 3 5 8 1 2 2 5 1 1 2 2 5 2 2 4 4 3 3 0 0 3 2 4 5 2 1 0 3

Readme

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

sublack

Black integration for SublimeText

Installation

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

        pip install black # Requires python 3.6
    or pip install blackd # 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 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 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.

Settings

Sublack will always look for settings in the following order:
  • First in a pyproject.toml file
  • Second in 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_skip_numeric_underscore_normalization:

    Don't normalize underscores in numeric literals.

  • black_exclude:

    Regex matching excluded path. Default is Black's default.

  • black_include:

    Regex matching included path. Default is Black's default.

  • black_py36:

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

Sublack specifics options

  • black_command:

    Set custom location. Default = "black".

  • black_on_save:

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

  • black_debug_on:

    Show non error messages in console. Default = false. Error messages are always shown in console.

  • black_default_encoding:

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

  • black_use_blackd:

    Use blackd instead of black. Default is false.

  • black_blackd_server_host:

    default = "localhost",

  • black_blackd_server_port:

    default = "45484"

  • black_blackd_autostart:

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

  • black_use_precommit:

    run black via pre-commit hook.

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 support use of black configuration in pyproject.toml. Be aware that global/project settings will BE OVERRIDEN 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 .

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.

Pre-commit integration

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

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 readme.

Authors

Laboriously coded by Jimmy Girardet

contributions by: