Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.54 KB

format.md

File metadata and controls

44 lines (31 loc) · 1.54 KB

Format

Maintaining consistent formatting across your project is a simple yet effective way to improve the readability of your code. To achieve this, I use two complementary formatters: isort for sorting imports and black for the rest of the code.

black

black is a code formatter that aims to be the standard formatting tool for Python. It has many advantages:

  • Ease of use.
  • PEP 8 compliance (of course).
  • Minimalistic configuration, which ensures that the formatting stays consistent across different developers.
  • Deterministic (it always produces the same output), so it can be used on CI/CD pipelines.

Usage

# format all the Python files of your project
black .

isort

isort is a tool that formats a part of your code left untouched by black: the order of your import statements. It splits your import list into 3 parts, as recommended by PEP-8: first the standard library, then the third-party modules, and finally your own package.

Usage

# order all the imports of your Python files
isort .

Configuration

Add the following configuration to your pyproject.toml. If you don't use git, turn skip_gitignore to false.

[tool.isort]
profile = "black"
skip_gitignore = true