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. |
normalize_version |
Ensure version is in X.0 format (e.g. '19' → '19.0'). |
removesuffix |
Remove a suffix from a string if present, compatible with Python < 3.9. |
slugify |
Convert a human name to a lowercase, hyphen-separated ASCII slug. |
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 src/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 src/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 |
|
bool
|
Whether to deduplicate the result. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
list
|
List of cleaned, non-empty, non-comment strings or the raw list. |
Source code in src/oops/utils/helpers.py
normalize_version
¶
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 src/oops/utils/helpers.py
slugify
¶
Convert a human name to a lowercase, hyphen-separated ASCII slug.
Strips accents (é → e, à → a) via Unicode NFKD decomposition before replacing any run of non-alphanumeric characters with a single hyphen.
Source code in src/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. |