Skip to content

Commit fb57dbf

Browse files
authored
toolshed/check_spdx.py: ensure all LICENSE files across the entire repo are identical (#2762)
This avoids: * hard-coded LICENSE filepaths. * checking the same LICENSE files multiple times, depending on how pre-commit batches the files.
1 parent 0c0ced0 commit fb57dbf

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

cuda_pathfinder/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22

33
Apache License
44
Version 2.0, January 2004

toolshed/check_spdx.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
}
3737

3838
SPDX_IGNORE_FILENAME = ".spdx-ignore"
39+
REPOSITORY_LICENSE_CONTENTS = Path("LICENSE").read_bytes()
40+
41+
42+
def license_files_match_repository(filepaths):
43+
licenses_match = True
44+
for filepath in filepaths:
45+
license_path = Path(filepath)
46+
if license_path.name != "LICENSE":
47+
continue
48+
if license_path.read_bytes() != REPOSITORY_LICENSE_CONTENTS:
49+
print(f"PACKAGE LICENSE {filepath!r} does not match repository LICENSE")
50+
licenses_match = False
51+
return licenses_match
3952

4053

4154
def load_spdx_ignore():
@@ -203,9 +216,12 @@ def main(args):
203216
else:
204217
fix = False
205218

219+
returncode = 0
220+
if not license_files_match_repository(args):
221+
returncode = 1
222+
206223
ignore_spec = load_spdx_ignore()
207224

208-
returncode = 0
209225
for filepath in args:
210226
if ignore_spec.match_file(filepath):
211227
continue

0 commit comments

Comments
 (0)