Skip to content

Commit cae38a1

Browse files
committed
Simplify license check
Signed-off-by: Jay Gu <jagu@nvidia.com>
1 parent f5d0cce commit cae38a1

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: python scripts/cpplint.py
4848

4949
- name: Check license headers (REUSE)
50-
run: scripts/check_license.sh
50+
run: python scripts/check_license.py
5151

5252
- name: Check inline samples are up to date
5353
run: python test/tools/inline_samples.py --check

scripts/check_license.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import subprocess
6+
import sys
7+
8+
skip_patterns = [
9+
"VERSION",
10+
".svg",
11+
"uv.lock",
12+
"LICENSES/",
13+
]
14+
15+
max_lines_to_check = 10
16+
17+
18+
def check_license():
19+
result = subprocess.run(
20+
["git", "ls-files"],
21+
capture_output=True,
22+
text=True,
23+
check=True,
24+
)
25+
bad_files = 0
26+
num_files = 0
27+
28+
for filepath in result.stdout.splitlines():
29+
if any(s in filepath for s in skip_patterns):
30+
continue
31+
try:
32+
with open(filepath, "r") as f:
33+
head = ""
34+
for i, line in enumerate(f):
35+
if i >= max_lines_to_check:
36+
break
37+
head += line
38+
except (UnicodeDecodeError, OSError):
39+
continue
40+
41+
if not head:
42+
continue
43+
num_files += 1
44+
has_error = False
45+
if "SPDX-FileCopyrightText" not in head:
46+
print(f"{filepath}: no copyright notice", file=sys.stderr)
47+
has_error = True
48+
if "SPDX-License-Identifier" not in head:
49+
print(f"{filepath}: no license identifier", file=sys.stderr)
50+
has_error = True
51+
if has_error:
52+
bad_files += 1
53+
54+
if bad_files > 0:
55+
print(f"Found {bad_files} files with missing or incomplete license headers",
56+
file=sys.stderr)
57+
sys.exit(1)
58+
elif num_files == 0:
59+
print("No input files found!", file=sys.stderr)
60+
sys.exit(2)
61+
else:
62+
print(f"Checked {num_files} files, all OK")
63+
64+
65+
if __name__ == "__main__":
66+
check_license()

scripts/check_license.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pytest-cov==6.2.1
99
pytest-env==1.2.0
1010
flake8==7.3.0
1111
pytest-cov==6.2.1
12-
reuse==5.1.0
1312

1413
numba-cuda[cu13]==0.20.0
1514
cupy-cuda13x==13.6.0

0 commit comments

Comments
 (0)