Skip to content

output modes

Everything that differs between output modes, in one table. Adding a mode, or changing which models it takes, which output functions render it or which template wraps it, happens here.

opm.output_modes

The output modes opm can compile an ODD for, in one table.

Everything that differs between output modes is recorded here: which ODD models take part, which output functions render them and with which text handling, whether web components may load, which template wraps the result and where a project configures it, and how --preview shows it. The compiler, the generated modules, the transform entry points and the CLI all look a mode up instead of testing its name.

JSON output records what another channel decided, so besides plain json (the web channel) there is a json-<channel> mode for each rendering channel, derived from that channel's entry.

This module imports nothing from the runtime: output functions and text handlers are named by dotted path and imported when a run needs them.

OutputMode dataclass

OutputMode(
    name: str,
    accepts: tuple[str, ...],
    functions: str,
    settings: tuple[tuple[str, str], ...] = (),
    stylesheet: str = "css",
    webcomponents: bool = True,
    records: bool = False,
    template: str | None = None,
    template_setting: str | None = None,
    default_template: str | None = None,
    print_css: bool = False,
    collects_metadata: bool = False,
    packaged: bool = False,
    binary: bool = False,
    extension: str = "",
    preview: str = "text",
    scaffold: bool = False,
    channel: str | None = None,
    compiler: str | None = None,
)

One output mode; see the module docstring.

section property

section: str

The [transform.<type>] table configuring this mode.

output_functions

output_functions() -> type

The output-functions class, imported on first use.

Source code in src/opm/output_modes.py
def output_functions(self) -> type:
    """The output-functions class, imported on first use."""
    return _import(self.functions)

context_settings

context_settings() -> dict[str, Callable]

The settings resolved to their callables.

Source code in src/opm/output_modes.py
def context_settings(self) -> dict[str, Callable]:
    """The `settings` resolved to their callables."""
    return {name: _import(path) for name, path in self.settings}

output_mode

output_mode(name: str | None) -> OutputMode

The mode called name (case-insensitive; empty means DEFAULT_MODE).

Source code in src/opm/output_modes.py
def output_mode(name: str | None) -> OutputMode:
    """The mode called *name* (case-insensitive; empty means `DEFAULT_MODE`)."""
    key = (name or '').strip().lower() or DEFAULT_MODE
    try:
        return MODES[key]
    except KeyError:
        known = ', '.join(CONFIG_SECTIONS)
        raise ValueError(f'Unknown output mode {name!r}; expected one of {known}.') from None

module_mode

module_mode(mod: Any) -> OutputMode

The mode a compiled transform module was generated for.

Source code in src/opm/output_modes.py
def module_mode(mod: Any) -> OutputMode:
    """The mode a compiled transform module was generated for."""
    return output_mode(mod.OUTPUT_MODE)