Templating
API Reference
Template module which handles all things related to templates.
- template.load_template(file, params=None, description=None, markdown_data=None, *, convert_to_snake_case=False)
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 {}.
description (str, optional) – Description of press entities in markdown format. Defaults to None. Note that this parameter will soon be deprecated. Use markdown_data instead.
markdown_data (Dict[str, str] | None, optional) – Dictionary containing the markdown data to be inserted into the template. The key is a colon-separated string representing the nested key path (e.g., “body:metadata:description”), and the value is the markdown content.
convert_to_snake_case (Optional[bool], optional) – Convert the keys of the dictionary to snake_case. Defaults to False.
- Returns:
Dictionary containing the rendered YAML file
- Return type:
Dict[str, Any]
CLI Reference
Helper functions for Peak cli.
- cli.helpers.check_file_extension(file_path)
Checks if the file has a .txt or .md extension.
- Parameters:
file_path (str) – Path to the file to check.
- Raises:
ValueError – If the file extension is not .txt or .md.
- Return type:
None
- cli.helpers.format_logs(logs)
Formats logs into a readable format.
- Parameters:
logs (List[Dict[str, Any]]) – List of logs
- Returns:
Formatted logs
- Return type:
str
- 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_envs(env)
Parses envs provided via cli args to the format {arg1: value1}.
- Parameters:
env (List[str]) – List of envs provided via cli args.
- Returns:
Envs in the required format.
- Return type:
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, markdown_files=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.
markdown_files (Optional[Dict[str, str]]) – Dictionary of markdown files to load. The key is a colon-separated string representing the nested key path (e.g., “body:metadata:description”), and the value is the path to the markdown file.
- Returns:
Rendered template with values substituted.
- Return type:
Dict[str, Any]