INNER CODE UNIT · Python

_read_stripped

onedr0p/cluster-template · template/scripts/plugin.py:12

def _read_stripped(file_path: str) -> str:
    try:
        content = Path(file_path).read_text().strip()
    except FileNotFoundError:
        raise FileNotFoundError(f"File not found: {file_path}") from None
    if not content:
        raise ValueError(f"{file_path} is empty")
    return content


# Return the parsed contents of a JSON file
def _read_json(file_path: str) -> dict[str, Any]:
    try:
        return json.loads(_read_stripped(file_path))
    except json.JSONDecodeError:
        raise ValueError(f"Could not decode JSON file: {file_path}") from None

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…