srdatalog.viz.introspect

Import a user’s .py program file and find its Program instance.

The auto-generated files produced by tools/nim_to_dsl.py all follow the same shape:

def build_<name>_program(meta: dict[str, int] | None = None) -> Program:
    ...

Users can also write programs that just construct a Program at module top level. This module handles both shapes and plumbs optional meta.json + entry overrides through.

Module Contents

Functions

load_program

Import the .py file, discover and invoke a Program builder.

API

exception srdatalog.viz.introspect.ProgramDiscoveryError[source]

Bases: RuntimeError

Raised when load_program can’t find or build a Program.

Initialization

Initialize self. See help(type(self)) for accurate signature.

srdatalog.viz.introspect.load_program(path: str | pathlib.Path, *, entry: str | None = None, meta: dict | str | pathlib.Path | None = None) srdatalog.dsl.Program[source]

Import the .py file, discover and invoke a Program builder.

Discovery order (stops at first match):

  1. entry arg — explicit function name; takes precedence.

  2. A top-level callable matching build_*_program.

  3. A module-level Program instance (non-callable).

meta — dataset_const metadata. Passed to the builder if the builder accepts a positional arg. Can be:

  • dict: passed as-is

  • str / Path: loaded as JSON

  • None: builder called with no args