project_config.utils.jmespath module
Utilities related to JMESPaths.
- exception project_config.utils.jmespath.JMESPathError(message: str)[source]
Bases:
ProjectConfigException
Class to wrap all JMESPath errors of the plugin.
- class project_config.utils.jmespath.JMESPathProjectConfigFunctions[source]
Bases:
Functions
JMESPath class to include custom functions.
- FUNCTION_TABLE = {'abs': {'function': <function Functions._func_abs>, 'signature': ({'types': ['number']},)}, 'avg': {'function': <function Functions._func_avg>, 'signature': ({'types': ['array-number']},)}, 'capitalize': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'casefold': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'ceil': {'function': <function Functions._func_ceil>, 'signature': ({'types': ['number']},)}, 'center': {'function': <function JMESPathProjectConfigFunctions._func_center>, 'signature': ({'types': ['string']}, {'types': ['number'], 'variadic': True})}, 'contains': {'function': <function Functions._func_contains>, 'signature': ({'types': ['array', 'string']}, {'types': []})}, 'count': {'function': <function JMESPathProjectConfigFunctions._func_count>, 'signature': ({'types': ['string', 'array']}, {'types': [], 'variadic': True})}, 'deepmerge': {'function': <function JMESPathProjectConfigFunctions._func_deepmerge>, 'signature': ({'types': [], 'variadic': True},)}, 'ends_with': {'function': <function JMESPathProjectConfigFunctions._func_ends_with>, 'signature': ({'types': ['string']}, {'types': ['string', 'array-string'], 'variadic': True})}, 'enumerate': {'function': <function JMESPathProjectConfigFunctions._func_enumerate>, 'signature': ({'types': ['string', 'array', 'object']},)}, 'exists': {'function': <function JMESPathProjectConfigFunctions._func_exists>, 'signature': ({'types': ['string']},)}, 'find': {'function': <function _create_find_function_for_string_or_array.<locals>._wrapper>, 'signature': ({'types': ['string', 'array'], 'variadic': True},)}, 'floor': {'function': <function Functions._func_floor>, 'signature': ({'types': ['number']},)}, 'format': {'function': <function JMESPathProjectConfigFunctions._func_format>, 'signature': ({'types': [], 'variadic': True},)}, 'from_items': {'function': <function JMESPathProjectConfigFunctions._func_from_items>, 'signature': ({'types': ['array']},)}, 'getenv': {'function': <function JMESPathProjectConfigFunctions._func_getenv>, 'signature': ({'types': ['string']},)}, 'gh_tags': {'function': <function JMESPathProjectConfigFunctions._func_gh_tags>, 'signature': ({'types': ['string']}, {'types': ['string'], 'variadic': True})}, 'glob': {'function': <function JMESPathProjectConfigFunctions._func_glob>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'insert': {'function': <function JMESPathProjectConfigFunctions._func_insert>, 'signature': ({'types': ['array']}, {'types': ['number']}, {'types': []})}, 'isalnum': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isalpha': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isascii': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isdecimal': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isdigit': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isdir': {'function': <function JMESPathProjectConfigFunctions._func_isdir>, 'signature': ({'types': ['string']},)}, 'isfile': {'function': <function JMESPathProjectConfigFunctions._func_isfile>, 'signature': ({'types': ['string']},)}, 'isidentifier': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'islower': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isnumeric': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isprintable': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isspace': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'istitle': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'isupper': {'function': <function _create_is_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'join': {'function': <function Functions._func_join>, 'signature': ({'types': ['string']}, {'types': ['array-string']})}, 'keys': {'function': <function Functions._func_keys>, 'signature': ({'types': ['object']},)}, 'length': {'function': <function Functions._func_length>, 'signature': ({'types': ['string', 'array', 'object']},)}, 'listdir': {'function': <function JMESPathProjectConfigFunctions._func_listdir>, 'signature': ({'types': ['string']},)}, 'ljust': {'function': <function _create_just_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['number'], 'variadic': True})}, 'lower': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'lstrip': {'function': <function _create_strip_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'map': {'function': <function Functions._func_map>, 'signature': ({'types': ['expref']}, {'types': ['array']})}, 'max': {'function': <function Functions._func_max>, 'signature': ({'types': ['array-number', 'array-string']},)}, 'max_by': {'function': <function Functions._func_max_by>, 'signature': ({'types': ['array']}, {'types': ['expref']})}, 'merge': {'function': <function Functions._func_merge>, 'signature': ({'types': ['object'], 'variadic': True},)}, 'min': {'function': <function Functions._func_min>, 'signature': ({'types': ['array-number', 'array-string']},)}, 'min_by': {'function': <function Functions._func_min_by>, 'signature': ({'types': ['array']}, {'types': ['expref']})}, 'mkdir': {'function': <function JMESPathProjectConfigFunctions._func_mkdir>, 'signature': ({'types': ['string']},)}, 'not_null': {'function': <function Functions._func_not_null>, 'signature': ({'types': [], 'variadic': True},)}, 'op': {'function': <function JMESPathProjectConfigFunctions._func_op>, 'signature': ({'types': []}, {'types': ['string']}, {'types': [], 'variadic': True})}, 'os': {'function': <function JMESPathProjectConfigFunctions._func_os>, 'signature': ()}, 'partition': {'function': <function _create_partition_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['string']})}, 'range': {'function': <function JMESPathProjectConfigFunctions._func_range>, 'signature': ({'types': ['number'], 'variadic': True},)}, 'regex_escape': {'function': <function JMESPathProjectConfigFunctions._func_regex_escape>, 'signature': ({'types': ['string']},)}, 'regex_match': {'function': <function JMESPathProjectConfigFunctions._func_regex_match>, 'signature': ({'types': ['string']}, {'types': ['string'], 'variadic': True})}, 'regex_matchall': {'function': <function JMESPathProjectConfigFunctions._func_regex_matchall>, 'signature': ({'types': ['string']}, {'types': ['array-string', 'object']})}, 'regex_search': {'function': <function JMESPathProjectConfigFunctions._func_regex_search>, 'signature': ({'types': ['string']}, {'types': ['string'], 'variadic': True})}, 'regex_sub': {'function': <function JMESPathProjectConfigFunctions._func_regex_sub>, 'signature': ({'types': ['string']}, {'types': ['string']}, {'types': ['string'], 'variadic': True})}, 'removeprefix': {'function': <function _create_removeaffix_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['string']})}, 'removesuffix': {'function': <function _create_removeaffix_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['string']})}, 'replace': {'function': <function JMESPathProjectConfigFunctions._func_replace>, 'signature': ({'types': ['string']}, {'types': ['string']}, {'types': ['string'], 'variadic': True})}, 'reverse': {'function': <function Functions._func_reverse>, 'signature': ({'types': ['array', 'string']},)}, 'rfind': {'function': <function _create_find_function_for_string_or_array.<locals>._wrapper>, 'signature': ({'types': ['string', 'array'], 'variadic': True},)}, 'rjust': {'function': <function _create_just_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['number'], 'variadic': True})}, 'rmdir': {'function': <function JMESPathProjectConfigFunctions._func_rmdir>, 'signature': ({'types': ['string']},)}, 'rootdir_name': {'function': <function JMESPathProjectConfigFunctions._func_rootdir_name>, 'signature': ()}, 'round': {'function': <function JMESPathProjectConfigFunctions._func_round>, 'signature': ({'types': ['number'], 'variadic': True},)}, 'rpartition': {'function': <function _create_partition_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']}, {'types': ['string']})}, 'rsplit': {'function': <function _create_split_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'rstrip': {'function': <function _create_strip_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'set': {'function': <function JMESPathProjectConfigFunctions._func_set>, 'signature': ({'types': ['object']}, {'types': ['string']}, {'types': []})}, 'setenv': {'function': <function JMESPathProjectConfigFunctions._func_setenv>, 'signature': ({'types': ['string']}, {'types': ['string', 'null']})}, 'shlex_join': {'function': <function JMESPathProjectConfigFunctions._func_shlex_join>, 'signature': ({'types': ['array-string']},)}, 'shlex_split': {'function': <function JMESPathProjectConfigFunctions._func_shlex_split>, 'signature': ({'types': ['string']},)}, 'sort': {'function': <function Functions._func_sort>, 'signature': ({'types': ['array-string', 'array-number']},)}, 'sort_by': {'function': <function Functions._func_sort_by>, 'signature': ({'types': ['array']}, {'types': ['expref']})}, 'split': {'function': <function _create_split_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'splitlines': {'function': <function JMESPathProjectConfigFunctions._func_splitlines>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'starts_with': {'function': <function JMESPathProjectConfigFunctions._func_starts_with>, 'signature': ({'types': ['string']}, {'types': ['string', 'array-string'], 'variadic': True})}, 'strip': {'function': <function _create_strip_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string'], 'variadic': True},)}, 'sum': {'function': <function Functions._func_sum>, 'signature': ({'types': ['array-number']},)}, 'swapcase': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'title': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'to_array': {'function': <function Functions._func_to_array>, 'signature': ({'types': []},)}, 'to_items': {'function': <function JMESPathProjectConfigFunctions._func_to_items>, 'signature': ({'types': ['object']},)}, 'to_number': {'function': <function Functions._func_to_number>, 'signature': ({'types': []},)}, 'to_string': {'function': <function Functions._func_to_string>, 'signature': ({'types': []},)}, 'type': {'function': <function Functions._func_type>, 'signature': ({'types': []},)}, 'unset': {'function': <function JMESPathProjectConfigFunctions._func_unset>, 'signature': ({'types': ['object']}, {'types': ['string']})}, 'update': {'function': <function JMESPathProjectConfigFunctions._func_update>, 'signature': ({'types': ['object']}, {'types': ['object']})}, 'upper': {'function': <function _create_simple_transform_function_for_string.<locals>.<lambda>>, 'signature': ({'types': ['string']},)}, 'values': {'function': <function Functions._func_values>, 'signature': ({'types': ['object']},)}, 'zfill': {'function': <function JMESPathProjectConfigFunctions._func_zfill>, 'signature': ({'types': ['string']}, {'types': ['number']})}}
- _func_capitalize(value)
- _func_casefold(value)
- _func_isalnum(value)
- _func_isalpha(value)
- _func_isascii(value)
- _func_isdecimal(value)
- _func_isdigit(value)
- _func_isidentifier(value)
- _func_islower(value)
- _func_isnumeric(value)
- _func_isprintable(value)
- _func_isspace(value)
- _func_istitle(value)
- _func_isupper(value)
- _func_ljust(value, width, *args)
- _func_lower(value)
- _func_lstrip(value, *args)
- _func_partition(value, sep)
- _func_removeprefix(value, affix)
- _func_removesuffix(value, affix)
- _func_rjust(value, width, *args)
- _func_rpartition(value, sep)
- _func_rsplit(value, *args)
- _func_rstrip(value, *args)
- _func_split(value, *args)
- _func_strip(value, *args)
- _func_swapcase(value)
- _func_title(value)
- _func_upper(value)
- project_config.utils.jmespath._create_find_function_for_string_or_array(func_prefix: str) Callable[[type, list[Any] | str, Any, Any], int] [source]
- project_config.utils.jmespath._create_is_function_for_string(func_suffix: str) Callable[[type, str], bool] [source]
- project_config.utils.jmespath._create_just_function_for_string(func_prefix: str) Callable[[type, str, int, Any], str] [source]
- project_config.utils.jmespath._create_partition_function_for_string(func_prefix: str) Callable[[type, str, str], list[str]] [source]
- project_config.utils.jmespath._create_removeaffix_function_for_string(func_suffix: str) Callable[[type, str, str], str] [source]
- project_config.utils.jmespath._create_simple_transform_function_for_string(func_name: str) Callable[[type, str], str] [source]
- project_config.utils.jmespath._create_split_function_for_string(func_prefix: str) Callable[[type, str, Any], list[str]] [source]
- project_config.utils.jmespath._create_strip_function_for_string(func_prefix: str) Callable[[type, str], str] [source]
- project_config.utils.jmespath.compile_JMESPath_expression(expression: str) ParsedResult [source]
Compile a JMESPath expression.
- Parameters:
expression (str) – JMESPath expression to compile.
- Returns:
JMESPath expression compiled.
- Return type:
jmespath.parser.ParsedResult
- project_config.utils.jmespath.compile_JMESPath_expression_or_error(expression: str) ParsedResult [source]
Compile a JMESPath expression or raise a
JMESPathError
.- Parameters:
expression (str) – JMESPath expression to compile.
- Returns:
- JMESPath
expression compiled.
- Return type:
jmespath.parser.ParsedResult
- Raises:
JMESPathError – If the expression cannot be compiled.
- project_config.utils.jmespath.compile_JMESPath_or_expected_value_error(expression: str, expected_value: Any) ParsedResult [source]
Compile a JMESPath expression or raise a
JMESPathError
.You can pass a expected value that was being expected in the error message.
- Parameters:
expression (str) – JMESPath expression to compile.
expected_value (Any) – Value that was expected to match against expression.
- Returns:
JMESPath expression compiled.
- Return type:
jmespath.parser.ParsedResult
- Raises:
JMESPathError – If the expression cannot be compiled.
- project_config.utils.jmespath.compile_JMESPath_or_expected_value_from_other_file_error(expression: str, expected_value_file: str, expected_value_expression: str) ParsedResult [source]
Compile a JMESPath expression or raise a
JMESPathError
.Show that the expression was being expected to match the value applying the expression to another file than the actual.
- Parameters:
- Returns:
- JMESPath
expression compiled.
- Return type:
jmespath.parser.ParsedResult
- Raises:
JMESPathError – If the expression cannot be compiled.
- project_config.utils.jmespath.evaluate_JMESPath(compiled_expression: ParsedResult, instance: Any) Any [source]
Evaluate a JMESPath expression against a instance.
- Parameters:
compiled_expression (
jmespath.parser.ParsedResult
) – JMESPath expression to evaluate.instance (any) – Instance to evaluate the expression against.
- Returns:
Result of the evaluation.
- Return type:
any
- Raises:
JMESPathError – If the expression cannot be evaluated.
- project_config.utils.jmespath.evaluate_JMESPath_or_expected_value_error(compiled_expression: ParsedResult, expected_value: Any, instance: Any) Any [source]
Evaluate a JMESPath expression against a instance or raise a
JMESPathError
.You can pass a expected value that was being expected in the error message.
- Parameters:
compiled_expression (
jmespath.parser.ParsedResult
) – JMESPath expression to evaluate.expected_value (any) – Value that was expected to match against expression.
instance (any) – Instance to evaluate the expression against.
- Returns:
Result of the evaluation.
- Return type:
any
- Raises:
JMESPathError – If the expression cannot be evaluated.
- project_config.utils.jmespath.fix_tree_serialized_file_by_jmespath(compiled_expression: ParsedResult, instance: Any, fpath: str) bool [source]
Fix a file by aplying a JMESPath expression to an instance.
This function is used to fix a file by applying a JMESPath expression. The result of the expression will be the serialized version of the updated instance.
- project_config.utils.jmespath.is_literal_jmespath_expression(expression: str) bool [source]
Check if a JMESPath expression is a literal expression.
- project_config.utils.jmespath.removeprefix(self, prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- project_config.utils.jmespath.removesuffix(self, suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- project_config.utils.jmespath.smart_fixer_by_expected_value(compiled_expression: ParsedResult, expected_value: Any) str [source]
Smart JMESPath fixer queries creator.
Build a smart JMESPath query fixer by altering a expression to match a expected value given the syntax of an expression.
- Parameters:
compiled_expression (
jmespath.parser.ParsedResult
) – JMESPath expression to evaluate.expected_value (any) – Value that was expected to match against expression.
- Returns:
JMESPath query fixer.
- Return type: