dpmcore.services.ast_generator

Generate engine-ready validation scripts from DPM-XL expressions. The resulting enriched_ast is keyed by the resolved module URI and carries the AST, resolved release, per-validation severity, operands, tables, preconditions, and dependency information.

The same script generation is exposed through the generate-script CLI command and the /api/v1/scripts REST endpoint.

ASTGeneratorService

class dpmcore.services.ast_generator.ASTGeneratorService(session=None)[source]

Bases: object

Generate engine-ready validation scripts from DPM-XL expressions.

Parameters:

session (Optional[Session]) – An open SQLAlchemy session (required for script).

__init__(session=None)[source]

Build the service, optionally bound to a SQLAlchemy session.

Parameters:

session (Session | None)

Return type:

None

script(expressions, module_code, module_version, preconditions=None, severity=None, severities=None, release=None)[source]

Generate an engine-ready validations script.

Parameters:
  • expressions (List[Tuple[str, str]]) – [(expression, validation_code), ...].

  • module_code (str) – Code of the primary module (e.g. "COREP_Con").

  • module_version (str) – Version of the primary module (e.g. "2.0.1").

  • preconditions (Optional[List[Union[Tuple[str, List[str]], Dict[str, Any]]]]) – Optional list of precondition specs. Each entry is either a tuple (precondition_expression, [validation_codes]) or a dict with keys expression and affected_operations (optional code and version_id are also accepted). A precondition can guard many validation codes; a validation may have no precondition.

  • severity (Optional[str]) – Optional global default severity tag ("error", "warning", "info"). Defaults to "warning".

  • severities (Optional[Dict[str, str]]) – Optional per-validation override map {validation_code: severity}. Resolution per validation is severities.get(code, severity_global). Unknown codes (not present in expressions) raise ValueError.

  • release (Optional[str]) – Optional release code. When omitted, resolved to the latest release whose window contains the requested ModuleVersion. The resolved release is surfaced in the dpm_release block and used for every downstream DB filter.

Return type:

Dict[str, Any]

Returns:

A dict with keys success (bool), enriched_ast (the namespaced dict, or None on failure), error (str or None), and failed_operations (a {validation_code: error_message} map of expressions skipped due to semantic errors). The namespaced dict mirrors the shape pydpm’s generate_validations_script produces.