Recipe 0
Load current source modules by exact path
Use this helper when working directly from a checked-out ENTITY repository. Numeric source-directory prefixes are valid filesystem paths but not normal Python package identifiers.
from pathlib import Path
import importlib.util
ROOT = Path.cwd() # run from the ENTITY repository root
def load_source(relative_path: str, module_name: str):
path = ROOT / relative_path
if not path.is_file():
raise FileNotFoundError(path)
spec = importlib.util.spec_from_file_location(module_name, path)
if spec is None or spec.loader is None:
raise RuntimeError(f"cannot load {path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
identity_mod = load_source(
"src/01_Core_Runtime/identity/canonical_identity.py",
"entity_identity",
)
fabric_mod = load_source(
"src/30_Universal_Transaction_Fabric/canonical_universal_fabric.py",
"entity_fabric",
)Why use this in the cookbook?
It keeps every example anchored to an exact repository file instead of pretending that a package such as from entity import ... already exists. Production integrations may wrap or package these modules differently.
Pin what you test
git rev-parse HEAD git status --short
For reproducible qualification, record the exact commit/tag used by the recipe.