flowserv.model.template.parameter module

Collection of helper methods for parameter references in workflow templates.

class flowserv.model.template.parameter.ParameterIndex(parameters: Optional[List[flowserv.model.parameter.base.Parameter]] = None)

Bases: dict

Index of parameter declaration. Parameters are indexed by their unique identifier.

static from_dict(doc: Dict, validate: Optional[bool] = True) flowserv.model.parameter.base.Parameter

Create a parameter index from a dictionary serialization. Expects a list of dictionaries, each being a serialized parameter declaration.

Raises an error if parameter indices are not unique.

Parameters
  • doc (list) – List of serialized parameter declarations.

  • validate (bool, default=True) – Validate dictionary serializations if True.

Return type

flowserv.model.template.base.ParameterIndex

set_defaults(arguments: Dict) Dict

Set default values for parameters that have a default and that are not present in the given arguments dictionary.

Returns a modified copy of the given arguments dictionary.

Parameters

arguments (dict) – Dictionary of user-provided argument values.

Return type

dict

sorted()

Get list of parameter declarations sorted by ascending parameter index position.

Return type

list(flowserv.model.parameter.base.Parameter)

to_dict()

Get dictionary serialization for the parameter declarations.

Return type

list

flowserv.model.template.parameter.VARIABLE(name)

Get string representation containing the reference to a variable with given name. This string is intended to be used as a template parameter reference within workflow specifications in workflow templates.

Parameters

name (string) – Template parameter name

Return type

string

flowserv.model.template.parameter.expand_value(value, arguments, parameters)

Test whether the string is a reference to a template parameter and (if True) replace the value with the given argument or default value.

In the current implementation template parameters are referenced using $[[..]] syntax.

Parameters
  • value (string) – String value in the workflow specification for a template parameter

  • arguments (dict) – Dictionary that associates template parameter identifiers with argument values

  • parameters (flowserv.model.template.parameter.ParameterIndex) – Dictionary of parameter declarations

Return type

any

Raises

flowserv.error.MissingArgumentError

flowserv.model.template.parameter.get_name(value)

Extract the parameter name for a template parameter reference.

Parameters

value (string) – String value in the workflow specification for a template parameter

Return type

string

flowserv.model.template.parameter.get_parameter_references(spec, parameters=None)

Get set of parameter identifier that are referenced in the given workflow specification. Adds parameter identifier to the given parameter set.

Parameters
  • spec (dict) – Parameterized workflow specification.

  • parameters (set, optional) – Result set of referenced parameter identifier.

Return type

set

Raises

flowserv.error.InvalidTemplateError

flowserv.model.template.parameter.get_value(value, arguments)

Get the result value from evaluating a parameter reference expression. Expects a value that satisfies the is_parameter() predicate. If the given expression is unconditional, e.g., $[[name]], the parameter name is the returned result. If the expression is conditional, e.g., $[[name ? x : y]] the argument value for parameter ‘name’ is tested for being Boolean True or False. Depending on the outcome of the evaluation either x or y are returned.

Note that nested conditional expressions are currently not supported.

Parameters
  • value (string) – Parameter reference string that satisifes the is_parameter() predicate.

  • arguments (dict) – Dictionary of user-provided argument values for template arguments.

Return type

string

Raises

flowserv.error.MissingArgumentError

flowserv.model.template.parameter.is_parameter(value)

Returns True if the given value is a reference to a template parameter.

Parameters

value (string) – String value in the workflow specification for a template parameter

Return type

bool

flowserv.model.template.parameter.placeholders(text: str) Set[str]

Get the set of names for all placeholders in the given string.

Placeholders start with ‘$’ following the string.template syntax.

Parameters

text (string) – Template string.

Return type

set of string

flowserv.model.template.parameter.replace_args(spec, arguments, parameters)

Replace template parameter references in the workflow specification with their respective values in the argument dictionary or their defined default value. The type of the result is depending on the type of the spec object.

Parameters
  • spec (any) – Parameterized workflow specification.

  • arguments (dict) – Dictionary that associates template parameter identifiers with argument values.

  • parameters (flowserv.model.template.parameter.ParameterIndex) – Dictionary of parameter declarations.

Return type

type(spec)

Raises