session#
In-memory view of the files that check-dev-files inspects and modifies.
The Session follows the Unit of Work pattern together with its
companion Identity Map: every
managed file is loaded once and, on exit, written back only if it changed. Each check
reports its modifications either by mutating one of the managed containers (whose own
changelog is collected here) or by appending to Session.changelog directly.
Resources are discovered lazily through Session.get(); adding another file type
therefore requires implementing
ModifiableResource, without modifying
Session.
- class Session(precommit: ModifiablePrecommit | None = None, pyproject: ModifiablePyproject | None = None)[source]#
Bases:
AbstractContextManagerShared, mutable working-tree state for all check hooks.
Load the managed files with
load()(or pass them in directly, e.g. in tests) and use the session as a context manager so that changed files are dumped once on exit.- classmethod load(precommit: ModifiablePrecommit | None = None) Session[source]#
Create a lazy session, optionally with an injected pre-commit resource.
- get(resource: type[R], /) R[source]#
Return the one session-owned instance of resource, loading it lazily.
- get_path(path: Path | str, /) ModifiablePath[source]#
Return the session-owned generic resource for one working-tree path.
- property precommit: ModifiablePrecommit[source]#
The managed
.pre-commit-config.yamlfile.
- property pyproject: ModifiablePyproject | None[source]#
The managed
pyproject.tomlfile, if the repository has one.
- property pixi: ModifiablePixi[source]#
The managed
pixi.tomlfile.