pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
773 stars 120 forks source link

`python3 setup.py lint` is deprecated: Let's lint with `pre-commit` #2772

Closed cclauss closed 2 months ago

cclauss commented 3 months ago

Running python3 setup.py lint is deprecated. https://packaging.python.org/en/latest/discussions/setup-py-deprecated

The setup.py logic for running black and clang-format is ~100 lines long and is skipping many Python and C files. https://github.com/pygame-community/pygame-ce/blob/65a256d9464ae22141ac9622ca35c558d293509f/setup.py#L786-L875

This pull request proposes using pre-commit with ~25 lines of configuration to rapidly run these two tools locally on contributors' machines and also in our GitHub Actions to cover any contributors who do not have pre-commit installed.

The 15 exclude lines should be removed gradually as more of the codebase passes the formatting and linting process.

How to use:

brew install pre-commit  # or `python3 -m pip install pre-commit`

pre-commit install
    > pre-commit installed at .git/hooks/pre-commit

pre-commit autoupdate
    > [https://github.com/psf/black-pre-commit-mirror] already up to date!
    > [https://github.com/pre-commit/mirrors-clang-format] already up to date!

pre-commit run --all-files
    > black....................................................................Passed
    > clang-format.............................................................Passed
cclauss commented 3 months ago

@ankith26 @Starbuck5 @oddbookworm Your reviews, please.