Skip to main content

context.build_context

context.build_context(spec, name)

The regeneration bundle of one unit, as Markdown.

The bundle is everything a generator needs and nothing it must not copy: the architecture (allowed dependencies, conventions, open choices), the unit’s purpose with its pace and the policy of that pace, its intent, the decisions behind it, the public contract without implementation bodies, the contracts of the modules it may import (depends_on), the source of its durable evaluations and the list of its consumers. Whether a regenerated file is accepted is decided by the rule accept/1, babregen.judge.accept, and by nothing else.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec. required
name str Dotted module name, or its unique suffix. required

Returns

Name Type Description
str str The Markdown bundle.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import build_context, load_spec, make_sample_repo

with TemporaryDirectory() as tmp:
    spec = load_spec(make_sample_repo(Path(tmp) / "demo"))
    bundle = build_context(spec, "core.calc")
    print(bundle.splitlines()[0])
    print("def add(a: int, b: int) -> int:" in bundle, "return a + b" in bundle)
# Regeneration bundle: samplepkg.core.calc
True False