Black is a style guide enforcement tool.
You can use this cookiecutter template to create a python project with
black already configured.
pip install black
Its configuration is stored in
# Example configuration for Black. # NOTE: you have to use single-quoted strings in TOML for regular expressions. # It's the equivalent of r-strings in Python. Multiline strings are treated as # verbose regular expressions by Black. Use [ ] to denote a significant space # character. [tool.black] line-length = 88 target-version = ['py36', 'py37', 'py38'] include = '\.pyi?$' exclude = ''' /( \.eggs | \.git | \.hg | \.mypy_cache | \.tox | \.venv | _build | buck-out | build | dist # The following are specific to Black, you probably don't want those. | blib2to3 | tests/data | profiling )/ '''
You can use it both with:
The Vim plugin
repos: - repo: https://github.com/ambv/black rev: stable hooks: - id: black language_version: python3.7
--- name: Lint on: [push, pull_request] jobs: Black: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - name: Black uses: psf/black@stable
If you want to split long lines, you need to use the
--experimental-string-processing flag. I haven't found how to set that option in the config file.
You can use the comments
# fmt: off and
# fmt: on