Templating
API Reference
Template module which handles all things related to templates.
- template.load_template(file, params)
Load a template file through Jinja into a dictionary.
- This function performs the following steps:
Passes the YAML file to be loaded and parsed through `Jinja`
`Jinja` substitutes the variables with their values as they are found in params
Loads any other files that are referenced using the Jinja {% include %} directive, if it is present.
Updates the context key path within image definitions with respect to its relative parent file path.
Loads the rendered YAML file into a dictionary.
- Parameters:
file (Union[Path, str]) – Path to the templated YAML file to be loaded.
params (Dict[str, Any] | None, optional) – Named parameters to be passed to Jinja. Defaults to {}.
- Returns:
Dictionary containing the rendered YAML file
- Return type:
Dict[str, Any]
CLI Reference
Helper functions for Peak cli.
- cli.helpers.get_client(command)
Create a client for the invoked command.
- Parameters:
command (str) – Invoked CLI command
- Returns:
client class for the invoked command
- Return type:
BaseClient
- cli.helpers.get_updated_artifacts(body, artifact_path, artifact_ignore_files)
Returns updated artifacts by replacing artifact path and ignore files by the ones provided via cli args.
- Parameters:
body (Dict[str, Any]) – Dictionary containing request body generated from user provided yaml file
artifact_path (str | None) – Path to the artifact.
artifact_ignore_files (List[str] | None) – Ignore files to use when creating artifact.
- Returns:
Dictionary containing updated artifacts
- Return type:
Dict[str, Any]
- cli.helpers.parse_build_arguments(build_arguments)
Parses build arguments provided via cli args to the format {name: arg1, value: value1}.
- Parameters:
build_arguments (List[str]) – List of build arguments provided via cli args
- Returns:
List of build arguments in the required format
- Return type:
List[Dict[str, str]]
- Raises:
BadParameterException – If a value is invalid
- cli.helpers.parse_params(params)
Parse parameters into key-value pairs.
- Parameters:
params (Optional[List[str]]) – List of key-value pairs
- Returns:
Dictionary of key-value pairs
- Return type:
Dict[str, str]
- Raises:
BadParameterException – If a value is invalid
>>> params = ["foo=1", "bar=2"] >>> vals = parse_params(params) >>> vals {'foo': '1', 'bar': '2'}
Raises an error if a value is invalid >>> parse_params([“bar==foo”]) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): … BadParameterException: Unable to parse: bar==foo
- cli.helpers.remove_unknown_args(args, func)
Filters keys from dictionary which are not accepted by the function.
- Parameters:
args (Dict[str, Any]) – dictionary to filter
func (Callable) – function to filter for
- Returns:
filtered dictionary
- Return type:
Dict[str, Any]
- cli.helpers.template_handler(file, params_file=None, params=None)
Loads and returns the rendered template.
- Parameters:
file (str) – Path to the template file.
params_file (Optional[str]) – Path to the params map file.
params (Optional[List[str]]) – List of params to override.
- Returns:
Rendered template with values substituted.
- Return type:
Dict[str, Any]