Example #1
0
def main():
    print(f"KFP-Tekton Compiler {__version__}")
    args = parse_arguments()
    if ((args.py is None and args.package is None)
            or (args.py is not None and args.package is not None)):
        raise ValueError('Either --py or --package is needed but not both.')
    if args.py:
        tekton_pipeline_conf = TektonPipelineConf()
        tekton_pipeline_conf.set_tekton_inline_spec(True)
        if args.disable_task_inline:
            tekton_pipeline_conf.set_tekton_inline_spec(False)
        compile_pyfile(args.py, args.function, args.output,
                       not args.disable_type_check, tekton_pipeline_conf)
    else:
        if args.namespace is None:
            raise ValueError('--namespace is required for compiling packages.')
        # TODO: deprecated, but without the monkey-patch this will produce Argo YAML
        kfp_compiler_main.compile_package(args.package, args.namespace,
                                          args.function, args.output,
                                          not args.disable_type_check)
Example #2
0
        image: library/bash:4.4.23
        command: ['sh', '-c']
        args:
        - |
          set -e
          echo op1 "$0" "$1"
        - {inputValue: item}
        - {inputValue: param}
'''


@dsl.pipeline(name='pipeline')
def pipeline(param: int = 10):
    loop_args = [1, 2]
    with dsl.ParallelFor(loop_args, parallelism=1) as item:
        op1_template = components.load_component_from_text(op1_yaml)
        op1 = op1_template(item, param)
        condi_1 = tekton.CEL_ConditionOp(f"{item} == 2").output
        with dsl.Condition(condi_1 == 'true'):
            tekton.Break()


if __name__ == '__main__':
    from kfp_tekton.compiler import TektonCompiler as Compiler
    from kfp_tekton.compiler.pipeline_utils import TektonPipelineConf
    tekton_pipeline_conf = TektonPipelineConf()
    tekton_pipeline_conf.set_tekton_inline_spec(True)
    Compiler().compile(pipeline,
                       __file__.replace('.py', '.yaml'),
                       tekton_pipeline_conf=tekton_pipeline_conf)
              set -e
              echo $0 > $1
            - {inputValue: input_text}
            - {outputPath: output_value}
    """ % (name))
    return print_op(msg)


@dsl.graph_component
def function_the_name_of_which_is_exactly_51_chars_long(i: int):
    decr_i = CEL_ConditionOp(f"{i} - 1").output
    PrintOp("print-iter", f"Iter: {decr_i}")
    with dsl.Condition(decr_i != 0):
        function_the_name_of_which_is_exactly_51_chars_long(decr_i)


@dsl.pipeline("pipeline-the-name-of-which-is-exactly-51-chars-long")
def pipeline_the_name_of_which_is_exactly_51_chars_long(iter_num: int = 42):
    function_the_name_of_which_is_exactly_51_chars_long(iter_num)


if __name__ == '__main__':
    from kfp_tekton.compiler import TektonCompiler as Compiler
    from kfp_tekton.compiler.pipeline_utils import TektonPipelineConf
    tekton_pipeline_conf = TektonPipelineConf()
    tekton_pipeline_conf.set_tekton_inline_spec(False)
    tekton_pipeline_conf.set_resource_in_separate_yaml(True)
    Compiler().compile(pipeline_the_name_of_which_is_exactly_51_chars_long,
                       __file__.replace('.py', '.yaml'),
                       tekton_pipeline_conf=tekton_pipeline_conf)