Skip to main content

More Black! Denser Black formatting

Project description

More Black! - Denser Black formatting

This is s a fork of the Black code formatter

Requires Python 3.7

The old version of Black depends on a number of binaries, each particular to Python 3.7.

Problem

I love Black formatting because I agree with its formatting choices, but it does have one pathology: Excessive indenting on data structures

Here is an example of Black formatting; many lines are wasted on lonely brackets:

my_method(
    [
        {
            "name": "a",
            "value": 42
        }
    ]
)

Solution: More Black!

When there is only one property (or list item, or parameter), then do not make a new line.

my_method([{
    "name": "a",
    "value": 42
}])

Usage

Please read the official Black documentation at time of fork

pip install mo-black

More about this fork

The right_hand_split() function has additional code that attempts to identify "simple" structures inside brackets. If it is simple, then block the multiline formatting and, recurse into deeper brackets to find something more complicated to split.

Development

Be sure you are in the mo-black main directory

Setup virtual environment

python -m venv .venv
source .venv/bin/activate

Install requirements

pip-compile --output-file=packaging/requirements.txt packaging/requirements.in
pip install -r packaging/requirements.txt
pip install -r tests/requirements.txt

Set some environment variables

export PYTHONPATH=.

Run the tests

python -m unittest tests/test_black.py

Here is the same for Windows...

c:\Python38\python -m pip install virtualenv
c:\Python38\python -m virtualenv .venv             
.venv\Scripts\activate
pip install -r packaging\requirements.txt
pip install -r tests\requirements.txt
set PYTHONPATH=.
python -m unittest tests\test_black.py

Development Installation

You can install mo-black from the main directory

python.exe -m pip install .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mo_black-22.364.23070-py2.py3-none-any.whl (94.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page