Skip to content

Commit 5f8c379

Browse files
authored
Add License headers (#87)
1 parent 17dda20 commit 5f8c379

37 files changed

+278
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
#!/usr/bin/env python3
8+
9+
import sys
10+
import argparse
11+
12+
REQUIRED_LICENSE_TEXT = "Copyright (c) Meta Platforms, Inc. and affiliates."
13+
14+
15+
def check_license_header(file_path):
16+
"""Check if a Python file has the required license header."""
17+
try:
18+
with open(file_path, "r", encoding="utf-8") as f:
19+
content = f.read()
20+
return REQUIRED_LICENSE_TEXT in content
21+
except Exception as e:
22+
print(f"Error reading {file_path}: {e}")
23+
return False
24+
25+
26+
def main():
27+
parser = argparse.ArgumentParser(description="Check license headers in Python files")
28+
parser.add_argument("files", nargs="*", help="Files to check")
29+
args = parser.parse_args()
30+
31+
if not args.files:
32+
return 0
33+
34+
missing_headers = []
35+
36+
for file_path in args.files:
37+
if file_path.endswith(".py"):
38+
if not check_license_header(file_path):
39+
missing_headers.append(file_path)
40+
41+
if missing_headers:
42+
print("Missing license headers in the following files:")
43+
for file_path in missing_headers:
44+
print(f" - {file_path}")
45+
print("\nPlease add the following license header to the top of each file:")
46+
print("# Copyright (c) Meta Platforms, Inc. and affiliates.")
47+
print("# All rights reserved.")
48+
print("#")
49+
print("# This source code is licensed under the BSD 3-Clause license found in the")
50+
print("# LICENSE file in the root directory of this source tree.")
51+
return 1
52+
53+
return 0
54+
55+
56+
if __name__ == "__main__":
57+
sys.exit(main())

.github/workflows/ruff.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ jobs:
2626
run: uv run ruff check .
2727

2828
- name: Run ruff format check
29-
run: uv run ruff format --check .
29+
run: uv run ruff format --check .
30+
31+
- name: Check license headers
32+
run: python .github/scripts/check_license_headers.py $(find . -name "*.py" -type f -not -path "./.venv/*" -not -path "./__pycache__/*")

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ repos:
44
hooks:
55
- id: ruff
66
args: [--fix]
7-
- id: ruff-format
7+
- id: ruff-format
8+
- repo: local
9+
hooks:
10+
- id: check-license-headers
11+
name: Check license headers
12+
entry: python .github/scripts/check_license_headers.py
13+
language: system
14+
files: \.py$
15+
pass_filenames: true

BackendBench/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
"""
28
BackendBench: A PyTorch backend evaluation framework with monkey patching support.
39

BackendBench/backends/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
"""
28
BackendBench backends submodule.
39

BackendBench/backends/aten.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
from .base import Backend
28

39

BackendBench/backends/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
18
class Backend:
29
def __init__(self, name):
310
self.name = name

BackendBench/backends/directory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
import importlib.util
28
import logging
39
import os

BackendBench/backends/flag_gems.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
import torch
28

39
from BackendBench.opregistry import register_operator

BackendBench/backends/kernel_agent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
import importlib.util
28
import logging
39
import os

0 commit comments

Comments
 (0)