Package: remove-print-statements
remove-print-statementsA command-line tool (and pre-commit hook) to remove all theprintstatements
from your Python project.Do you useprintstatements for debugging? We all do, and there's nothing wrong
with it. After the bug has been resolved, we need to manually open all the files
which we added the print statements in, only if we remember all of them after
hours of debugging, and remove them. A better way would be to use some sort of
find and replace from the editor or command-line, but that's still a lot of
manual work. Worst case, it gets pushed and deployed to production.Who wants to do all the manual work in the age of automation? No one. So,
install this tool and forget about removing the print statements manually
forever. You could either run this tool manually or add it as apre-commithook. You could even preview the print statements along with it's location
without removing it. How nice is that!InstallationYou can installremove-print-statementsfrom the Python Package Index (PyPI)
withpipxor equivalent.pipx install remove-print-statementsOr, try it out usingpipx:pipx run remove-print-statements --helpOr, withpre-commitin therepossection of your.pre-commit-config.yamlfile (docs):-repo:https://github.com/dhruvmanila/remove-print-statementsrev:''# Replace with latest tag on GitHubhooks:-id:remove-print-statements# args: ['--verbose']   # Show all the print statements to be removedUsageRun it on a given set of files:remove-print-statementsfoo.pybar.py...# or use globbingremove-print-statements*.pyYou can ignore files as well. To specify multiple files to ignore, use the flag
multiple times otherwise it's difficult to know the difference between the files
to ignore and the ones to check.remove-print-statements*.py--ignorefoo.py--ignorebar.pyYou can preview the print statements which would be removed without modifying
the source files using both--dry-runand--verboseflags like so:$remove-print-statements--dry-run--verbosetest.pytest.py7 print("module")18 print("property")27 print("method")29 print("for loop")1 file would be transformed, 4 print statements would be removedremove-print-statementsis a command-line tool that rewrites the files in
place. It focuses on upgrading your code and not on making it look nice. Run
remove-print-statements before formatters likeBlack.remove-print-statementsdoes not have any ability to recurse through
directories. Use the pre-commit integration, globbing, or another technique for
applying to many files such aswithgit ls-files | xargs.Single statementIf there's only a single statement in the body of a function, for/while loop, if
statement, etc., which is a print statement, then it will be replaced with thepasskeyword.def foo():-    print()+    passfor _ in range(5):-    print()+    passif __name__ == "__main__":-    print()+    passExit statusremove-print-statementscommand returns exit statuses as follows:StatusDescription0No print statements / changes made successfully1Files would be updated (dry run)123Some error happenedDevelopmentReleaseRunpoetry lockBump version inpyproject.tomland__version__variableCommit and push the changes with messagerelease: <version>Publish a new release on GitHub which will trigger an automated workflow to
publish on PyPiLicenseremove-print-statements is licensed under the MIT License.SeeLICENSEfor details.