Merge pull request #2189 from arl-o/master

Add Black beautifier for Python
This commit is contained in:
Steven Zeck 2018-09-11 23:19:43 -05:00 committed by GitHub
commit 596b979c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 15 deletions

View File

@ -8,6 +8,7 @@
# v0.33.0 (2018-08-10) # 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 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/**/*`) - 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) # v0.32.5 (2018-05-28)
- Fixes an issue with Rubocop not working on Windows ([#2092](https://github.com/Glavin001/atom-beautify/issues/2092)) - Fixes an issue with Rubocop not working on Windows ([#2092](https://github.com/Glavin001/atom-beautify/issues/2092))

View File

@ -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! | | 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/):<br/>1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) with `docker pull unibeautify/autopep8`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) by following https://github.com/hhatto/autopep8#installation<br/>2. Install [isort (`isort`)](https://github.com/timothycrosley/isort) by following https://github.com/timothycrosley/isort#installing-isort<br/> | | autopep8 | :warning: 2 executables | :warning: Only 1 of 2 executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) with `docker pull unibeautify/autopep8`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [autopep8 (`autopep8`)](https://github.com/hhatto/autopep8) by following https://github.com/hhatto/autopep8#installation<br/>2. Install [isort (`isort`)](https://github.com/timothycrosley/isort) by following https://github.com/timothycrosley/isort#installing-isort<br/> |
| beautysh | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) with `docker pull unibeautify/beautysh`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) by following https://github.com/bemeurer/beautysh#installation<br/> | | beautysh | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) with `docker pull unibeautify/beautysh`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [beautysh (`beautysh`)](https://github.com/bemeurer/beautysh) by following https://github.com/bemeurer/beautysh#installation<br/> |
| black | :warning: 1 executable | :x: No Docker support | :bookmark_tabs: Manually:<br/>1. Install [black (`black`)](https://github.com/ambv/black) by following https://github.com/ambv/black#installation<br/> |
| brittany | :warning: Manual installation | :construction: Not an executable | :page_facing_up: Go to https://github.com/lspitzner/brittany and follow the instructions. | | 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/):<br/>1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) with `docker pull unibeautify/clang-format`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) by following https://clang.llvm.org/docs/ClangFormat.html<br/> | | clang-format | :warning: 1 executable | :white_check_mark: :100:% of executables | :whale: With [Docker](https://www.docker.com/):<br/>1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) with `docker pull unibeautify/clang-format`<br/><br/>:bookmark_tabs: Manually:<br/>1. Install [ClangFormat (`clang-format`)](https://clang.llvm.org/docs/ClangFormat.html) by following https://clang.llvm.org/docs/ClangFormat.html<br/> |
| cljfmt | :white_check_mark: | :ok_hand: Not necessary | :smiley: Nothing! | | 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/)** | | 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/) | | 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/)** | | 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)** | | 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)** | | 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) | | Ruby | `Ruby`, `Ruby on Rails` |`.rb` | **[`Rubocop`](https://github.com/bbatsov/rubocop)**, [`Ruby Beautify`](https://github.com/erniebrodeur/ruby-beautify) |

View File

@ -164,6 +164,23 @@ Options for beautysh executable.
2. Go into *Packages* and search for "*Atom Beautify*" package. 2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*beautysh*" and change it to your desired configuration. 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) ##### [ClangFormat](#clangformat)
**Important**: This option is only configurable from within Atom Beautify's setting panel. **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) #### [Python](#python)
**Supported Beautifiers**: [`autopep8`](#autopep8) [`pybeautifier`](#pybeautifier) [`yapf`](#yapf) **Supported Beautifiers**: [`autopep8`](#autopep8) [`black`](#black) [`pybeautifier`](#pybeautifier) [`yapf`](#yapf)
| Option | autopep8 | pybeautifier | yapf | | Option | autopep8 | black | pybeautifier | yapf |
| --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `disabled` | :white_check_mark: | :white_check_mark: | :white_check_mark: | | `disabled` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `default_beautifier` | :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: | | `beautify_on_save` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `formatter` | :white_check_mark: | :white_check_mark: | :x: | | `formatter` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `ignore` | :white_check_mark: | :white_check_mark: | :x: | | `ignore` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `indent_size` | :white_check_mark: | :white_check_mark: | :x: | | `indent_size` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `max_line_length` | :white_check_mark: | :white_check_mark: | :x: | | `max_line_length` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `multi_line_output` | :white_check_mark: | :white_check_mark: | :x: | | `multi_line_output` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `sort_imports` | :white_check_mark: | :white_check_mark: | :x: | | `sort_imports` | :white_check_mark: | :x: | :white_check_mark: | :x: |
| `style_config` | :white_check_mark: | :white_check_mark: | :x: | | `style_config` | :white_check_mark: | :x: | :white_check_mark: | :x: |
**Description**: **Description**:
@ -10988,7 +11005,7 @@ Disable Python Beautification
**Type**: `string` **Type**: `string`
**Enum**: `autopep8` `pybeautifier` `yapf` **Enum**: `autopep8` `black` `pybeautifier` `yapf`
**Description**: **Description**:

View File

@ -169,6 +169,10 @@
"name": "Kohei Hiraga", "name": "Kohei Hiraga",
"url": "https://github.com/range3" "url": "https://github.com/range3"
}, },
{
"name": "Arlo Shallit",
"url": "https://github.com/arl-o"
},
{ {
"name": "Liam Newman", "name": "Liam Newman",
"url": "https://github.com/bitwiseman" "url": "https://github.com/bitwiseman"
@ -450,6 +454,7 @@
"vhdl beautifier", "vhdl beautifier",
"gn", "gn",
"blade", "blade",
"black",
"ocamlformat" "ocamlformat"
], ],
"devDependencies": { "devDependencies": {

View File

@ -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
})

View File

@ -43,6 +43,7 @@ module.exports = class Beautifiers extends EventEmitter
'cljfmt' 'cljfmt'
'clang-format' 'clang-format'
'crystal' 'crystal'
'black'
'dfmt' 'dfmt'
'elm-format' 'elm-format'
'hh_format' 'hh_format'

View File

@ -6457,6 +6457,7 @@
], ],
"beautifiers": [ "beautifiers": [
"autopep8", "autopep8",
"black",
"pybeautifier", "pybeautifier",
"yapf" "yapf"
], ],
@ -6607,6 +6608,7 @@
"description": "Default Beautifier to be used for Python", "description": "Default Beautifier to be used for Python",
"enum": [ "enum": [
"autopep8", "autopep8",
"black",
"pybeautifier", "pybeautifier",
"yapf" "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": { "dfmt": {
"key": "dfmt", "key": "dfmt",
"title": "Dfmt", "title": "Dfmt",