click_extra.sphinx.matrix module¶
Release compatibility matrices derived from a project’s git history.
Walk every vX.Y.Z tag in a project’s git repository, extract each release’s
declared support for some axis, group consecutive tags that agree, and render a
GitHub-flavored markdown matrix suitable for a project’s install.md.
Two axes are supported:
Python (
{matrix} python): per-tag support comes from theProgramming Language :: Python :: X.Yclassifier list inpyproject.toml(the explicit tested grid), falling back in priority order to PEP 621requires-python, Poetry[tool.poetry.dependencies].python, andsetup.py’spython_requires. A floor-only declaration is capped at the latest Python released while the range was current, so the✅set does not over-claim support for Pythons that did not yet exist. Cells are three-valued: the classifier list drives✅,requires-pythondrives❌, and a version neither attested nor ruled out renders as–(seeUNDECLARED_CELL).A dependency (
{matrix} <distribution>, like{matrix} click): the per-tag constraint is that distribution’s requirement specifier; each column covers a run of that distribution’s releases on PyPI (plus theuv.lockresolved version) that every range treats alike. The specifier, read withpackaging, drives✅and❌, and a release it accepts but that came out after the range was superseded renders as–, like a future Python. So does a release of a major that came out after the last release of a superseded range: no release of that range ever met it.
Both axes then keep only the support envelope of the project (see
_envelope()): the ranges from the newest one down to the oldest one that
supports the floor of the newest range or a later version, and the versions from
the oldest one these ranges support. The <!-- envelope --> region lists the
obsolete bounds of the envelopes of several axes: see envelope_bounds().
The rendered tables back the always-on matrix Sphinx directive (see
MatrixDirective), so a project’s install.md can embed a live matrix
kept current by the click-extra refresh-directives command instead of a
static table maintained by hand. The generation functions shell out to git;
they carry no runtime CLI relevance and are kept out of the click_extra
public API.
- click_extra.sphinx.matrix.PYTHON_RELEASE_DATES: dict[str, str] = {'2.7': '2010-07-03', '3.0': '2008-12-03', '3.1': '2009-06-27', '3.10': '2021-10-04', '3.11': '2022-10-24', '3.12': '2023-10-02', '3.13': '2024-10-07', '3.14': '2025-10-07', '3.15': '2026-10-09', '3.2': '2011-02-20', '3.3': '2012-09-29', '3.4': '2014-03-16', '3.5': '2015-09-13', '3.6': '2016-12-23', '3.7': '2018-06-27', '3.8': '2019-10-14', '3.9': '2020-10-05'}¶
ISO release date of each
X.YPython final release.Used to cap
✅cells when a release range’s Python support is derived from arequires-python-style floor rather than an explicit classifier list: a floor without upper bound would otherwise over-claim support for Pythons that did not yet exist while the range was current. Update this table each October when a new final release ships.
- click_extra.sphinx.matrix.SUPPORTED_CELL: str = '✅'¶
Cell marking a version the release declares support for.
- click_extra.sphinx.matrix.FORBIDDEN_CELL: str = '❌'¶
Cell marking a version the release’s own metadata rules out.
Reserved for a hard incompatibility: a version an installer refuses outright because it falls below the declared floor, on or above the declared ceiling, or inside an exclusion clause.
- click_extra.sphinx.matrix.UNDECLARED_CELL: str = '–'¶
Cell marking a version the release neither supports nor forbids.
Covers the flavours of absence of evidence: a version its declaration lets through but that came out after the range was superseded or belongs to a major that came out after its last release, and, on the
pythonaxis, a Python that was released but never added to the classifier list. Neither is a statement of incompatibility, so spelling themFORBIDDEN_CELLwould over-claim. Spelling the first oneSUPPORTED_CELLwould over-claim the other way: an open-ended specifier likeclick>=8.0accepts every future release, whether it works or not.
- click_extra.sphinx.matrix.DEFAULT_TAG_PATTERN: str = '^v\\d+\\.\\d+\\.\\d+$'¶
Default regex for release tags (
vMAJOR.MINOR.PATCH).
- click_extra.sphinx.matrix.DEFAULT_TAGS_SORT: str = 'version:refname'¶
Default
git tag --sortargument.
- click_extra.sphinx.matrix.NEWEST_FIRST: str = 'newest-first'¶
Ordering value: highest version / most recent release first.
- click_extra.sphinx.matrix.OLDEST_FIRST: str = 'oldest-first'¶
Ordering value: lowest version / oldest release first.
- click_extra.sphinx.matrix.ORDER_CHOICES: tuple[str, ...] = ('newest-first', 'oldest-first')¶
Allowed values of the
column-orderandrow-ordermatrix options.
- click_extra.sphinx.matrix.PYPI_JSON_URL: str = 'https://pypi.org/pypi/{name}/json'¶
PyPI’s JSON API endpoint for a project, formatted with its normalized name.
- click_extra.sphinx.matrix.PYPI_TIMEOUT: float = 10¶
Seconds to wait for PyPI before the release lookup gives up.
- click_extra.sphinx.matrix.POETRY_VERSION_PATTERN: str = '(?P<release>\\d+(?:\\.\\d+){0,2})(?P<suffix>(?:[-_.]?[a-z]+\\d*)*)'¶
The version a Poetry caret or tilde range opens on.
Up to three release components, then an optional PEP 440 pre-, post- or dev-release suffix. The suffix stays on the floor and plays no part in the ceiling, as poetry-core reads it:
^2.0.0.post1means>=2.0.0.post1,<3.0.0.
- click_extra.sphinx.matrix.POETRY_CARET_RE = re.compile('^\\^\\s*(?P<release>\\d+(?:\\.\\d+){0,2})(?P<suffix>(?:[-_.]?[a-z]+\\d*)*)$', re.IGNORECASE)¶
Poetry’s caret range.
- click_extra.sphinx.matrix.POETRY_TILDE_RE = re.compile('^~\\s*(?P<release>\\d+(?:\\.\\d+){0,2})(?P<suffix>(?:[-_.]?[a-z]+\\d*)*)$', re.IGNORECASE)¶
Poetry’s tilde range.
Deliberately also matches a bare
~X. It cannot swallow PEP 440’s~=, whose=is not a digit.
- click_extra.sphinx.matrix.POETRY_WILDCARD_RE = re.compile('^(?:\\*|(\\d+)(?:\\.(\\d+))?\\.\\*)$')¶
Poetry’s wildcard range.
A bare
*allows any version at all.X.*andX.Y.*pin their series, without PEP 440’s leading==.
- class click_extra.sphinx.matrix.PythonMatrixGroup(first_tag, last_tag, first_date, python_versions, spec='')[source]¶
Bases:
NamedTupleA contiguous run of release tags sharing the same Python support set.
Create new instance of PythonMatrixGroup(first_tag, last_tag, first_date, python_versions, spec)
- spec: str¶
The range’s declared
requires-python, raw and unparsed.Kept alongside the supported set because the two answer different questions: the set is what the release claims (its classifier list), while the spec is what an installer enforces. A version outside the spec is a hard incompatibility, a version merely missing from the set is an undeclared one. See
UNDECLARED_CELL.
- click_extra.sphinx.matrix.python_versions_released_by(cutoff_date, release_dates=None)[source]¶
Return Python
X.Yversions released on or beforecutoff_date.
- click_extra.sphinx.matrix.parse_python_spec(spec)[source]¶
Parse a Python version spec into
(floor, ceiling, excluded).Supports:
PEP 440:
>=3.10,>=3.10,<3.14,>=2.7, !=3.0.*, !=3.1.*.Poetry caret:
^3.7expands to>=3.7, <4.0.Poetry tilde:
~3.7expands to>=3.7, <3.8.setup.py’spython_requires(uses the same PEP 440 syntax asrequires-python).
- Return type:
- Returns:
(floor, ceiling, excluded)where each offloorandceilingis a bare"X.Y"string (empty if unspecified) andexcludedis the set of bare"X.Y"values one per!=X.Y.*clause. The ceiling is exclusive:<3.14means 3.14 itself is not supported. Returns("", "", set())when no floor is found.
- click_extra.sphinx.matrix.memoized_history()[source]¶
Serve every git read made inside from one memo.
A refresh renders a block per axis on every page of a project, and each block walks the same tags of the same working tree. Inside this context the tag listing and each tag’s release files are read once, whatever the floor or pattern each block applies. The memo lives no longer than the context: a tag pushed between two refreshes is seen by the second. Nesting reuses the outer memo.
- click_extra.sphinx.matrix.python_matrix_groups(project_root, *, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', version_floor='', release_dates=None)[source]¶
Walk every release tag in
project_rootand group consecutive releases that declare the same effective set of Python versions.- Parameters:
project_root (
Path) – git working tree to walk.tag_pattern (
str) – regex matching release tags. Defaults toDEFAULT_TAG_PATTERN(vMAJOR.MINOR.PATCH).tags_sort (
str) – value passed togit tag --sort. Defaults toDEFAULT_TAGS_SORT(version:refname).version_floor (
str) – drop every release tag below this bare version ("4.9.0","4.9"). Empty (the default) keeps all tags. Applied before grouping so the oldest surviving group starts at the floor.release_dates (
dict[str,str] |None) – Python-version release-date table used for the cap. Defaults toPYTHON_RELEASE_DATES.
- Return type:
- Returns:
List of
PythonMatrixGroup, in chronological order. Tags with no Python declaration in any recognized form are skipped.
- click_extra.sphinx.matrix.python_matrix_table(project_root, label, *, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', python_floor='', version_floor='', column_order='newest-first', row_order='newest-first', show_date=False, full_history=False, release_dates=None)[source]¶
Render the Python compatibility matrix as a GitHub-flavored markdown table.
By default newest releases sit on top and newest Python versions on the left, so the most recent compatibility information always sits in the upper-left corner of the table;
row_orderandcolumn_orderflip either axis.The table keeps the support envelope of the project (see
_envelope()). Consecutive ranges whose cells then coincide merge into one row.- Parameters:
project_root (
Path) – git working tree to walk.label (
str) – the header column name (usually the package name, like"click-extra"or"repomatic"). Rendered in backticks.tag_pattern (
str) – passed topython_matrix_groups().tags_sort (
str) – passed topython_matrix_groups().python_floor (
str) – drop every PythonX.Ycolumn below this bare version ("3.9"). Empty (the default) sets no floor. The support envelope reads its floor from the columns left (see_envelope()): apython_floorabove the oldest Python of the newest range raises that floor, which drops the ranges below the oldest one supporting it or a later Python. Underfull_history,python_floordrops columns only.version_floor (
str) – passed topython_matrix_groups()to drop release rows below a bare package version.column_order (
str) – left-to-right ordering of the Python columns:NEWEST_FIRST(default) orOLDEST_FIRST.row_order (
str) – top-to-bottom ordering of the release rows:NEWEST_FIRST(default) orOLDEST_FIRST.show_date (
bool) – follow each row label with the release date of its first tag, like6.0.x (2025-09-25) → 9.x.full_history (
bool) – keep every release range, not just the support envelope.release_dates (
dict[str,str] |None) – passed topython_matrix_groups().
- Return type:
- Returns:
rendered markdown table, or the empty string when no group was collected.
- Raises:
ValueError – on an unrecognized
column_orderorrow_order.
- class click_extra.sphinx.matrix.DependencyMatrixGroup(first_tag, last_tag, first_date, spec, last_date='')[source]¶
Bases:
NamedTupleA contiguous run of release tags declaring the same dependency spec.
Create new instance of DependencyMatrixGroup(first_tag, last_tag, first_date, spec, last_date)
- exception click_extra.sphinx.matrix.ReleasesUnreadable[source]¶
Bases:
ExceptionPyPI could not answer for a distribution’s releases.
Raised by
_pypi_releases()only when its caller asked for the read to be required, which the source refresh in_regenerate()does. Live rendering never asks, and keeps the fallback columns.
- click_extra.sphinx.matrix.dependency_matrix_groups(project_root, dep_name, *, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', version_floor='')[source]¶
Group consecutive release tags declaring the same
dep_namespec.Specifiers are compared parsed (see
_spec_identity()), so a re-spelled specifier continues its range:cloup >= 3.0.7rewritten ascloup>=3.0.7by a formatter is no new range. Splitting there would end the older half early, and every release of the dependency published after that would read as undeclared for it. A group keeps the spelling of its first tag.- Parameters:
dep_name (
str) – the distribution whose requirement specifier is tracked (like"click").- Return type:
- Returns:
DependencyMatrixGrouplist in chronological order; tags with no declared requirement fordep_nameare skipped.
- click_extra.sphinx.matrix.dependency_matrix_table(project_root, label, dep_name, *, show_spec=False, show_date=False, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', version_floor='', column_order='newest-first', row_order='newest-first', full_history=False, require_releases=False)[source]¶
Render the
dep_namecompatibility matrix as a markdown table.Each cell classifies a release of
dep_nameagainst a range (see_dependency_cell()). Each column covers a run of releases that every shown range treats alike (see_column_candidates()and_dependency_columns()), labeled like the rows. Headers read from their newest bound,9.4.x←9.3.4, while the columns run newest first. The table keeps the support envelope of the project (see_envelope()), and consecutive ranges whose cells coincide merge into one row. By default newest releases sit on top and newest dependency versions on the left, matching the Python axis;row_orderandcolumn_orderflip either axis.- Parameters:
label (
str) – header column name (the documented package, in backticks).dep_name (
str) – the tracked distribution ("click").show_spec (
bool) – add aSpeccolumn with each range’s raw specifier. A merged row shows the specifier of its oldest range, so ranges then merge only when they also accept the same versions (see_spec_identity()).show_date (
bool) – follow each row label with the release date of its first tag, like6.0.x (2025-09-25) → 9.x.column_order (
str) – left-to-right ordering of the version columns:NEWEST_FIRST(default) orOLDEST_FIRST.row_order (
str) – top-to-bottom ordering of the release rows:NEWEST_FIRST(default) orOLDEST_FIRST.full_history (
bool) – keep every release range, not just the support envelope.require_releases (
bool) – refuse the offline fallback columns, for a caller comparing the result against a checked-in table.
- Return type:
- Returns:
rendered markdown table, or
""when nothing was collected.- Raises:
ValueError – on an unrecognized
column_orderorrow_order.ReleasesUnreadable – under
require_releases, when PyPI cannot answer fordep_name.
- class click_extra.sphinx.matrix.EnvelopeBound(subject, version, date)[source]¶
Bases:
NamedTupleAn obsolete bound of the support envelopes of several axes.
The release bound is the oldest release every envelope keeps. A version bound is the oldest version that a range in scope supports, which can be newer than the oldest column of the matrix of its axis (see
envelope_bounds()).Create new instance of EnvelopeBound(subject, version, date)
- click_extra.sphinx.matrix.envelope_bounds(project_root, package, axes, *, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', require_releases=False)[source]¶
Return the obsolete bounds of the support envelopes of
axes.Each axis keeps its own envelope, as its matrix does (see
_envelope()). A release is in scope when every envelope that leaves out releases keeps it, so the release bound is the newest of their first releases. Each version bound is then the oldest version a range in scope supports, read over those ranges alone: it can be newer than the oldest version of the axis’ matrix, whose older rows support older versions.A release is dated by its tag, a Python by its final release (see
PYTHON_RELEASE_DATES), and a dependency release by PyPI.- Parameters:
- Return type:
- Returns:
the release bound first, when an envelope leaves out releases, then one version bound per axis, in the order of
axes.
- click_extra.sphinx.matrix.envelope_list(project_root, package, axes, *, tag_pattern='^v\\d+\\.\\d+\\.\\d+$', tags_sort='version:refname', require_releases=False)[source]¶
Render the obsolete bounds of the envelopes of
axesas a Markdown list.One item per bound of
envelope_bounds(), which takes every parameter. An item names what the bound limits and the oldest version in scope, then the release date of that version when known.- Return type:
- Returns:
the list, or the empty string when no axis has any data.
- class click_extra.sphinx.matrix.MatrixDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
ContentOffsetMixinRender a package’s compatibility matrix for a given axis.
{matrix} pythonrenders the interpreter matrix (release ranges × Python versions).{matrix} <distribution>(like{matrix} click) renders a dependency matrix (release ranges × that dependency’s versions, from its requirement specifier across the git history). Both emit a GitHub-flavored table parsed by the host document’s parser, so it lands as a real<table>.The table normally lives inside the block as its content, kept current by the offline updater (
update_matrix_blocks(), exposed as theclick-extra refresh-directivescommand). Rendering that embedded copy needs no git access at build time, so shallow clones and read-only build hosts still show the matrix. An empty block falls back to generating from the working tree’s git tags, so a freshly authored block renders before its first refresh.Argument: the axis,
pythonor a distribution name.Options:
:package:sets the header column label. Defaults to the name declared in the project’spyproject.toml, then to the name of its folder.:path:names the git working tree to walk, absolute or relative to the documented project’s git root. Defaults to that git root.:version-floor:drops the release rows below this package version.:tag-pattern:is the regex selecting release tags. Defaults toDEFAULT_TAG_PATTERN.:column-order:orders the version columns from left to right:newest-first(default) oroldest-first.:row-order:orders the release rows from top to bottom:newest-first(default) oroldest-first.:python-floor:drops the Python columns belowX.Y(python axis).:show-spec:adds a raw-specifierSpeccolumn (dependency axis).:show-date:follows each row label with its first release date.:full-history:keeps every release range, not just the support envelope (see_envelope()).
The git fallback is resilient: a missing git binary, a non-repository path, or a tag-less repository logs a build warning and renders nothing rather than aborting the build.
- has_content = True¶
May the directive have content?
- required_arguments = 1¶
Number of required directive arguments.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- option_spec: ClassVar[OptionSpec] = {'column-order': <function _order_option>, 'full-history': <function flag>, 'package': <function unchanged>, 'path': <function unchanged>, 'python-floor': <function unchanged>, 'row-order': <function _order_option>, 'show-date': <function flag>, 'show-spec': <function flag>, 'tag-pattern': <function unchanged>, 'version-floor': <function unchanged>}¶
Mapping of option names to validator functions.
- click_extra.sphinx.matrix.setup(app)[source]¶
Register the always-on
matrixdirective onapp.Called from
click_extra.sphinx.setup()so projects only need to list"click_extra.sphinx"in theirextensions. Unlike theclick:*/python:*families, the directive is registered unconditionally: it runs a canned matrix generator, not user-supplied Python, so it needs no opt-in.- Return type:
- click_extra.sphinx.matrix.rewrite_matrix_blocks(text, base_dir)[source]¶
Return
textwith everymatrixblock’s table regenerated.Handles both forms: the
{matrix} <axis>directive fence (rendered by Sphinx) and the<!-- matrix <axis> -->comment region (which renders as a real table on GitHub too). Each keeps its axis and options; only the embedded table is replaced. Every<!-- envelope <axis>... -->region gets its list of obsolete bounds regenerated too (seeenvelope_list()). The walk is fence-aware: a{matrix}example nested inside a longer code fence is a documented illustration, copied verbatim and never refreshed. A block whose generation fails (non-repository path, missing git, unreadable PyPI, no data) is left byte-for-byte untouched.- Return type:
- click_extra.sphinx.matrix.update_matrix_blocks(paths, *, check=False)[source]¶
Refresh every
{matrix}block and envelope region of Markdown sources.See
click_extra.markdown.blocks.update_blocks()for the walk, write, andcheck-mode contract.Every block of the refresh reads the git history through one memo, see
memoized_history(): a project’s tags are listed once, and each tag’s release files read once, however many pages and axes render them.