check-license.py 880 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. from __future__ import annotations
  3. '''Copyright The Microsoft DeepSpeed Team'''
  4. """
  5. Modified from https://github.com/jlebar/pre-commit-hooks/blob/master/check_do_not_submit.py
  6. """
  7. import subprocess
  8. import sys
  9. def err(s: str) -> None:
  10. print(s, file=sys.stderr)
  11. success = True
  12. failures = []
  13. for f in sys.argv[1:]:
  14. res = subprocess.run(
  15. ["git",
  16. "grep",
  17. "--quiet",
  18. "-e",
  19. r"Copyright .* DeepSpeed Team",
  20. f],
  21. capture_output=True)
  22. if res.returncode == 1:
  23. success = False
  24. failures.append(f)
  25. elif res.returncode == 2:
  26. err(f"Error invoking grep on {', '.join(sys.argv[1:])}:")
  27. err(res.stderr.decode("utf-8"))
  28. sys.exit(2)
  29. if not success:
  30. err(f'{failures}: Missing license at top of file')
  31. err(res.stdout.decode("utf-8"))
  32. sys.exit(1)