Skip to content

Introduce black as the standard Python code formatter #356

@nanotaboada

Description

@nanotaboada

Description

This project currently uses flake8 for linting, which is great for enforcing code quality. However, it doesn’t handle code formatting.

Introducing black will enforce a consistent code style across the codebase, reduce style-related discussions in code reviews, and speed up development by automating formatting.

We will add black alongside flake8, not as a replacement.

Proposed Solution

  • Add black to requirements-lint.txt
  • Add a pyproject.toml with basic black configuration (targeting Python 3.13)
  • Format the existing codebase using black
  • Add a black --check . step to the existing CI workflow (alongside flake8)
  • Document this in CONTRIBUTING.md

Suggested Implementation

1. Update requirements-lint.txt

Append:

black==25.1.0

2. Add pyproject.toml

Create at the repo root:

[tool.black]
line-length = 88
target-version = ['py313']
include = '\.pyi?$'
exclude = '''
/(
    \.git
  | \.venv
  | build
  | dist
  | __pycache__
  | \.eggs
  | \.mypy_cache
  | \.tox
)/
'''

3. Format the codebase

Run:

black .

4. Update CI Workflow (lint job)

Append this step after flake8:

- name: Check code formatting with black
  run: black --check .

5. (Optional) Update CONTRIBUTING.md

Add a new line:

Format your code with black before committing. Run black . from the project root

Acceptance Criteria

  • black==25.1.0 is listed in requirements-lint.txt
  • pyproject.toml with black config exists
  • All Python code is formatted with black
  • CI pipeline checks code formatting with black
  • Contribution guide includes instructions on using black

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpythonPull requests that update Python code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions