selfdoc v0.15.1 /selfdoc.utils
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

python
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

python
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

python
def detect_project_version(base_dir: str, fallback: str='') -> str

Detect project version from manifest files.

Checks sources in order:

  1. pyproject.toml [project].version
  2. package.json "version"
  3. VERSION file (plain text)

Returns fallback if no version is found.