Here is a workaround for pyupgrade's lack of --check
option (one of many related issues) and folder scanning (related issue).
find . -type f -name "*.py" -exec pyupgrade --py38-plus {} \;
test $(git status --porcelain | wc -l) = 0
You can use this in any CI platform like GitHub Actions
Explanation:
- The first line recursively searches current directory for any
.py
files and appliespyupgrade --py38-plus
to each found file - The second line uses
git status
to list all files modified by pyupgrade, and if there is even one, fails with a non-zero exit code (author: @hugovk)