check-license.py 1.15 KB
Newer Older
aiss's avatar
aiss committed
1
#!/usr/bin/env python3
aiss's avatar
aiss committed
2
3
4
5
6
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

aiss's avatar
aiss committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from __future__ import annotations
'''Copyright The Microsoft DeepSpeed Team'''
"""
Modified from https://github.com/jlebar/pre-commit-hooks/blob/master/check_do_not_submit.py
"""

import subprocess
import sys


def err(s: str) -> None:
    print(s, file=sys.stderr)


aiss's avatar
aiss committed
21
22
23
24
25
COPYRIGHT = [
    r"^\(\/\/\|#\) Copyright (c) Microsoft Corporation.$", r"^\(\/\/\|#\) SPDX-License-Identifier: Apache-2.0$",
    r"^\(\/\/\|#\) DeepSpeed Team$"
]

aiss's avatar
aiss committed
26
27
28
success = True
failures = []
for f in sys.argv[1:]:
aiss's avatar
aiss committed
29
30
31
32
33
34
35
36
37
38
39
    for copyright_line in COPYRIGHT:
        if not success:
            break
        res = subprocess.run(["git", "grep", "--quiet", "-e", copyright_line, f], capture_output=True)
        if res.returncode == 1:
            success = False
            failures.append(f)
        elif res.returncode == 2:
            err(f"Error invoking grep on {', '.join(sys.argv[1:])}:")
            err(res.stderr.decode("utf-8"))
            sys.exit(2)
aiss's avatar
aiss committed
40
41
42
43
44

if not success:
    err(f'{failures}: Missing license at top of file')
    err(res.stdout.decode("utf-8"))
    sys.exit(1)