kamihi.base.utils
⚓︎
Utility functions and variables for the Kamihi project.
License
MIT
Functions:
| Name | Description |
|---|---|
cron_regex |
Get the compiled regex pattern for validating cron expressions. |
is_valid_cron_expression |
Validate if a given string is a valid cron expression. |
requires |
Check if required optional dependencies are available. |
timer |
Context manager to log the time taken for a block of code. |
cron_regex
cached
⚓︎
cron_regex() -> re.Pattern
Get the compiled regex pattern for validating cron expressions.
Returns:
| Type | Description |
|---|---|
Pattern
|
re.Pattern: The compiled regex pattern. |
Source code in src/kamihi/base/utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
is_valid_cron_expression
⚓︎
is_valid_cron_expression(expression: str) -> bool
Validate if a given string is a valid cron expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The cron expression to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the expression is valid, False otherwise. |
Source code in src/kamihi/base/utils.py
125 126 127 128 129 130 131 132 133 134 135 136 | |
requires
⚓︎
requires(group: str) -> Callable
Check if required optional dependencies are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the extra group to check for dependencies. |
required |
Source code in src/kamihi/base/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
timer
⚓︎
timer(
logger: Logger, message: str, level: str = "DEBUG"
) -> Generator[None, Any, None]
Context manager to log the time taken for a block of code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Logger
|
The logger instance to use for logging. |
required |
|
str
|
The message to log with the elapsed time. |
required |
|
str
|
The logging level to use (default is "DEBUG"). |
'DEBUG'
|
Returns:
| Type | Description |
|---|---|
None
|
Generator[None, Any, None]: A generator that yields control to the block of code being timed. |
Source code in src/kamihi/base/utils.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |