Inputs and Outputs
For full introduction about Inputs and Outputs concept, please refer to Inputs and Outputs documentation.
To define component inputs and outputs:
Add
inputsandoutputssection to the component spec to specify the component interface.Add reference to the inputs and outputs in the
commandsection. A reference looks like{inputs.name_of_parameter}, which will be replaced by the value of the parameter when invoking the component.
Refer to the component spec for full description.
Optional Inputs and Parameters
Use optional to make an input port or a parameter optional.
In the snippet below, two input ports and the parameter “Optional string parameter” are optional.
inputs:
input_path:
type: path
optional: true
optional_input_path:
type: path
optional: true
string_parameter:
type: string
default: string value
description: A parameter accepts a string value.
optional_string_parameter:
type: string
optional: true
description: A optional parameter accepts a string value.
In the command part, put optional parameter into [] as follows:
[--optional-input-path {inputs.optional_input_path}][--optional-input-path={inputs.optional_input_path}]
For example:
command: >-
python optional_input.py
--input-path {inputs.input_path}
[--optional-input-path {inputs.optional_input_path}]
--string-param {inputs.string_parameter}
[--optional-string-param={inputs.optional_string_parameter}]
When invoking the component, the command line will look like:
# When the optional input is linked, and the optional parameter is set.
python optional_input.py --input-path /aaa/bbb --optional-input-path /xxx/yyy --string-param abc --optional-string-param def
# When the optional input is linked, and the optional parameter is not set.
python optional_input.py --input-path /aaa/bbb --optional-input-path /xxx/yyy --string-param abc
# When the optional input is not linked, and the optional parameter is set.
python optional_input.py --input-path /aaa/bbb --string-param abc --optional-string-param def
# When the optional input is not linked, and the optional parameter is not set.
python optional_input.py --input-path /aaa/bbb --string-param abc
NOTE: Only optional input can be placed in nested argument.
NOTE: When multi-nested of optional parameters in command, if not outer optional parameter, inner optional parameter doesn’t exist in result command, no matter whether inner optional parameter is assigned. For example
[[{inputs.option1}] {inputs.option2}]in a command, if not set option2, option1 doesn’t exists in result command, even option1 is assigned.
Sample component
Default Parameters
Use default to specify the default value of a parameter.
Once a default value is set, Component SDK will set the value to corresponding when initialize the component by component = component_func().
Note that default and optional are independent properties, no matter the parameter is optional or not, the default value will be set.
Thus, usually you don’t need to both set default and optional.