Skip to content

Instantly share code, notes, and snippets.

@npanuhin
Created December 7, 2022 13:38
Show Gist options
  • Save npanuhin/0058aee88066620945ea141f18509ccf to your computer and use it in GitHub Desktop.
Save npanuhin/0058aee88066620945ea141f18509ccf to your computer and use it in GitHub Desktop.
Pyupgrade in CI

How run pyupgrade in CI (real usecase)

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:

  1. The first line recursively searches current directory for any .py files and applies pyupgrade --py38-plus to each found file
  2. 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment