简体   繁体   中英

Pre-commit-hook for Python project

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.

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 ? "

Here is extension for flake8: https://pypi.org/project/flake8-print/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM