コード例 #1
0
 def test_concat_placeholder(self):
     placeholder = "{{$.inputs.parameters[''input1'']}}+{{$.inputs.parameters[''input2'']}}"
     actual = structures.maybe_convert_command_arg_to_placeholder(
         placeholder)
     expected = structures.ConcatPlaceholder(items=[
         structures.InputValuePlaceholder(input_name='input1'), '+',
         structures.InputValuePlaceholder(input_name='input2')
     ])
     self.assertEqual(actual, expected)
コード例 #2
0
 def _transform_arg(arg: ValidCommandArgs) -> Any:
     if isinstance(arg, str):
         return arg
     if isinstance(arg, InputValuePlaceholder):
         return v1_structures.InputValuePlaceholder(arg.input_name)
     if isinstance(arg, InputPathPlaceholder):
         return v1_structures.InputPathPlaceholder(arg.input_name)
     if isinstance(arg, InputUriPlaceholder):
         return v1_structures.InputUriPlaceholder(arg.input_name)
     if isinstance(arg, OutputPathPlaceholder):
         return v1_structures.OutputPathPlaceholder(arg.output_name)
     if isinstance(arg, OutputUriPlaceholder):
         return v1_structures.OutputUriPlaceholder(arg.output_name)
     if isinstance(arg, IfPresentPlaceholder):
         return v1_structures.IfPlaceholder(arg.if_structure)
     if isinstance(arg, ConcatPlaceholder):
         return v1_structures.ConcatPlaceholder(arg.concat)
     raise ValueError(
         f'Unexpected command/argument type: "{arg}" of type "{type(arg)}".'
     )
コード例 #3
0
    def test_concat_placeholder(self):
        compiled_yaml = textwrap.dedent("""
components:
  comp-concat:
    executorLabel: exec-concat
    inputDefinitions:
      parameters:
        input1:
          parameterType: STRING
        input2:
          parameterType: STRING
deploymentSpec:
  executors:
    exec-concat:
      container:
        command:
        - sh
        - -c
        - echo "$0"
        - '{{$.inputs.parameters[''input1'']}}+{{$.inputs.parameters[''input2'']}}'
        image: alpine
pipelineInfo:
  name: concat
root:
  dag:
    tasks:
      concat:
        cachingOptions:
          enableCache: true
        componentRef:
          name: comp-concat
        inputs:
          parameters:
            input1:
              componentInputParameter: input1
            input2:
              componentInputParameter: input2
        taskInfo:
          name: concat
  inputDefinitions:
    parameters:
      input1:
        parameterType: STRING
      input2:
        parameterType: STRING
schemaVersion: 2.1.0
sdkVersion: kfp-2.0.0-alpha.2""")
        loaded_component_spec = structures.ComponentSpec.load_from_component_yaml(
            compiled_yaml)
        component_spec = structures.ComponentSpec(
            name='concat',
            implementation=structures.Implementation(
                container=structures.ContainerSpec(
                    image='alpine',
                    command=[
                        'sh', '-c', 'echo "$0"',
                        structures.ConcatPlaceholder(items=[
                            structures.InputValuePlaceholder(
                                input_name='input1'), '+',
                            structures.InputValuePlaceholder(
                                input_name='input2')
                        ])
                    ],
                    args=None,
                    env=None,
                    resources=None),
                graph=None,
                importer=None),
            description=None,
            inputs={
                'input1': structures.InputSpec(type='String', default=None),
                'input2': structures.InputSpec(type='String', default=None)
            },
            outputs=None)
        self.assertEqual(loaded_component_spec, component_spec)
コード例 #4
0
      container:
        args:
        - concat: ['--arg1', {inputValue: input_prefix}]
        image: alpine
    inputs:
    - {name: input_prefix, type: String}
    """)

COMPONENT_SPEC_CONCAT_PLACEHOLDER = structures.ComponentSpec(
    name='component_concat',
    implementation=structures.Implementation(
        container=structures.ContainerSpec(
            image='alpine',
            args=[
                structures.ConcatPlaceholder(items=[
                    '--arg1',
                    structures.InputValuePlaceholder(input_name='input_prefix'),
                ])
            ])),
    inputs={'input_prefix': structures.InputSpec(type='String')},
)

V1_YAML_NESTED_PLACEHOLDER = textwrap.dedent("""\
    name: component_nested
    implementation:
      container:
        args:
        - concat:
            - --arg1
            - if:
                cond:
                    isPresent: input_prefix