KangOl / black-macchiato

paints part of your python code black

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

black-macchiato

https://travis-ci.org/wbolster/black-macchiato.svg?branch=master
I see some Python and I want it painted black
Mick Jagger (The Rolling Stones)

What?

This is a small utility built on top of the black Python code formatter to enable formatting of partial files.

Why?

Python code should be black, just like coffee. However, sometimes other people insist on adding milk for unexplicable reasons. Since caffè latte is undrinkable, you eventually settle for caffè macchiato as a compromise.

In other words, you want to use black for the code you write, but for some reason you cannot convert whole files, e.g. when contributing to upstream codebases that are not under your complete control.

However, partial formatting is not supported by black itself, for various good reasons, and it won't be implemented either (134, 142, 245, 370, 511).

This is where black-macchiato enters the stage. This tool is for those who want to do partial formatting anyway. It also accepts indented blocks, which means that you can format an indented method inside a class, or a small block of code.

Note that this tool is a stopgap measure, and you should avoid using it if you can.

How?

To install, use:

pip install black-macchiato

The black-macchiato command reads from standard input, and writes to standard output. Any command line flags are forwarded to black.

Alternatively, you can invoke the module directly through the python executable, which may be preferable depending on your setup. Use python -m macchiato instead of black-macchiato in that case.

Example:

$ echo "    if True: print('hi')" | black-macchiato
    if True:
        print("hi")

Integrating this piping of input and output with your editor is left as an exercise to the reader. For instance, Vim users can use visual line mode and type :!black-macchiato, and Emacs users can use python-black.el.

License

BSD. See LICENSE.rst.

About

paints part of your python code black

License:Other


Languages

Language:Python 100.0%