Parameter policies reference#
Parameter policies determine how cab parameters are converted into command-line options of the underlying executables (with one exception pertaining to Python callables – see below). Most tools follow an -option value or --option value convention on the command line – the latter is taken to be the default, but see prefix below.
Policies can be defined for all the parameters of the cab as a whole, via a policies section in the cab definition. They can also be tweaked on a per-parameter basis, via a policies section in the appropriate schema.
The policies section can contain one or more of the following attributes (see also the source code for details):
prefixdetermines the prefix of command-line options. The default is--, while another common setting is-. The examples below use--option– this becomes-optionifprefix: -is used.key_value: truecauses the parameter to map to aname=valueargument.positional: truecauses the parameter to be passed as a positional argument. The examples below use--option– ifpositionalis set, the--optionargument is omitted, and the parameter value is passed directly.positional_head: truecauses the parameter to be passed as a positional argument ahead of all non-positional options. The default is to pass positional arguments after non-positional arguments.repeatdetermines how to treat list-type parameters. This policy has no default, and must be set for any list types. Possible settings are:listto pass the list as multiple arguments, i.e. given a parameter named “option” with a value of [X, Y], this results in three command-line arguments:--option,X,Y(or two command-line argumentsXandY, if a positional policy is set.)[]to use a YAML-formatted list, i.e.--option,[X,Y].repeatto repeat the option for every list element, i.e.--option,X,--option,Y.any other value is used as a separator to paste list elements together:
repeat: ,results in the command-line arguments--option,X,Y.
skip: truecauses the parameter to be omitted from the command line entirely.skip_implicits: truecauses the parameter to be omitted if it is implicit.disable_substitutions: truedisables substitutions and formula evaluations <subst>` on the parameter.explicit_true: valuecauses true-valued boolean parameters to be passed as--option value. If not given, they are simply passed as--option.explicit_false: valuecauses false-valued boolean parameters to be passed as--option value. If not given, false-valued booleans are omitted.split: separatorcauses string-valued parameters to be split using the separator, and passed as separate arguments. For example, givensplit: ,, the parameteroptionwith a value ofX,Ywill be passed as--option X Y.replacegives a dictionary offrom: topairs that effect replacements in the name of the parameter when converting it to a command-line option. A common example isreplace: {_: -}, which results in, e.g., parameteroption_namebecoming--option-name.formatdetermines how parameter values are converted into command-line arguments (which are intrinsically always strings). The default behaviour is to simply use Python’sstr()function. If a value forformatis specified, Stimela uses it as a format string, invoking thestr.format(**params)method. Note that the entire parameter dictionary is passed in, so the format string can, in principle, refer to other parameters.If the value of the parameter is a list, the format string is applied to each element, making a list of command-line arguments (unless
format_listis specified). Thus, the entire list is formatted uniformly.By contrast,
format_listshould be used when a list needs to be formatted non-uniformly. Each element offormat_listis treated as a format string, invoked asstr.format(*value, **params). The resulting list of strings becomes a list of command-line arguments.Finally,
format_list_scalarcan be used to turn a single parameter value into a list of command-line arguments. Each element offormat_list_scalaris treated as a format string, invoked asstr.format(value, **params). The resulting list of strings becomes a list of command-line arguments.pass_missing_as_none: trueis the one policy attribute that applies to Python callable flavour cabs. Setting this causes missing parameters (i.e. non-required parameters defined by the schema and not supplied within the recipe) to be passed to the underlying callable anyway, using values ofNone. If this is not set, missing parameters are not passed to the callable.