This commit is contained in:
2025-12-30 23:19:02 -08:00
parent a97657a757
commit 3bbaa28fb4
17 changed files with 1735 additions and 558 deletions

View File

@@ -14,13 +14,35 @@ _CONFIG_CACHE: Dict[str, Dict[str, Any]] = {}
def _strip_inline_comment(line: str) -> str:
# Keep it simple: only strip full-line comments and inline comments that start after whitespace.
# Users can always quote values that contain '#' or ';'.
# Strip comments in a way that's friendly to common .conf usage:
# - Full-line comments starting with '#' or ';'
# - Inline comments starting with '#' or ';' *outside quotes*
# (e.g. dtype="float16" # optional)
stripped = line.strip()
if not stripped:
return ""
if stripped.startswith("#") or stripped.startswith(";"):
return ""
in_single = False
in_double = False
for i, ch in enumerate(line):
if ch == "'" and not in_double:
in_single = not in_single
continue
if ch == '"' and not in_single:
in_double = not in_double
continue
if in_single or in_double:
continue
if ch in {"#", ";"}:
# Treat as a comment start only when preceded by whitespace.
# This keeps values like paths or tokens containing '#' working
# when quoted, and reduces surprises for unquoted values.
if i == 0 or line[i - 1].isspace():
return line[:i].rstrip()
return line