Compiler

Compile a Kale Pipeline into a Kubeflow Pipelines v2 DSL script.

This module renders the Jinja2 templates in kale/templates/ to produce a ready-to-run KFP v2 pipeline script, formats it, and optionally hands it off to the KFP SDK for compilation and submission.

kale.compiler.to_kale_env_var_name(pvc_name: str) str[source]

Derive a KALE_VOLUME_<NAME> env var name from a PVC name.

Non-alphanumeric characters are collapsed to _. This mapping is lossy for DNS subdomain names (both - and . become _), so callers that expose multiple volumes must ensure the derived names stay unique.

class kale.compiler.Artifact(name: str, type: str, is_input: bool = False)[source]

Bases: NamedTuple

A Step artifact.

name: str

Alias for field number 0

type: str

Alias for field number 1

is_input: bool

Alias for field number 2

class kale.compiler.Compiler(pipeline: Pipeline, imports_and_functions: str)[source]

Bases: object

Converts a Pipeline object into a KFP executable.

Compiler provides the tools to convert a Pipeline object into an executable script that uses the KFP DSL to create and upload a new pipeline.

The Pipeline object is assumed to provide all the necessary information (environment, configuration, etc…) for the script to be compiled.

modules: dict[str, str]
compile_and_run()[source]

First compile the Pipeline to DSL and then run it.

compile()[source]

Convert Pipeline to KFP DSL.

Returns path to DSL script.

run()[source]

Run the generated KFP script.

generate_dsl()[source]

Generate a Python KFP DSL executable starting from the pipeline.

Returns (str): A Python executable script

generate_composition(nodes)[source]

Generate the DSL for a pipeline that references other notebooks.

Every referenced notebook becomes an importable module of its own, holding its components and a nested pipeline, and this notebook’s DSL imports them and wires them together with its own steps. The modules are written next to it by _save_compiled_code().

generate_lightweight_component(step: Step)[source]

Generate Python code using the notebook function template.

generate_pipeline(lightweight_components)[source]

Generate Python code using the pipeline template.