Fix CI/CD issues: linting errors and test file corruption
Some checks failed
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.8) (push) Has been cancelled
CI / test (ubuntu-latest, 3.9) (push) Has been cancelled
CI / test-minimal (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled

This commit is contained in:
2026-02-03 05:13:35 +00:00
parent 21aa249d68
commit 376f631b29

View File

@@ -30,7 +30,9 @@ def detect_format(file_path: str) -> str:
} }
format_name = format_map.get(ext) format_name = format_map.get(ext)
if format_name is None: if format_name is None:
raise ValueError(f"Unsupported file extension: {ext}. Supported formats: {', '.join(SUPPORTED_FORMATS)}") raise ValueError(
f"Unsupported file extension: {ext}. Supported formats: {', '.join(SUPPORTED_FORMATS)}"
)
return format_name return format_name
@@ -74,12 +76,18 @@ def parse_content(content: str, format: str) -> Any:
elif tomllib is not None: elif tomllib is not None:
return tomllib.loads(content) return tomllib.loads(content)
else: else:
raise ImportError("Neither tomli nor tomllib is available for TOML parsing") raise ImportError(
"Neither tomli nor tomllib is available for TOML parsing"
)
else: else:
raise ValueError(f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}") raise ValueError(
f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}"
)
def dump_data(data: Any, format: str, output: Optional[str] = None, indent: int = 2) -> str: def dump_data(
data: Any, format: str, output: Optional[str] = None, indent: int = 2
) -> str:
"""Dump data to string or file based on format.""" """Dump data to string or file based on format."""
if format == "json": if format == "json":
result = json.dumps(data, indent=indent, ensure_ascii=False) result = json.dumps(data, indent=indent, ensure_ascii=False)
@@ -88,16 +96,22 @@ def dump_data(data: Any, format: str, output: Optional[str] = None, indent: int
elif format == "toml": elif format == "toml":
try: try:
import tomli_w import tomli_w
result = tomli_w.dumps(data) result = tomli_w.dumps(data)
except ImportError: except ImportError:
try: try:
import tomllib import tomllib
result = tomllib.dumps(data) result = tomllib.dumps(data)
except ImportError: except ImportError:
raise ImportError("tomli_w or tomllib required for TOML output") raise ImportError(
"tomli_w or tomllib required for TOML output"
)
else: else:
raise ValueError(f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}") raise ValueError(
f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}"
)
if output: if output:
with open(output, "w", encoding="utf-8") as f: with open(output, "w", encoding="utf-8") as f:
f.write(result) f.write(result)