Skip to main content

spec.resolve_unit

spec.resolve_unit(spec, name)

Find a unit by its dotted name or by a unique suffix of it.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec. required
name str Dotted module name ("samplepkg.core.calc"), or a suffix that identifies exactly one unit ("core.calc", "calc"). required

Returns

Name Type Description
Unit Unit The matching unit.

Raises

Name Type Description
SpecError If name matches no unit or more than one.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import SpecError, load_spec, make_sample_repo, resolve_unit

with TemporaryDirectory() as tmp:
    spec = load_spec(make_sample_repo(Path(tmp) / "demo"))
    print(resolve_unit(spec, "core.calc").name)
    try:
        resolve_unit(spec, "nope")
    except SpecError as exc:
        print("SpecError:", exc)
samplepkg.core.calc
SpecError: unknown unit 'nope'; known: ['samplepkg.core.calc']