Skip to main content
Glama
lin2000wl
by lin2000wl
general.py1.07 kB
import os from typing import Literal, overload from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap def _create_YAML(preserve_comments: bool = False) -> YAML: """ Creates a YAML that can load/save with comments if preserve_comments is True. """ typ = None if preserve_comments else "safe" result = YAML(typ=typ) result.preserve_quotes = preserve_comments return result @overload def load_yaml(path: str, preserve_comments: Literal[False]) -> dict: ... @overload def load_yaml(path: str, preserve_comments: Literal[True]) -> CommentedMap: ... def load_yaml(path: str, preserve_comments: bool = False) -> dict | CommentedMap: with open(path, encoding="utf-8") as f: yaml = _create_YAML(preserve_comments) return yaml.load(f) def save_yaml(path: str, data: dict | CommentedMap, preserve_comments: bool = False) -> None: yaml = _create_YAML(preserve_comments) os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, "w", encoding="utf-8") as f: yaml.dump(data, f)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lin2000wl/Serena-cursor-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server