#!/usr/bin/env python3 # Copyright: 2026, Maximiliano Curia # # License: ISC # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # . # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. """Generate decopy's shipped licence-text data from the SPDX corpus. Offline maintenance aid: reads the SPDX JSON vendored under tests/testdata/ and writes the committed package-data under decopy/licensing/data/. It is NOT part of the test suite and must never run in CI; re-run it by hand after refreshing the SPDX corpus, then commit the regenerated files. scripts/emit-license-data.py --headers # data/headers/.txt scripts/emit-license-data.py --licenses # data/licenses/.txt scripts/emit-license-data.py --exceptions # data/exceptions/.txt Headers are the cleaned ``standardLicenseHeader`` keyed by decopy's DEP-5 name (so GPL-2.0-only -> GPL-2, GPL-2.0-or-later -> GPL-2+). Only the common-licenses families are emitted: the renderer prepends a header solely when it emits a common-licenses reference (to disambiguate the +/only variant), so other SPDX headers would never be read. When several SPDX ids canonicalise to one name the smallest id wins, so the result is deterministic. """ from __future__ import annotations import argparse import json import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) from decopy.licensing.data.common_licenses import COMMON_LICENSES # noqa: E402 from decopy.licensing.spdx import ( # noqa: E402 canonical_license_name, exception_to_spdx, ) LICENSES_DIR = ROOT / "tests" / "testdata" / "licenses" EXCEPTIONS_DIR = ROOT / "tests" / "testdata" / "exceptions" DATA_DIR = ROOT / "decopy" / "licensing" / "data" HEADERS_DIR = DATA_DIR / "headers" LICENSES_OUT = DATA_DIR / "licenses" EXCEPTIONS_OUT = DATA_DIR / "exceptions" # Short / widely used licences embedded as full verbatim text instead of a # common-licenses reference (they are too short for the indirection and are not # in common-licenses). SPDX ids; the output is keyed by the decopy DEP-5 name. # The original seed (MIT/ISC/Zlib/X11 + BSD-2/3) was extended 2026-07-02 from # the completed tag-mode codesearch ranking (scripts/rank-license-usage- # codesearch.py, .claude/reports/s3.5-license-status.md): every short candidate # was queried and those at or above ~5 distinct source packages were added. The # SPDX-License-Identifier signal is biased toward tag-adopting ecosystems # (Rust/Go/modern) so it undercounts untagged C/Perl, but with the whole batch # ranked it is a usable relative shortlist. BSD-2-Clause-FreeBSD is a deprecated # SPDX id, kept because it still sees real (22-package) usage. _EMBEDDED_LICENSE_IDS: tuple[str, ...] = ( "0BSD", "BSD-1-Clause", "BSD-2-Clause", "BSD-2-Clause-FreeBSD", "BSD-3-Clause", "BSD-3-Clause-Clear", "BSD-4-Clause", "CC-PDDC", "FSFAP", "FSFUL", "FSFULLR", "ISC", "MIT", "MIT-0", "PSF-2.0", "Unicode-3.0", "Unlicense", "X11", "Zlib", "curl", ) # Widely used licence exceptions embedded as full verbatim text so a # " with