# SPDX-License-Identifier: Apache-2.0 # Copyright 2026 Scienting # # Source Code: https://git.scient.ing/papers/paperspec # See the LICENSE.md file for full license terms. """Every source file carries the license header; ruff checks the Python files, this checks the rest. paperspec is an exception to Scienting's Prosperity header: its code is Apache-2.0 (LICENSE.md), so the header is an SPDX identifier, and the schemas, SQL and vectors, which are CC0-1.0 data, carry none. """ import subprocess from pathlib import Path import pytest ROOT = Path(__file__).resolve().parent.parent NOTICE = "SPDX-License-Identifier: Apache-2.0" SOURCE = "Source Code: https://git.scient.ing/papers/paperspec" # Comment syntax by file suffix. Data, lock files, generated output and the normative CC0 data (schemas, SQL, # vectors, fixtures) are not source files and are not listed. COMMENT = { ".py": "#", ".sh": "#", ".js": "//", ".ts": "//", } # Paths (relative, forward slashes) that are generated or vendored, never source. EXCLUDED = ("src/paperspec/_version.py",) def tracked_sources() -> list[Path]: """Return the tracked and untracked-but-not-ignored files whose suffix names a source language.""" out = subprocess.run( [ "git", "-C", str(ROOT), "ls-files", "--cached", "--others", "--exclude-standard", ], capture_output=True, text=True, check=True, ).stdout.splitlines() return [ ROOT / name for name in out if Path(name).suffix in COMMENT and not name.startswith(EXCLUDED) and (ROOT / name).is_file() ] @pytest.mark.parametrize( "path", tracked_sources(), ids=lambda p: str(p.relative_to(ROOT)) ) def test_file_has_the_license_header(path: Path) -> None: """The first lines (after a shebang) are the SPDX notice and name this repository as the source.""" lines = path.read_text(encoding="utf-8").splitlines() if lines and lines[0].startswith("#!"): lines = lines[1:] head = "\n".join(lines[:8]) marker = COMMENT[path.suffix] assert f"{marker} {NOTICE}" in head, ( f"{path.relative_to(ROOT)} lacks the license header" ) assert f"{marker} {SOURCE}" in head