repomatic.pyproject module¶
Utilities for reading and interpreting pyproject.toml metadata.
Provides standalone functions for extracting project name and source paths
from pyproject.toml. These functions have no dependency on the
Metadata singleton and can be used independently.
- repomatic.pyproject.BUMPVERSION_SOURCES: Final[tuple[tuple[str, tuple[str, ...]], ...]] = (('.bumpversion.toml', ()), ('pyproject.toml', ('tool', 'bumpversion')))¶
Where bump-my-version reads its configuration, in the order it searches.
Each entry pairs a file name with the path of the table holding
current_versionin it: the top level of.bumpversion.toml, or the[tool.bumpversion]table ofpyproject.toml.
- repomatic.pyproject.cached_toml(path)[source]¶
Parse the TOML file at path, once per version of its bytes.
The one parser behind
read_pyproject_toml()andrepomatic.deps.lockfile.LockFile.load(): a lock runs to hundreds of kilobytes, and a single command reads the samepyproject.tomlmany times over.Caution
The
tomlrtdocument is shared by every caller, so treat it as read-only. It keeps the formatting trivia of the file (the tool runner relies on it), which a caller editing the file must not touch:load_pyproject_doc()returns a private, editable parse instead.- Parameters:
path (
Path) – The TOML file to read.- Return type:
- Returns:
The parsed document.
- Raises:
OSError – When the file is missing or cannot be read.
ValueError – When the file is not valid TOML: a
tomlrt.TOMLParseError.
- repomatic.pyproject.read_pyproject_toml(project_root=None)[source]¶
Parse
pyproject.tomlfrom project_root.Parses are cached per file identity (see
cached_toml()), since a single CLI invocation reads the same document many times over: treat the result as read-only.
- repomatic.pyproject.load_pyproject_doc(pyproject_path)[source]¶
Parse a TOML file into a private, editable, round-trippable document.
The counterpart to
read_pyproject_toml(), whose cached document is shared and read-only. This one is parsed afresh on every call and keepstomlrt’s formatting trivia, so the document can be edited and written back with the rest of the file byte-identical.
- repomatic.pyproject.bumpversion_current_version(document, table_path)[source]¶
Read
current_versionfrom the bump-my-version table of a TOML document.
- repomatic.pyproject.get_current_version(project_root=None)[source]¶
Returns the current version as managed by bump-my-version.
Same as calling the CLI:
$ bump-my-version show current_version
Reads the first file of
BUMPVERSION_SOURCESthat declares a version. Each parse is cached per version of the file’s bytes, seecached_toml().
- repomatic.pyproject.uv_table(doc)[source]¶
Return the
[tool.uv]table of a parsedpyproject.toml.- Parameters:
doc (
Any) – Document fromload_pyproject_doc().- Return type:
- Returns:
The
[tool.uv]table, or an empty mapping when the project declares none. Reading a key off the result is therefore always safe; writing one back requires the caller to check the table exists first, since the empty fallback is not attached to doc.
- repomatic.pyproject.dependency_group_names(project_root=None)[source]¶
Every group name declared in
[dependency-groups], sorted.
- repomatic.pyproject.extra_names(project_root=None)[source]¶
Every extra declared in
[project.optional-dependencies], sorted.
- repomatic.pyproject.derive_source_paths(pyproject_data=None)[source]¶
Derive source code directory name from
[project.name].Converts the project name to its importable form by replacing hyphens with underscores, the universal Python convention that all build backends (setuptools, hatchling, flit, uv) follow by default. For example,
name = "extra-platforms"yields["extra_platforms"].
- repomatic.pyproject.resolve_source_paths(config, pyproject_data=None)[source]¶
Resolve workflow source paths from config or auto-derivation.
- Parameters:
- Return type:
- Returns:
List of source directory names, or
Nonewhen no source paths can be determined (paths should be stripped entirely).
- repomatic.pyproject.get_project_name(pyproject_data=None)[source]¶
Read the project name from
pyproject.toml.
- repomatic.pyproject.is_python_project(project_root=None, pyproject_data=None)[source]¶
Detect whether project_root hosts a Python project.
Returns
Truewhen thepyproject.tomlparses cleanly throughpyproject_metadata.StandardMetadata.from_pyproject: it must declare a PEP 621[project]table that respects the standard. Apyproject.tomlthat only carries third-party[tool.*]sections does not qualify, so repositories that merely lean on the file for tool configuration (linters, formatters,[tool.repomatic]itself) are correctly classified as non-Python.- Parameters:
- Return type:
- Returns:
Truewhen the[project]table satisfies PEP 621.
- repomatic.pyproject.is_python_package(project_root=None, pyproject_data=None)[source]¶
Detect whether project_root builds a distributable Python package.
Strictly narrower than
is_python_project(): every package is a Python project, but not every Python project is a package. A uv virtual project declares a PEP 621[project]table purely to carry dependencies, and opts out of being built or installed with[tool.uv] package = false. Blogs, docs sites and dotfiles repos that lean on uv for dependency management all look like this.The distinction matters because the two traits gate different things. A virtual project still has dependencies to lock, a
uv.lockto sync and tests to cover, so it wants everything scoped toPYTHON_ONLY. It has nothing to publish, tag or write release notes for, so it wants nothing scoped toPACKAGE_ONLY.Note
Only uv’s opt-out is recognized. Poetry’s
[tool.poetry] package-modeequivalent is deliberately ignored: repomatic dropped Poetry support in4.0.0and expects standardpyproject.tomlconventions.- Parameters:
- Return type:
- Returns:
Truefor a PEP 621 project that is not a uv virtual project.