Helpers¶
helpers
¶
Functions:
| Name | Description |
|---|---|
clean_string |
Convert a value to a stripped string, returning an empty string for falsy input. |
date_from_string |
Convert an 8-character YYYYMMDD string into a date object. |
deep_visit |
Yield flattened (path, value) pairs by recursively walking a nested structure. |
filter_and_clean |
Filter comment lines and clean inline comments from a list of strings. |
removesuffix |
Remove a suffix from a string if present, compatible with Python < 3.9. |
str_to_list |
Split a separated string into a list of cleaned, non-empty items. |
clean_string
¶
date_from_string
¶
Convert an 8-character YYYYMMDD string into a date object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Date string in YYYYMMDD format (exactly 8 characters). |
required |
Returns:
| Type | Description |
|---|---|
date
|
Corresponding date object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If raw is not exactly 8 characters long. |
Source code in oops/utils/helpers.py
deep_visit
¶
Yield flattened (path, value) pairs by recursively walking a nested structure.
Dict keys become dot-separated segments; list indices become [n] segments.
Example: assets.web.assets_backend[0] → "/module/static/..."
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Nested dict, list, tuple, or scalar to walk. |
required |
|
str
|
Accumulated path prefix for the current node. Defaults to "". |
''
|
Yields:
| Type | Description |
|---|---|
Generator[tuple[str, Any]]
|
Tuple of (dotted_path_string, leaf_value) for each scalar encountered. |
Source code in oops/utils/helpers.py
filter_and_clean
¶
Filter comment lines and clean inline comments from a list of strings.
Strips full-line comments (starting with #), blank lines, and inline
comments (everything after # on a line).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
List[str]
|
Lines of text to process. |
required |
Returns:
| Type | Description |
|---|---|
set
|
Set of cleaned, non-empty, non-comment strings. |
Source code in oops/utils/helpers.py
removesuffix
¶
Remove a suffix from a string if present, compatible with Python < 3.9.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Input string to process. |
required |
|
str
|
Suffix to strip if present. |
required |
Returns:
| Type | Description |
|---|---|
str
|
String with the suffix removed, or the original string if not present. |
Source code in oops/utils/helpers.py
str_to_list
¶
Split a separated string into a list of cleaned, non-empty items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Input string to split. |
required |
|
str
|
Separator character or string. Defaults to ",". |
','
|
Returns:
| Type | Description |
|---|---|
list
|
List of stripped, non-empty strings. |