# jwodder/versioningit architecture

> Architecture diagram of the GitHub repository jwodder/versioningit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jwodder/versioningit
- Repository: https://github.com/jwodder/versioningit

## Overview

#### Purpose and entry points
`versioningit` is a Python 3.8+ packaging plugin/library that derives a project version from VCS tags, optionally persists version metadata, and integrates with setuptools and Hatch. Primary entry points are the import API in `src/versioningit/__init__.py`, CLI in `src/versioningit/__main__.py`, setuptools integration in `src/versioningit/cmdclass.py`/`src/versioningit/get_cmdclasses.py`, and Hatch plugin integration in `src/versioningit/hatch.py`.

#### Orchestration and version pipeline
`src/versioningit/core.py` is the central coordinator: it loads configured methods, obtains VCS state, converts a tag to a base version, computes a next version where needed, formats the final value, and triggers configured build-time actions. `src/versioningit/basics.py` supplies standard implementations and data shapes used across this pipeline. Domain-specific failures are centralized in `src/versioningit/errors.py`.

#### Configuration and method resolution
Configuration is read from `pyproject.toml` or standalone `versioningit.toml`, then normalized into callable pipeline stages by `src/versioningit/config.py`. `src/versioningit/methods.py` resolves built-in methods, project-local functions, and installed entry-point extensions, creating the main extensibility boundary. This permits replacement of VCS querying, tag conversion, next-version calculation, formatting, and writing behavior without changing orchestration.

#### VCS acquisition boundary
Git and Mercurial are isolated behind `src/versioningit/git.py` and `src/versioningit/hg.py`. They inspect live repositories and supported archive metadata, returning common versioning inputs such as latest tag, commit distance, revision identifier, and dirty state. This separates external command/archive behavior from version policy and lets the core select VCS-specific implementations through configuration.

#### Version calculation and formatting
`src/versioningit/next_version.py` implements built-in version-bumping strategies. `src/versioningit/methods.py` contains configurable method families, including tag-to-version and template-field behavior. Formatting uses repository state to select configured templates for exact, distanced, dirty, or distanced-and-dirty states; output is intended to be packaging-compatible version text.

#### Build/runtime materialization
`src/versioningit/onbuild.py` handles build-time source modifications/hooks, including injecting version details into project files. `src/versioningit/hook.py` supports hook-oriented integration around these actions. The optional write stage can make a computed version available at runtime without requiring VCS metadata in installed distributions. `src/versioningit/cmdclass.py` connects these behaviors to setuptools build commands.

#### Runtime, packaging, and delivery boundaries
The repository is a typed Python package (`src/versioningit/py.typed`) built and configured through `pyproject.toml`. It depends on Python packaging standards (PEP 518 configuration), setuptools or Hatch/Hatchling build execution, Git, and optionally Mercurial; it does not expose a web-service runtime. CI is GitHub Actions under `.github/workflows/test.yml`, including explicit no-VCS/minimum-VCS environments in `.github/workflows/no-vcs.yml` and `.github/workflows/minimum-vcs.yml`.

Main entry points: [`src/versioningit/core.py`](https://github.com/jwodder/versioningit/blob/master/src/versioningit/core.py) (Version coordinator), [`src/versioningit/onbuild.py`](https://github.com/jwodder/versioningit/blob/master/src/versioningit/onbuild.py) (Build actions), [`src/versioningit/cmdclass.py`](https://github.com/jwodder/versioningit/blob/master/src/versioningit/cmdclass.py) (Setuptools commands), [`src/versioningit/hatch.py`](https://github.com/jwodder/versioningit/blob/master/src/versioningit/hatch.py) (Hatch plugin)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Entry Points"]
  node_import_api["Import API<br/>Python API<br/>[__init__.py]"]
  node_cli["CLI<br/>[__main__.py]"]
end

subgraph group_engine["Version Engine"]
  node_core["Version coordinator<br/>pipeline orchestrator<br/>[core.py]"]
  node_config["Configuration loader<br/>[config.py]"]
  node_methods{{"Method resolver<br/>extension boundary<br/>[methods.py]"}}
  node_basics["Standard methods<br/>pipeline primitives<br/>[basics.py]"]
  node_next_version["Version bumping<br/>version strategy<br/>[next_version.py]"]
  node_errors["Domain errors<br/>error model<br/>[errors.py]"]
end

subgraph group_vcs["VCS Boundary"]
  node_git["Git provider<br/>VCS adapter<br/>[git.py]"]
  node_hg["Mercurial provider<br/>VCS adapter<br/>[hg.py]"]
end

subgraph group_build["Build Integration"]
  node_onbuild["Build actions<br/>materialization<br/>[onbuild.py]"]
  node_hook["Build hooks<br/>hook integration<br/>[hook.py]"]
  node_setuptools["Setuptools commands<br/>build integration<br/>[cmdclass.py]"]
  node_get_cmdclasses["cmdclass factory<br/>setuptools API<br/>[get_cmdclasses.py]"]
  node_hatch["Hatch plugin<br/>build integration<br/>[hatch.py]"]
end

subgraph group_delivery["Packaging &amp; CI"]
  node_package_config["Package configuration<br/>PEP 518 metadata<br/>[pyproject.toml]"]
  node_ci["GitHub Actions<br/>CI<br/>[test.yml]"]
end

node_import_api -->|"computes version"| node_core
node_cli -->|"invokes"| node_core
node_package_config -->|"versioning settings"| node_config
node_config -->|"normalizes stages"| node_methods
node_methods -->|"configured callables"| node_core
node_core -->|"uses standard stages"| node_basics
node_core -->|"calculates next version"| node_next_version
node_core -->|"queries when configured"| node_git
node_core -->|"queries when configured"| node_hg
node_core -->|"triggers build actions"| node_onbuild
node_core -->|"raises"| node_errors
node_hook -->|"runs hooks around"| node_onbuild
node_get_cmdclasses -->|"provides command classes"| node_setuptools
node_setuptools -->|"computes build version"| node_core
node_setuptools -->|"materializes metadata"| node_onbuild
node_hatch -->|"computes build version"| node_core
node_hatch -->|"materializes metadata"| node_onbuild
node_ci -->|"builds and tests"| node_package_config

click node_import_api "https://github.com/jwodder/versioningit/blob/master/src/versioningit/__init__.py"
click node_cli "https://github.com/jwodder/versioningit/blob/master/src/versioningit/__main__.py"
click node_core "https://github.com/jwodder/versioningit/blob/master/src/versioningit/core.py"
click node_config "https://github.com/jwodder/versioningit/blob/master/src/versioningit/config.py"
click node_methods "https://github.com/jwodder/versioningit/blob/master/src/versioningit/methods.py"
click node_basics "https://github.com/jwodder/versioningit/blob/master/src/versioningit/basics.py"
click node_next_version "https://github.com/jwodder/versioningit/blob/master/src/versioningit/next_version.py"
click node_errors "https://github.com/jwodder/versioningit/blob/master/src/versioningit/errors.py"
click node_git "https://github.com/jwodder/versioningit/blob/master/src/versioningit/git.py"
click node_hg "https://github.com/jwodder/versioningit/blob/master/src/versioningit/hg.py"
click node_onbuild "https://github.com/jwodder/versioningit/blob/master/src/versioningit/onbuild.py"
click node_hook "https://github.com/jwodder/versioningit/blob/master/src/versioningit/hook.py"
click node_setuptools "https://github.com/jwodder/versioningit/blob/master/src/versioningit/cmdclass.py"
click node_get_cmdclasses "https://github.com/jwodder/versioningit/blob/master/src/versioningit/get_cmdclasses.py"
click node_hatch "https://github.com/jwodder/versioningit/blob/master/src/versioningit/hatch.py"
click node_package_config "https://github.com/jwodder/versioningit/blob/master/pyproject.toml"
click node_ci "https://github.com/jwodder/versioningit/blob/master/.github/workflows/test.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_import_api,node_cli toneBlue
class node_core,node_config,node_methods,node_basics,node_next_version,node_errors toneAmber
class node_git,node_hg toneMint
class node_onbuild,node_hook,node_setuptools,node_get_cmdclasses,node_hatch toneRose
class node_package_config,node_ci toneIndigo
```

## Components

### Entry Points

- [Import API](https://github.com/jwodder/versioningit/blob/master/src/versioningit/__init__.py): Python API · `src/versioningit/__init__.py`
- [CLI](https://github.com/jwodder/versioningit/blob/master/src/versioningit/__main__.py): Python CLI · `src/versioningit/__main__.py`

### Version Engine

- [Version coordinator](https://github.com/jwodder/versioningit/blob/master/src/versioningit/core.py): pipeline orchestrator · Runs configured version stages and build actions. · `src/versioningit/core.py`
- [Configuration loader](https://github.com/jwodder/versioningit/blob/master/src/versioningit/config.py): configuration · Reads pyproject.toml or versioningit.toml and normalizes stages. · `src/versioningit/config.py`
- [Method resolver](https://github.com/jwodder/versioningit/blob/master/src/versioningit/methods.py): extension boundary · Resolves built-ins, local callables, and entry-point extensions. · `src/versioningit/methods.py`
- [Standard methods](https://github.com/jwodder/versioningit/blob/master/src/versioningit/basics.py): pipeline primitives · `src/versioningit/basics.py`
- [Version bumping](https://github.com/jwodder/versioningit/blob/master/src/versioningit/next_version.py): version strategy · `src/versioningit/next_version.py`
- [Domain errors](https://github.com/jwodder/versioningit/blob/master/src/versioningit/errors.py): error model · `src/versioningit/errors.py`

### VCS Boundary

- [Git provider](https://github.com/jwodder/versioningit/blob/master/src/versioningit/git.py): VCS adapter · Reads repositories and supported archive metadata. · `src/versioningit/git.py`
- [Mercurial provider](https://github.com/jwodder/versioningit/blob/master/src/versioningit/hg.py): VCS adapter · Reads repositories and supported archive metadata. · `src/versioningit/hg.py`

### Build Integration

- [Build actions](https://github.com/jwodder/versioningit/blob/master/src/versioningit/onbuild.py): materialization · Modifies source files or injects version details during builds. · `src/versioningit/onbuild.py`
- [Build hooks](https://github.com/jwodder/versioningit/blob/master/src/versioningit/hook.py): hook integration · `src/versioningit/hook.py`
- [Setuptools commands](https://github.com/jwodder/versioningit/blob/master/src/versioningit/cmdclass.py): build integration · `src/versioningit/cmdclass.py`
- [cmdclass factory](https://github.com/jwodder/versioningit/blob/master/src/versioningit/get_cmdclasses.py): setuptools API · `src/versioningit/get_cmdclasses.py`
- [Hatch plugin](https://github.com/jwodder/versioningit/blob/master/src/versioningit/hatch.py): build integration · `src/versioningit/hatch.py`

### Packaging & CI

- [Package configuration](https://github.com/jwodder/versioningit/blob/master/pyproject.toml): PEP 518 metadata · Defines build and versioning configuration. · `pyproject.toml`
- [GitHub Actions](https://github.com/jwodder/versioningit/blob/master/.github/workflows/test.yml): CI · Tests normal, no-VCS, and minimum-VCS environments. · `.github/workflows/test.yml`

## Connections

- Import API → Version coordinator: computes version
- CLI → Version coordinator: invokes
- Package configuration → Configuration loader: versioning settings
- Configuration loader → Method resolver: normalizes stages
- Method resolver → Version coordinator: configured callables
- Version coordinator → Standard methods: uses standard stages
- Version coordinator → Version bumping: calculates next version
- Version coordinator → Git provider: queries when configured
- Version coordinator → Mercurial provider: queries when configured
- Version coordinator → Build actions: triggers build actions
- Version coordinator → Domain errors: raises
- Build hooks → Build actions: runs hooks around
- cmdclass factory → Setuptools commands: provides command classes
- Setuptools commands → Version coordinator: computes build version
- Setuptools commands → Build actions: materializes metadata
- Hatch plugin → Version coordinator: computes build version
- Hatch plugin → Build actions: materializes metadata
- GitHub Actions → Package configuration: builds and tests
