Skip to content

🧰👌 Use pre-commit instead of tox -e style to run all CQA tools #288

@s-weigand

Description

@s-weigand

Currently, this project has 2 ways to run CQA tools:

  • tox -e style
  • pre-commit

To a new contributor, it might not be very clear how to run CQA tools.

Please don't take this the wrong way this is just my contributor experience it isn't meant as an attack.
I know first-hand that time for a FOSS maintainer is stretched VERY thin, sometimes you need to make hard calls like "tests pass, just linting fails so let's merge it, we will fix it later" and that typically no maintainer gets the praise that they deserve.
So thanks maintainers to not let a super nice project die and keeping it alive ❤️

My experience as a first-time contributor:

  • I forked the repo and cloned my fork
  • Installed the pre-commit git hooks (pre-commit install)
  • And ran pre-commit run -a (as I usually do) to populate its cache with the tooling versions of this project
  • Suddenly there were a lot of changes in a clean clone
$ git status       
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .github/workflows/do-update-authors.yml
        modified:   CHANGELOG.md
        modified:   docs/source/authors.rst
        modified:   docs/source/license.rst
        modified:   src/docformatter/syntax.py
        modified:   src/docformatter/util.py
        modified:   tests/_data/string_files/do_format_code.toml
        modified:   tests/_data/string_files/do_format_docstrings.toml
        modified:   tests/_data/string_files/format_code.toml
        modified:   tests/formatter/test_do_format_docstring.py
        modified:   tests/test_configuration_functions.py
        modified:   tests/test_docformatter.py
        modified:   tests/test_encoding_functions.py
        modified:   tests/test_string_functions.py
        modified:   tests/test_syntax_functions.py
        modified:   tests/test_utility_functions.py

no changes added to commit (use "git add" and/or "git commit -a")
  • So I git rest hard and uninstall the pre-commit git hooks (pre-commit uninstall)
  • I do my changes and push to my fork to see that the do-lint workflow fails
  • I have to look up how CQA tools are run (also took a moment since I didn't see a tox.ini) and run tox -e style locally
  • tox -e style also fails in a clean clone because of unpinned versions and tooling updates
  • Since ruff in .pre-commit-config.yaml was very outdated I pinned it to that version in the tox env (that version of the hook used a sys executable since it didn't define a pyproject.toml to pin the version) this should "just fix it" right?
  • When I look at the sill failing CI I see that pycodestyle also has an error because linting on the default branch was broken since Aug 9, 2023
  • Finally I can fix I wanted to fix

Advantages of running all CQA with pre-commit:

  • Single source of truth
  • Reproducibility due to version locking (... mostly since sometimes something down in the dependency tree just breaks things 🙈)
  • Easier maintenance due to update functionality (pre-commit autoupdate)
  • Clean commit history (no "Fix linting and formatting issues" commits)

Disadvantages of running all CQA with pre-commit:

  • Additional PRs/commits due to updating of pinned versions of tools BUT on your own schedule (same as pinning versions in the tox config)

Alternative:

Remove the .pre-commit-config.yaml and use a tox.ini, so experienced python project contributors know how to contribute even without a contributing guide (at least I did see a guide prominently mentioned)

I know given my PR it might seem like "Given this issue why do you advertise for pre-commit?", but this is the first time that I experienced a problem that wouldn't have happened the same way with a fresh venv or tox.
While I have seen far more issues running tooling outside of pre-commit (e.g. see above).

So if maintainers are ok with fully changing to pre-commit as the CQA runner I would be happy to make a PR for this transition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: stakeholderRelates to docformatter stakeholder requested behaviorP: enhancementFeature that is outside the scope of PEP 257U: lowA relatively low urgency issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions