black (The uncompromising Python code formatter)

../../_images/logo_black.png

Installation

pipenv install black --dev

black with git pre-commit (.pre-commit-config.yaml)

# .pre-commit-config.yaml
# ========================
#
# - https://gdevops.frama.io/dev/tuto-project/tests/frameworks/pre_commit/pre_commit.html
#
# Calling examples
#
# - pre-commit run black
# - pre-commit run isort
#
# continuous integration
# ======================
#
# - pre-commit run --all-files
#
repos:
  - repo: https://github.com/ambv/black
    rev: 19.3b0
    hooks:
    - id: black
      language_version: python3.7


  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.1.0
    hooks:
    - id: trailing-whitespace
      description: This hook trims trailing whitespace.
    - id: detect-private-key
    - id: mixed-line-ending
      args: [--fix=lf]
      description: Forces to replace line ending by the UNIX 'lf' character.

black in a makefile

 1 # makefile for quality code.
 2 #
 3 # ATTENTION:
 4 #
 5 # - le marqueur est la tabulation
 6 #
 7 # Exemples
 8 # =========
 9 # https://github.com/kennethreitz/requests/blob/master/Makefile
10 #
11
12 # https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html#Makefile-Basics
13 SHELL = /bin/bash
14
15 # Put it first so that "make" without argument is like "make help".
16 help:
17     @echo " "
18     @echo "Targets:"
19     @echo " "
20     @echo "- make black"
21     @echo "- make check_all_files"
22     @echo "- make precommit_autoupdate"
23     @echo " "
24
25
26 black:
27     pre-commit run black
28
29
30 check_all_files:
31     pre-commit run --all-files
32
33 precommit_autoupdate:
34     pre-commit autoupdate
35
36
37 .PHONY: help  Makefile
38
39 # Catch-all target:
40 %: Makefile
41     echo "Hello World !"