Skip to content

Commit 4ce0da6

Browse files
committed
toolshed/check_spdx.py: ensure all LICENSE files across the entire repo are identical
This avoids: * hard-coded LICENSE filepaths. * checking the same LICENSE files multiple times, depending on how pre-commit batches the files.
1 parent 7e2b151 commit 4ce0da6

2 files changed

Lines changed: 18 additions & 12 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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@
3737
}
3838

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

4554

4655
def load_spdx_ignore():
@@ -208,14 +217,11 @@ def main(args):
208217
else:
209218
fix = False
210219

211-
ignore_spec = load_spdx_ignore()
212-
213220
returncode = 0
214-
repository_license = Path("LICENSE").read_bytes()
215-
for license_file in PACKAGE_LICENSE_FILES:
216-
if Path(license_file).read_bytes() != repository_license:
217-
print(f"PACKAGE LICENSE {license_file!r} does not match repository LICENSE")
218-
returncode = 1
221+
if not license_files_match_repository(args):
222+
returncode = 1
223+
224+
ignore_spec = load_spdx_ignore()
219225

220226
for filepath in args:
221227
if ignore_spec.match_file(filepath):

0 commit comments

Comments
 (0)