On this page
Shared utility module with helper functions for path resolution, atomic file writes, frontmatter parsing, and text processing used across selfdoc modules.
#selfdoc.utils
#selfdoc.utils
Shared utility functions for selfdoc.
#extract_module_docstring
def extract_module_docstring(filepath)Extract the first line of a Python module's docstring.
Uses ast.parse and ast.get_docstring to read the module-level docstring. Returns the first sentence (up to the first period followed by whitespace/end, or the first newline), truncated to 155 characters. Returns None if the file is not Python, cannot be parsed, or has no module docstring.
#atomic_write
def atomic_write(filepath, content, permissions=None)Write content to filepath atomically.
Writes to a temporary file in the same directory, then replaces the target. Optionally sets file permissions after writing.
#detect_project_version
def detect_project_version(base_dir: str, fallback: str='') -> strDetect project version from manifest files.
Checks sources in order:
- pyproject.toml [project].version
- package.json "version"
- VERSION file (plain text)
Returns fallback if no version is found.