#!/usr/bin/env python """Check the "Added in version" entries of the macro pages against the git tags. For every macro documented in docs/api/macros, find the first release tag whose amalgamated header mentions the macro and compare it with the version the page's "Version history" names. A macro documented as added *before* it appears in any release, or documented with a released version although no release contains it, is reported as a problem. A macro that appears in the header *before* its documented version is only a note: many macros existed internally before they were documented for users. The check is heuristic and meant to be run by hand, not in CI. usage: python3 check_version_history.py (from docs/mkdocs/docs, needs the git tags) """ import functools import glob import re # the script only runs git with fixed arguments and without a shell import subprocess # nosec B404 import sys HEADER_PATHS = ["single_include/nlohmann/json.hpp", "src/json.hpp"] # older releases used src/json.hpp VERSION_RE = re.compile(r"[Aa]dded in (?:version )?(\d+)\.(\d+)\.(\d+)") NAMED_VERSION_RE = re.compile(r"[Aa]dded `([A-Z0-9_]+)` in (?:version )?(\d+)\.(\d+)\.(\d+)") def release_tags(): # fixed git command without a shell tags = subprocess.run(["git", "tag", "-l", "v*"], capture_output=True, text=True, check=True).stdout.split() # nosec B603, B607 versions = [] for tag in tags: match = re.fullmatch(r"v(\d+)\.(\d+)\.(\d+)", tag) if match: versions.append((tuple(map(int, match.groups())), tag)) return sorted(versions) @functools.lru_cache(maxsize=None) def header(tag): for path in HEADER_PATHS: # fixed git command without a shell; the tag names come from "git tag" result = subprocess.run(["git", "show", f"{tag}:{path}"], capture_output=True, text=True) # nosec B603, B607 if result.returncode == 0: return result.stdout return "" def macros_and_versions(page): with open(page, encoding="utf-8") as content: text = content.read() match = re.search(r"^# (.+)$", text, re.MULTILINE) or re.search(r"