odd_compiler¶
Compile an ODD file into a transform module. compile_odd() is the low-level
entry point used by the on-demand cache; CodeGenerator / PythonGenerator are
the code-emission backend and load_odd() parses the ODD XML into a
ParsedOdd.
For day-to-day use prefer opm.odd_cache.ensure_compiled_module,
which writes into the platform user cache and skips recompilation when inputs
are unchanged.
opm.odd_compiler ¶
Compile TEI Publisher ODD processing models to target language transformation modules.
CodeGenerator ¶
Bases: ABC
Abstract base class for ODD-to-target-language code generators.
target_name
abstractmethod
property
¶
Target language identifier (e.g., 'python', 'rust').
file_extension
abstractmethod
property
¶
File extension for generated files (e.g., '.py', '.rs').
generate_module
abstractmethod
¶
generate_module(
parsed: ParsedOdd,
module_name: str,
*,
output_mode: str = "web",
base_css: str | None = None,
) -> str
Generate target language source code from a parsed ODD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed
|
ParsedOdd
|
The parsed ODD structure |
required |
module_name
|
str
|
Logical name for the generated module |
required |
output_mode
|
str
|
Output channel (web, markdown, print, etc.) |
'web'
|
Returns:
| Type | Description |
|---|---|
str
|
Complete source code as a string |
Source code in src/opm/odd_compiler/codegen/__init__.py
PythonGenerator ¶
Bases: CodeGenerator
Generate Python source from a parsed ODD.
Source code in src/opm/odd_compiler/codegen/python_generator.py
unsupported
property
¶
Expressions the last generate_module call compiled out.
Each is one opm can never evaluate (see
expression_check). It was replaced by what a
failing evaluation returns, so the output is unchanged; the difference
is that it is now known and reported instead of failing on every node.
compile_odd ¶
compile_odd(
odd_path: str,
*,
target: str = "python",
module_name: str = "generated_odd",
output_mode: str = "web",
base_css: str | None = None,
diagnostics: list | None = None,
) -> str
Compile an ODD file to target language source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
odd_path
|
str
|
Path to the ODD file |
required |
target
|
str
|
Target language ('python', or future 'rust') |
'python'
|
module_name
|
str
|
Logical name for the generated module |
'generated_odd'
|
output_mode
|
str
|
Output channel (web, markdown, print, etc.) |
'web'
|
base_css
|
str | None
|
Rules prepended to the generated stylesheet, replacing the
packaged default. |
None
|
diagnostics
|
list | None
|
When given, receives one
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Generated source code as a string |
Raises:
| Type | Description |
|---|---|
ValueError
|
If target language is not supported |
Source code in src/opm/odd_compiler/__init__.py
Parsed ODD representation¶
opm.odd_compiler.parse_odd.ParsedOdd
dataclass
¶
ParsedOdd(
tree: _ElementTree,
schema_ns: str,
odd_path: str,
element_specs: list,
odd_chain: list[str],
nsmap: dict[str, str],
licences: list[OddLicence] = list(),
)
Odd cache¶
opm.odd_cache ¶
Compile-on-demand cache for ODD → Python transform modules.
ResolvedTransform
dataclass
¶
ResolvedTransform(
module_path: Path,
source_odd: Path | None = None,
freshly_compiled: bool = False,
unsupported: tuple = (),
)
A loadable transform module, optionally produced from an ODD.
modules_cache_dir ¶
cache_key ¶
Return a content hash covering the ODD chain, CSS inputs, mode, and opm version.
Source code in src/opm/odd_cache.py
cached_module_path ¶
cached_module_path(
odd_path: Path,
output_mode: str,
digest: str | None = None,
base_css: str | None = None,
) -> Path
Return the cache path for odd_path in output_mode (does not compile).
Source code in src/opm/odd_cache.py
ensure_compiled_module ¶
ensure_compiled_module(
odd_path: Path | str,
*,
output_mode: str = "web",
module_name: str | None = None,
base_css: str | None = None,
diagnostics: list | None = None,
) -> tuple[Path, bool]
Return (module_path, freshly_compiled) for odd_path.
On a cache miss, compiles the ODD into the user cache directory and returns the new path. On a hit, returns the existing cached module unchanged.
diagnostics, when given, receives the expressions a fresh compile skipped
(see compile_odd); a cache hit leaves it empty.
Source code in src/opm/odd_cache.py
resolve_transform_module ¶
resolve_transform_module(
*,
module: Path | None = None,
odd: Path | None = None,
output_mode: str = "web",
use_packaged_default: bool = True,
base_css: str | None = None,
) -> ResolvedTransform
Resolve a loadable .py module from an explicit path, ODD, or packaged default.
Precedence: module → odd → packaged teipublisher.odd (when
use_packaged_default is true).
base_css replaces the packaged rules prepended to the generated stylesheet, and is part of the cache key, so a project overriding them gets its own compiled module.