run_black.ps1 805 B

1234567891011121314151617181920
  1. $ExitCode = 0
  2. $GitDiff = git diff --name-only origin/master
  3. $GitDiffBlack = Write-Output $GitDiff | Select-String -Pattern ".*\.py" | Select-String -NotMatch ".*/project_template/.*"
  4. # If there is no diff between master, then black everything.
  5. if ( $GitDiffBlack -eq $null ) {
  6. black --check .
  7. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  8. }
  9. # Else black just the diff.
  10. else {
  11. black --check $GitDiffBlack
  12. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  13. # If the project_template changed, then black the testproject too.
  14. $GitDiffTempl = Write-Output $GitDiff | Select-String -Pattern ".*/project_template/.*"
  15. if ( $GitDiffTempl -ne $null ) {
  16. black --check testproject/
  17. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  18. }
  19. }
  20. exit $ExitCode