repomatic.metadata.core module¶
Extract metadata from repository and Python projects to be used by GitHub workflows.
This module solves a fundamental limitation of GitHub Actions: a workflow run is
triggered by a singular event, which might encapsulate multiple commits. GitHub only
exposes github.event.head_commit (the most recent commit), but workflows often need
to process all commits in the push event.
This is critical for releases, where two commits are pushed together:
[changelog] Release vX.Y.Z: the release commit to be tagged and published[changelog] Post-release bump vX.Y.Z → vX.Y.Z: the next dev cycle’s bump
Since github.event.head_commit only sees the post-release bump, this module extracts
the full commit range from the push event and identifies release commits that need
special handling (tagging, PyPI publishing, GitHub release creation).
Output shapes
Every key is printed to the environment file
as one key=value line. Values take three shapes:
is_python_project=true
doc_files="changelog.md" "readme.md" "docs/license.md"
new_commits_matrix={"commit": ["346ce66…", "6f27db4…"], "include": [{"commit": "346ce66…", "short_sha": "346ce66"}]}
A scalar prints bare. A list prints as space-joined, individually quoted items,
not a JSON array: workflow if: conditions test membership with a padded
contains() against that string. A matrix prints as inlined JSON for
fromJSON() to parse into a job matrix. See
format_github_value() for the encoding, and
Dialect for the other output formats.
The full key inventory is generated from this module rather than listed here, so
it cannot go stale: run repomatic show-metadata --list-keys, or read the rendered
table in the workflows documentation.
- repomatic.metadata.core.FILE_GROUP_KEYS: Final[frozenset[str]] = frozenset({'doc_files', 'gitignore_exists', 'image_files', 'json_files', 'markdown_files', 'pyproject_files', 'python_files', 'shfmt_files', 'workflow_files', 'yaml_files', 'zsh_files'})¶
Metadata keys read off
Metadata.files, the attribute of the same name.The inventory answers them with no CI context, no git history and no
pyproject.toml, soMetadata.dump_factories()reads them there directly.
- repomatic.metadata.core.METADATA_CONFIG_FIELDS: Final[tuple[str, ...]] = ('binaries_sync', 'manpages_script', 'release_assets', 'site_deploy', 'sphinx_builder', 'sphinx_fail_on_warning')¶
Configfields a workflow reads through the metadata output, sorted.Every other field stays out of the output: the subcommand that needs one reads it from
[tool.repomatic]directly. A new field joins this list only when a workflow condition or step reads it, like thebinaries.synctoggle a separatepr-syncstep depends on.
- repomatic.metadata.core.METADATA_KEYS_HEADER_DEFS: tuple[ColumnSpec, ...] = (ColumnSpec(id='key', label='Key', description='', max_width=None, optional=False, sortable=True), ColumnSpec(id='description', label='Description', description='', max_width=None, optional=False, sortable=True))¶
Column definitions for the metadata keys reference table.
- repomatic.metadata.core.metadata_keys_reference()[source]¶
Build the metadata keys reference as table rows.
Returns a list of
(key, description)tuples for all keys produced byMetadata.dump(), including theMETADATA_CONFIG_FIELDSof[tool.repomatic]. Rows are unsorted: sorting is handled by the CLI’sSortByOption.
- repomatic.metadata.core.all_metadata_keys()[source]¶
Returns the set of all valid metadata key names.
- repomatic.metadata.core.METADATA_VALUE_OPTIONS: frozenset[str] = frozenset({'--format', '--output', '--output-format', '--sort-by', '-o'})¶
Options on the
show-metadatacommand consuming the token that follows them.Needed by
unknown_metadata_keys()to tell a positional key from an option’s value while reading a workflow’srun:line.--formatis the spelling of releases before8.0.0, kept so that a workflow pinned to one of them still parses.Listed here rather than derived, and pinned against the real command by repomatic’s own test suite, so an option added later cannot quietly turn its value into a token the lint reports as an unknown key.
- repomatic.metadata.core.METADATA_SUBCOMMAND: Final[str] = 'show-metadata'¶
The subcommand that prints the metadata keys a workflow asks for.
- repomatic.metadata.core.REMOVED_METADATA_ALIAS: Final[str] = 'metadata'¶
The alias of
METADATA_SUBCOMMANDthat8.0.0removed.A workflow still calling it fails at its first job, so the readers below recognize it in order to report it.
- repomatic.metadata.core.RENAMED_METADATA_OPTIONS: Final[dict[str, str]] = {'--format': '--output-format'}¶
Options of
METADATA_SUBCOMMANDthat8.0.0renamed, mapped to the new name.The command rejects the old spelling with a
UsageError, so a workflow still passing one fails at its first job, like a call of the removed alias. Header-only sync never reads the job body holding the call, so the readers below recognize the old spelling in order to report it.
- class repomatic.metadata.core.MetadataRequest(path, job_id, keys, unknown, removed_alias, renamed_options=())[source]¶
Bases:
NamedTupleThe metadata one workflow step asks for.
Create new instance of MetadataRequest(path, job_id, keys, unknown, removed_alias, renamed_options)
- removed_alias: bool¶
Whether the step calls the
REMOVED_METADATA_ALIASspelling.
- renamed_options: tuple[str, ...]¶
The
RENAMED_METADATA_OPTIONSthe step still passes, sorted.
- repomatic.metadata.core.unknown_metadata_keys(workflows, package)[source]¶
Read every metadata call of workflows, and the keys it gets wrong.
The one scan behind the
lint-repocheck and therepomatic initwarning, so the two verdicts cannot disagree about what arun:line requests.- Parameters:
- Return type:
- Returns:
One entry per step that calls the metadata subcommand with keys, or that calls the removed alias or passes a renamed option at all, in workflow order. A step requesting only valid keys is listed with no unknown key.
- class repomatic.metadata.core.Metadata[source]¶
Bases:
EnvironmentMetadata,GitMetadata,MatrixMetadata,ProjectMetadataMetadata class.
Implemented as a singleton: every
Metadata()call returns the same instance within a process, and each property keeps the first value it reads. Env vars do not change during a single CLI invocation. Project files can: a command that rewrites one, likebump-version, reads the new content throughget_current_version(), not through a cached property. Usereset()in test teardown to discard the cached instance between tests.- classmethod reset()[source]¶
Discard the singleton so the next call creates a fresh instance.
Intended for test teardown only. Production code should never call this.
- Return type:
- property cloudflare_project: str[source]¶
The Cloudflare Pages project the site deploys into.
[tool.repomatic] site.cloudflare-projectwhen it names one, else the repository name. The deploy job reads this key, and thecloudflare-pagesandcloudflare-r2commands fall back to it when--projectis absent, so all of them address the same project.- Returns:
The project name, empty when neither source names one.
- property files: FileInventory[source]¶
What this repository holds on disk,
.gitignoreapplied.The inventory is its own concern (
repomatic.file_inventory): answering “which Markdown files are there” needs no CI context, no git history and nopyproject.toml. TheFILE_GROUP_KEYSoutput keys read the inventory attribute of the same name.
- property current_version: str | None[source]¶
Returns the current version.
Current version is fetched from the
bump-my-versionconfiguration file.During a release, two commits are bundled into a single push event:
[changelog] Release vX.Y.Z: freezes the version to the release number[changelog] Post-release bump vX.Y.Z → vX.Y.Z: the next dev version
In this situation, the current version returned is the one from the most recent commit (the post-release bump), which represents the next development version. Use
released_versionto get the version from the release commit.The commit matrix lists the new commits oldest first, so the most recent one is its last entry.
- property released_version: str | None[source]¶
Returns the version of the release commit.
During a release push event, this extracts the version from the
[changelog] Release vX.Y.Zcommit, which is distinct fromcurrent_version(the post-release bump version).Returns
Noneif no release commit is found in the current event.
- dump_factories()[source]¶
Lazy value factories for every metadata key, in output order.
Each value is computed only when its key is included, so
keys=("is_python_project",)skipsnuitka_matrixand the git history walk it pulls in.Split out of
dump()so the key inventory is inspectable without computing anything:tests/test_metadata.pyasserts these names match_METADATA_KEY_DESCRIPTIONSplusMETADATA_CONFIG_FIELDS, which is what keeps--list-keys,all_metadata_keys()and the emitted output from drifting apart.Derived from
_METADATA_KEY_DESCRIPTIONSrather than re-listing every key: most keys read the attribute of the same name, on this instance or onfilesfor theFILE_GROUP_KEYS, so only the handful whose value is not a plain attribute carry an explicit factory.
- dump(dialect=Dialect.github, keys=())[source]¶
Returns metadata in the specified format.
Defaults to GitHub dialect. When keys is non-empty, only the requested keys are computed and included in the output. Filtered-out keys are never accessed, so callers requesting a small subset avoid triggering expensive dependent computations (git history walks, file system scans, build matrix expansion). See
dump_factories().- Return type: