Skip to content

Conversation

@max-models
Copy link

Since this project is all about code formatting, I thought it would be a nice idea to also format the python code, so I ran two of the most popular python code formatters (black and isort) on the Python files in the repo.

I also added a check in the Github workflow to verify that the code is formatted with both black and isort.

@nbehrnd
Copy link

nbehrnd commented Nov 12, 2025

@max-models

I also added a check in the Github workflow to verify that the code is formatted with both black and isort.

I propose to edit the PR to equally amend the already present pre-commit hook file. Once locally activated, this already can assist (at local level) en route to eventually file a PR. Be welcome to pick, edit, adjust to your preference from example below:

repos:

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: trailing-whitespace
        exclude: ^tests/resources/

  - repo: https://github.com/psf/black
    rev: 25.1.0
    hooks:
      - id: black

  - repo: https://github.com/PyCQA/flake8
    rev: 7.1.1
    hooks:
      - id: flake8
        name: "flake8 (advisory only, it does not block a commit)"
        args:
          - --exclude=.*/site-packages/.*
          - --filename=.*\.py
          - --max-line-length=90
          - --show-source
          - --statistics
          - --count
          - --exit-zero
        verbose: true
        always_run: true

  - repo: https://github.com/pre-commit/mirrors-isort
    rev: v5.10.1
    hooks:
      - id: isort
        name: sorts imports
        args: ["--profile", "black", "--filter-files", "--line-width=99"]

The file defines them explicitly, in addition to templates git init provides in .git/hooks/. If set well, they equally work fine with commitizen, too (because multiple commits by @gnikit adhere to the pattern of conventional commits -- but like pre-commit hooks, it is an opt-in).

@max-models
Copy link
Author

@max-models

I also added a check in the Github workflow to verify that the code is formatted with both black and isort.

I propose to edit the PR to equally amend the already present pre-commit hook file. Once locally activated, this already can assist (at local level) en route to eventually file a PR. Be welcome to pick, edit, adjust to your preference from example below:

repos:

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: trailing-whitespace
        exclude: ^tests/resources/

  - repo: https://github.com/psf/black
    rev: 25.1.0
    hooks:
      - id: black

  - repo: https://github.com/PyCQA/flake8
    rev: 7.1.1
    hooks:
      - id: flake8
        name: "flake8 (advisory only, it does not block a commit)"
        args:
          - --exclude=.*/site-packages/.*
          - --filename=.*\.py
          - --max-line-length=90
          - --show-source
          - --statistics
          - --count
          - --exit-zero
        verbose: true
        always_run: true

  - repo: https://github.com/pre-commit/mirrors-isort
    rev: v5.10.1
    hooks:
      - id: isort
        name: sorts imports
        args: ["--profile", "black", "--filter-files", "--line-width=99"]

The file defines them explicitly, in addition to templates git init provides in .git/hooks/. If set well, they equally work fine with commitizen, too (because multiple commits by @gnikit adhere to the pattern of conventional commits -- but like pre-commit hooks, it is an opt-in).

Ok, good idea! I can do that, although I personally don't like to add too much to the pre-commit hooks, since it often becomes a bit too annoying.

@nbehrnd
Copy link

nbehrnd commented Nov 12, 2025

@max-models I agree with you. Each hook and test is like a droplet of glue -- if there are too many, they i) can hinder each other's action. Instead of providing a tangible benefit to the project per sé, ii) they then slow down progress.

@max-models
Copy link
Author

@max-models I agree with you. Each hook and test is like a droplet of glue -- if there are too many, they i) can hinder each other's action. Instead of providing a tangible benefit to the project per sé, ii) they then slow down progress.

Agreed :) Sometimes I feel like there is so much glue that I can't even make a dirty temporary commit, so I just turn off all the pre-commit hooks instead. In any case, using the hooks is optional, and the formatting is checked with Github actions.

I added a .pre-commit-config.yaml with black and isort hooks in 3815c71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants