Skip to content

Instantly share code, notes, and snippets.

@wjt
Created December 17, 2025 15:15
Show Gist options
  • Select an option

  • Save wjt/3f4d7656fe9d014146f62cc47ffbf608 to your computer and use it in GitHub Desktop.

Select an option

Save wjt/3f4d7656fe9d014146f62cc47ffbf608 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Copyright The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
import json
import subprocess
import csv
import sys
import re
NO_CREDIT_LICENSES = {
"LicenseRef-AlkaKrab",
"LicenseRef-AllRightsReserved",
"LicenseRef-CathranMusic",
"CC0-1.0",
}
CREDIT_LICENSES = {
"CC-BY-4.0",
"CC-BY-SA-4.0",
"MIT",
"MPL-2.0",
"OFL-1.1",
}
STRIP_PREFIXES = {
# stop reuse lint from reading this file!
"SPDX-" + "FileCopyrightText:",
"Copy" + "right",
}
def main() -> None:
result = subprocess.run(("reuse", "lint", "-j"), capture_output=True)
lint = json.loads(result.stdout)
credits_by_license = {}
for file in lint["files"]:
if file["path"] == "docs/LICENSING.md":
# This file confuses `reuse` because it contains examples of the
# license header embedded within it.
continue
if len(file["spdx_expressions"]) != 1:
raise ValueError(file)
spdx = file["spdx_expressions"][0]
license = spdx["value"]
if license in NO_CREDIT_LICENSES:
continue
if license not in CREDIT_LICENSES:
raise ValueError(file)
for copyright in file["copyrights"]:
value = copyright["value"].strip()
for prefix in STRIP_PREFIXES:
value = value.removeprefix(prefix).strip()
credits_by_license.setdefault(license, set()).add(value)
w = csv.writer(sys.stdout)
w.writerow(["License", "Credit"])
for license, credits in credits_by_license.items():
for credit in credits:
w.writerow([license, credit])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment