diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f4c48c..fad1947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ # v0.33.0 (2018-08-10) - Fixes an issue where Atom Beautify would display a Docker error instead of an executable error ([#2146](https://github.com/Glavin001/atom-beautify/issues/2146)) - Fixes Rubocop not excluding files with an exact pattern match (`db/schema.rb` vs `db/**/*`) +- Add [Black](http://github.com/ambv/black) beautifier for Python. # v0.32.5 (2018-05-28) - Fixes an issue with Rubocop not working on Windows ([#2092](https://github.com/Glavin001/atom-beautify/issues/2092)) diff --git a/README.md b/README.md index a24bd1c..6756c73 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Some of the supported beautifiers are developed for Node.js and are automaticall | align-yaml | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | | autopep8 | :warning: 2 executables | :warning: Only 1 of 2 executables | :whale: With [Docker](https://www.docker.com/):
1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) with `docker pull unibeautify/autopep8`

:bookmark_tabs: Manually:
1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) by following https://github.com/hhatto/autopep8#installation
2. Install [isort (`isort`)](https://github.com/timothycrosley/isort) by following https://github.com/timothycrosley/isort#installing-isort
| | beautysh | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):
1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) with `docker pull unibeautify/beautysh`

:bookmark_tabs: Manually:
1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) by following https://github.com/bemeurer/beautysh#installation
| +| black | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:
1. Install [black (`black`)](https://github.com/ambv/black) by following https://github.com/ambv/black#installation
| | brittany | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to https://github.com/lspitzner/brittany and follow the instructions. | | clang-format | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):
1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) with `docker pull unibeautify/clang-format`

:bookmark_tabs: Manually:
1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) by following https://clang.llvm.org/docs/ClangFormat.html
| | cljfmt | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | @@ -197,7 +198,7 @@ See [all supported options in the documentation at `docs/options.md`](docs/opti | Perl | `Perl`, `Perl 6` |`.pl`, `.PL`, `.pm`, `.pod`, `.t` | **[`Perltidy`](http://perltidy.sourceforge.net/)** | | PHP | `PHP` |`.php`, `.module`, `.inc` | **[`PHP-CS-Fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer)**, [`PHPCBF`](http://php.net/manual/en/install.php), [`hh_format`](http://hhvm.com/) | | Puppet | `Puppet` |`.pp` | **[`puppet-lint`](http://puppet-lint.com/)** | -| Python | `Python`, `MagicPython` |`.py` | **[`autopep8`](https://github.com/hhatto/autopep8)**, [`pybeautifier`](https://github.com/guyskk/pybeautifier), [`yapf`](https://github.com/google/yapf) | +| Python | `Python`, `MagicPython` |`.py` | **[`autopep8`](https://github.com/hhatto/autopep8)**, [`black`](https://github.com/ambv/black), [`pybeautifier`](https://github.com/guyskk/pybeautifier), [`yapf`](https://github.com/google/yapf) | | R | `R` |`.r`, `.R` | **[`formatR`](https://github.com/yihui/formatR)** | | Riot.js | `Riot.js`, `HTML (Riot Tag)` |`.tag` | **[`Pretty Diff`](https://github.com/prettydiff/prettydiff)** | | Ruby | `Ruby`, `Ruby on Rails` |`.rb` | **[`Rubocop`](https://github.com/bbatsov/rubocop)**, [`Ruby Beautify`](https://github.com/erniebrodeur/ruby-beautify) | diff --git a/docs/options.md b/docs/options.md index 26b6149..51093eb 100644 --- a/docs/options.md +++ b/docs/options.md @@ -164,6 +164,23 @@ Options for beautysh executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*beautysh*" and change it to your desired configuration. +##### [black](#black) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `object` + +**Description**: + +Options for black executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*black*" and change it to your desired configuration. + ##### [ClangFormat](#clangformat) **Important**: This option is only configurable from within Atom Beautify's setting panel. @@ -10944,20 +10961,20 @@ Automatically beautify Puppet files on save #### [Python](#python) -**Supported Beautifiers**: [`autopep8`](#autopep8) [`pybeautifier`](#pybeautifier) [`yapf`](#yapf) +**Supported Beautifiers**: [`autopep8`](#autopep8) [`black`](#black) [`pybeautifier`](#pybeautifier) [`yapf`](#yapf) -| Option | autopep8 | pybeautifier | yapf | -| --- | --- | --- | --- | -| `disabled` | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| `default_beautifier` | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| `formatter` | :white_check_mark: | :white_check_mark: | :x: | -| `ignore` | :white_check_mark: | :white_check_mark: | :x: | -| `indent_size` | :white_check_mark: | :white_check_mark: | :x: | -| `max_line_length` | :white_check_mark: | :white_check_mark: | :x: | -| `multi_line_output` | :white_check_mark: | :white_check_mark: | :x: | -| `sort_imports` | :white_check_mark: | :white_check_mark: | :x: | -| `style_config` | :white_check_mark: | :white_check_mark: | :x: | +| Option | autopep8 | black | pybeautifier | yapf | +| --- | --- | --- | --- | --- | +| `disabled` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| `default_beautifier` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| `formatter` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `ignore` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `indent_size` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `max_line_length` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `multi_line_output` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `sort_imports` | :white_check_mark: | :x: | :white_check_mark: | :x: | +| `style_config` | :white_check_mark: | :x: | :white_check_mark: | :x: | **Description**: @@ -10988,7 +11005,7 @@ Disable Python Beautification **Type**: `string` -**Enum**: `autopep8` `pybeautifier` `yapf` +**Enum**: `autopep8` `black` `pybeautifier` `yapf` **Description**: diff --git a/package.json b/package.json index 6b14af6..1b98534 100644 --- a/package.json +++ b/package.json @@ -169,6 +169,10 @@ "name": "Kohei Hiraga", "url": "https://github.com/range3" }, + { + "name": "Arlo Shallit", + "url": "https://github.com/arl-o" + }, { "name": "Liam Newman", "url": "https://github.com/bitwiseman" @@ -450,6 +454,7 @@ "vhdl beautifier", "gn", "blade", + "black", "ocamlformat" ], "devDependencies": { diff --git a/src/beautifiers/black.coffee b/src/beautifiers/black.coffee new file mode 100644 index 0000000..e83c8d4 --- /dev/null +++ b/src/beautifiers/black.coffee @@ -0,0 +1,39 @@ +### +Requires [black](https://github.com/ambv/black) +### +"use strict" +Beautifier = require('./beautifier') +path = require('path') + +module.exports = class Black extends Beautifier + name: "black" + link: "https://github.com/ambv/black" + executables: [ + { + name: "black" + cmd: "black" + homepage: "https://github.com/ambv/black" + installation: "https://github.com/ambv/black#installation" + version: { + parse: (text) -> + # Try to read beta values, eg "black, version 18.6b4" -> 18.6.4 + try + text.match(/black, version (\d+\.\d+)/)[1] + "." + text.match(/b(\d+)$/)[1] + catch + text.match(/black, version (\d+\.\d+)/)[1] + ".0" + } + } + ] + + options: { + Python: false + } + + beautify: (text, language, options, context) -> + cwd = context.filePath and path.dirname context.filePath + # `-` as filename reads from stdin + @exe("black").run(["-"], { + cwd: cwd + onStdin: (stdin) -> + stdin.end text + }) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index b3e548a..80af18a 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -43,6 +43,7 @@ module.exports = class Beautifiers extends EventEmitter 'cljfmt' 'clang-format' 'crystal' + 'black' 'dfmt' 'elm-format' 'hh_format' diff --git a/src/options.json b/src/options.json index 745f56c..823f85a 100644 --- a/src/options.json +++ b/src/options.json @@ -6457,6 +6457,7 @@ ], "beautifiers": [ "autopep8", + "black", "pybeautifier", "yapf" ], @@ -6607,6 +6608,7 @@ "description": "Default Beautifier to be used for Python", "enum": [ "autopep8", + "black", "pybeautifier", "yapf" ] @@ -9682,6 +9684,22 @@ } } }, + "black": { + "key": "black", + "title": "black", + "type": "object", + "collapsed": true, + "description": "Options for black executable.", + "properties": { + "path": { + "key": "path", + "title": "Binary/Script Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"black\" executable's binary/script." + } + } + }, "dfmt": { "key": "dfmt", "title": "Dfmt",