deepspeed
1#!/usr/bin/env python3
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: Apache-2.0
4
5# DeepSpeed Team
6
7from __future__ import annotations8'''Copyright The Microsoft DeepSpeed Team'''
9"""
10Modified from https://github.com/jlebar/pre-commit-hooks/blob/master/check_do_not_submit.py
11"""
12
13import subprocess14import sys15
16
17def err(s: str) -> None:18print(s, file=sys.stderr)19
20
21COPYRIGHT = [22(r"^# Copyright (c) Microsoft Corporation.$", r"^\/\/ Copyright (c) Microsoft Corporation.$"),23(r"^# SPDX-License-Identifier: Apache-2.0$", r"^\/\/ SPDX-License-Identifier: Apache-2.0$"),24(r"^# DeepSpeed Team$", r"^\/\/ DeepSpeed Team$"),25]
26
27success = True28failures = []29for f in sys.argv[1:]:30for copyright_line in COPYRIGHT:31cmd = ["git", "grep", "--quiet"]32for line in copyright_line:33cmd.extend(["-e", line])34cmd.append(f)35res = subprocess.run(cmd, capture_output=True)36if res.returncode == 1:37success = False38failures.append(f)39break40elif res.returncode == 2:41err(f"Error invoking grep on {', '.join(sys.argv[1:])}:")42err(res.stderr.decode("utf-8"))43sys.exit(2)44
45if not success:46err(f'{failures}: Missing license at top of file')47err(res.stdout.decode("utf-8"))48sys.exit(1)49