spec.resolve_unit(spec, name)
Find a unit by its dotted name or by a unique suffix of it.
Parameters
| 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
| Unit |
Unit |
The matching unit. |
Raises
|
KeyError |
If name matches no unit or more than one. |
Examples
from pathlib import Path
from tempfile import TemporaryDirectory
from spotregen import 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 KeyError as exc:
print("KeyError:", exc)
samplepkg.core.calc
KeyError: "unknown unit 'nope'; known: ['samplepkg.core.calc']"