omnipy.util.docstr_macros
Docstring macro expansion utilities.
This module provides functionality to expand macros in Python docstrings while preserving the original docstring (with unexpanded macros) in comment blocks above the docstring.
Created: January 2026
| FUNCTION | DESCRIPTION |
|---|---|
expand_macros |
Expand all macros in text. |
find_macros_in_docstring |
Find all macro references in a docstring. |
get_macros_from_env |
Load macro definitions from environment variables. |
process_content |
Process Python source code, expanding macros in docstrings. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
ENV_MACRO_PREFIX |
|
ORIGINAL_DOCSTRING_PREFIX |
|
ORIGINAL_DOCSTRING_PREFIX
module-attribute
expand_macros
Expand all macros in text.
Source code in src/omnipy/util/docstr_macros.py
find_macros_in_docstring
Find all macro references in a docstring.
Source code in src/omnipy/util/docstr_macros.py
get_macros_from_env
Load macro definitions from environment variables.
Environment variables starting with 'OMNIPY_MACRO_' are treated as macro definitions. For example:
bash
OMNIPY_MACRO_COMMON_PARAM='Parameters:
param1: desc'
defines the macro COMMON_PARAM.
Returns: Dict mapping macro names (with {{...}} delimiters) to their expansion values
Source code in src/omnipy/util/docstr_macros.py
process_content
Process Python source code, expanding macros in docstrings.
Preserves complete original docstrings (with unexpanded macros) in comment blocks immediately before the expanded docstring.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Python source code as a string
TYPE:
|
macros
|
Dict mapping macro names to their expansion values
TYPE:
|
verbose
|
Whether to print verbose output
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, bool]
|
Tuple of (processed_content, was_modified) |
Source code in src/omnipy/util/docstr_macros.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |