How do I remove print statements in a Python project using pre-commit hook before checking in code to GitHub? Currently, I use black and flake8 pre-commit hooks. But they don't seem to have the option to check and remove print statements before checking in code.
Asked
Active
Viewed 602 times
2 Answers
0
Since the pre-commit framework only calls flake8, you would need to check its configuration to see if there is any setting which would trigger a print statement deletion (as opposed to error/violation codes)
Since that is not supported by flake8 itself, you would need to develop a plugin to flake8 in order to act on those error and delete the print lines.
If you do, don't forget to add the changes, as explained in "Can you change a file content during git commit?"
VonC
- 1,129,465
- 480
- 4,036
- 4,755
0
You could use flake8 plugin to check for print statements.
https://pypi.org/project/flake8-print/
Just add to your pre-commit config:
- repo: https://gitlab.com/pycqa/flake8
rev: <desired-rev>
hooks:
- id: flake8
additional_dependencies: [flake8-print]
Andrii Dubonos
- 66
- 4