plexus.reports.parameter_utils module

Utility functions for handling parameters in report configurations.

This module provides functions for: - Extracting parameter definitions from YAML configuration - Validating parameter values - Rendering configuration content with Jinja2 templates

plexus.reports.parameter_utils.enrich_parameters_with_names(param_defs: List[Dict[str, Any]], parameters: Dict[str, Any], client: Any) Dict[str, Any]

Enrich parameters by adding name variables for scorecard_select and score_select types.

For each parameter of type ‘scorecard_select’ or ‘score_select’, this function: 1. Resolves the identifier (ID, key, external ID, or name) to the actual object 2. Adds a new parameter ‘{parameter_name}_name’ with the resolved name

This allows templates to reference both the identifier and the human-readable name.

Args:

param_defs: List of parameter definitions from the configuration parameters: Dictionary of parameter name -> value mappings client: PlexusDashboardClient instance for API lookups

Returns:

Enriched parameters dictionary with additional _name variables

Example:

If parameters = {‘scorecard’: ‘some-id-123’, ‘days’: 30} And ‘scorecard’ is type ‘scorecard_select’ Returns: {‘scorecard’: ‘some-id-123’, ‘scorecard_name’: ‘My Scorecard’, ‘days’: 30}

plexus.reports.parameter_utils.extract_parameters_from_config(configuration: str) tuple[List[Dict[str, Any]], str]

Extract parameter definitions and content from report configuration.

Args:

configuration: The full report configuration string (may include YAML frontmatter)

Returns:

Tuple of (parameter_definitions, content) - parameter_definitions: List of parameter definition dicts - content: The report content (everything after — separator, or full config if no separator)

plexus.reports.parameter_utils.get_parameter_display_value(param_def: Dict[str, Any], value: Any) str

Get a human-readable display string for a parameter value.

Args:

param_def: Parameter definition value: The parameter value

Returns:

String representation for display

plexus.reports.parameter_utils.has_parameters(configuration: str) bool

Check if a configuration has parameter definitions.

Args:

configuration: The report configuration string

Returns:

True if parameters are defined, False otherwise

plexus.reports.parameter_utils.normalize_parameter_value(param_def: Dict[str, Any], value: str) Any

Convert a string parameter value to the appropriate Python type.

Args:

param_def: Parameter definition with ‘type’ field value: String value from CLI or user input

Returns:

Converted value (int, bool, str, etc.)

plexus.reports.parameter_utils.render_configuration_with_parameters(configuration: str, parameters: Dict[str, Any], strict: bool = True) str

Render report configuration content with Jinja2 parameter interpolation.

Args:

configuration: The report configuration content (may include parameter definitions) parameters: Dictionary of parameter name -> value mappings strict: If True, raise error on undefined variables. If False, leave them as-is.

Returns:

The rendered configuration with parameters interpolated

Raises:

TemplateError: If Jinja2 rendering fails (e.g., undefined variable in strict mode)

plexus.reports.parameter_utils.validate_all_parameters(param_defs: List[Dict[str, Any]], values: Dict[str, Any]) tuple[bool, List[str]]

Validate all parameter values against their definitions.

Args:

param_defs: List of parameter definitions values: Dictionary of parameter name -> value

Returns:

Tuple of (all_valid, list_of_errors)

plexus.reports.parameter_utils.validate_parameter_value(param_def: Dict[str, Any], value: Any) tuple[bool, str | None]

Validate a parameter value against its definition.

Args:

param_def: Parameter definition dict with ‘name’, ‘type’, ‘required’, etc. value: The value to validate

Returns:

Tuple of (is_valid, error_message)