liveBook · Manning

Formatting

As explained in Data Pipelines with Apache Airflow, Second Edition

A code formatter is a software tool that rewrites source code into a consistent formatting style according to configured or built-in rules.

Code formatting rewrites Python source into a consistent style, reducing differences between contributors. Unlike Flake8 or Pylint, a formatter changes layout such as indentation, line breaks, and quoting. section 12.1.1

A practical formatting workflow uses:

  • Black or YAPF to apply a project-wide formatting style; their styles differ slightly. section 12.1.1
  • Black by installing it with pip and running `python -m black dags/`. section 12.1.1
  • Flake8 or Pylint alongside formatting when broader code-quality feedback is required. section 12.1.1

Black reformats a function

Black turns a function with split arguments, mixed quote styles, and an explicit line continuation into a compact signature, consistent double quotes, and a direct return expression. section 12.1.1

Listing 12.7 Installing and running Black
python -m pip install black
python -m black dags/

Use the command listing to install Black and format the DAG directory. section 12.1.1

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Demonstrates formatter behavior, installation, execution, and before-and-after output, but does not detail formatter configuration.
Examples
Uses noncompliant Python snippets, a reformatted function, and Black command output as concrete examples.
What it assumes
Assumes basic Python source files and pip usage while demonstrating formatting differences from zero.
What you can do after
Apply consistent Python formatting with Black or YAPF and combine it with static checks when needed.
How it connects
Connects code formatting with PEP 8, static analysis, Flake8, Pylint, Black, and YAPF.

Also explained in

Compare how 7 books explain formatting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.