repomatic.init.tool_config module

Merge the bundled [tool.*] templates into a pyproject.toml.

Each ToolConfigComponent ships its section in the native format of its tool, under repomatic/data/. A missing section is installed from the template. An existing one is left alone, or re-derived from the template on every sync while the local additions are grafted back on, depending on its SyncMode.

repomatic.init.tool_config.PYPROJECT_FMT_INDENT = 2

Spaces pyproject-fmt puts before each row of a multi-line array, its default.

_graft_local_additions lays out a rebuilt multi-line array at this indent. tomlrt’s own fallback is four spaces, which the format-pyproject job rewrites in a pull request of its own.

repomatic.init.tool_config.TOOL_CONFIG_COMPONENTS: dict[str, ToolConfigComponent] = {'bumpversion': ToolConfigComponent(name='bumpversion', description='bump-my-version configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='bumpversion.toml', tool_section='tool.bumpversion', sync_mode=<SyncMode.ONGOING: 2>, customizable_entries=(), legacy_table='', preserved_keys=('current_version',), graft_identity_keys=('filename', 'glob', 'key_path', 'replace'), overlay=False), 'coverage': ToolConfigComponent(name='coverage', description='Coverage.py measurement and reporting configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='coverage.toml', tool_section='tool.coverage', sync_mode=<SyncMode.BOOTSTRAP: 1>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'lychee': ToolConfigComponent(name='lychee', description='Lychee link checker configuration', init_default=<InitDefault.INCLUDE: 1>, scope=<RepoScope.AWESOME_ONLY: 2>, files=(), config_key='', ephemeral=False, location_field='', source_file='lychee.toml', tool_section='tool.lychee', sync_mode=<SyncMode.ONGOING: 2>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'mdformat': ToolConfigComponent(name='mdformat', description='mdformat Markdown formatter configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='mdformat.toml', tool_section='tool.mdformat', sync_mode=<SyncMode.BOOTSTRAP: 1>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'mypy': ToolConfigComponent(name='mypy', description='Mypy type checking configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='mypy.toml', tool_section='tool.mypy', sync_mode=<SyncMode.BOOTSTRAP: 1>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'pytest': ToolConfigComponent(name='pytest', description='Pytest test configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='pytest.toml', tool_section='tool.pytest', sync_mode=<SyncMode.BOOTSTRAP: 1>, customizable_entries=(('addopts', '--cov=.'),), legacy_table='ini_options', preserved_keys=(), graft_identity_keys=(), overlay=False), 'ruff': ToolConfigComponent(name='ruff', description='Ruff linter/formatter configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='ruff.toml', tool_section='tool.ruff', sync_mode=<SyncMode.BOOTSTRAP: 1>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'typos': ToolConfigComponent(name='typos', description='Typos spell checker configuration', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='typos.toml', tool_section='tool.typos', sync_mode=<SyncMode.ONGOING: 2>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=False), 'uv': ToolConfigComponent(name='uv', description='uv resolver pin and dependency cooldown policy', init_default=<InitDefault.EXPLICIT: 3>, scope=<RepoScope.ALL: 1>, files=(), config_key='', ephemeral=False, location_field='', source_file='uv.toml', tool_section='tool.uv', sync_mode=<SyncMode.ONGOING: 2>, customizable_entries=(), legacy_table='', preserved_keys=(), graft_identity_keys=(), overlay=True)}

The tool config components, by name: what init_config() accepts.

repomatic.init.tool_config.merge_tool_config(content, comp)[source]

Merge the template of comp into the pyproject.toml text content.

A missing section is installed from the template. An existing one is left alone in BOOTSTRAP mode. In ONGOING mode it is re-derived from the template, or, for a partial template (overlay), only the keys the template owns are updated in place.

Parameters:
  • content (str) – The current pyproject.toml content.

  • comp (ToolConfigComponent) – The component whose section is merged.

Return type:

str | None

Returns:

The new content, or None when the section needs no change.

repomatic.init.tool_config.init_config(config_type, pyproject_path=None)[source]

Merge the template of one tool config into a pyproject.toml file.

Reads the file and hands it to merge_tool_config(). The file itself is left alone: the caller writes the returned content.

Parameters:
  • config_type (str) – The component name (like "ruff" or "bumpversion").

  • pyproject_path (Path | None) – Path to pyproject.toml. Defaults to ./pyproject.toml.

Return type:

str | None

Returns:

The modified pyproject.toml content, or None when no change is needed or the file does not exist.

Raises:

ValueError – If no tool config component carries that name.

repomatic.init.tool_config.adopted_ongoing_configs(output_dir)[source]

Return the ongoing tool configs whose section pyproject.toml already carries.

EXPLICIT governs adoption, not upkeep: it keeps a bare init from pushing [tool.typos] onto a repository that never asked for one. Once the section is there the repository has asked, so an ONGOING component rejoins the bare-init set and resumes tracking the bundled template.

Without this the two flags cancel out. The only sync that ever runs unattended is the bare init the sync-repomatic job calls, so an ONGOING section is otherwise re-derived only when a human types its component name, and a [tool.typos] written by hand sits indefinitely beside a bundled template it never adopts a single rule from.

BOOTSTRAP components stay out: their template is a starting point the repository owns outright after the first write, and re-selecting one would revert deliberate local edits.

Parameters:

output_dir (Path) – Repository root holding pyproject.toml.

Return type:

set[str]

Returns:

Component names to add to a bare init selection. Empty when the file is absent, unparsable, or carries no [tool] table.