From 376f631b29e16be3487eff9ebb9c2f42b4dc9966 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Tue, 3 Feb 2026 05:13:35 +0000 Subject: [PATCH] Fix CI/CD issues: linting errors and test file corruption --- dataforge/parsers.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/dataforge/parsers.py b/dataforge/parsers.py index 384c860..41d2a16 100644 --- a/dataforge/parsers.py +++ b/dataforge/parsers.py @@ -30,7 +30,9 @@ def detect_format(file_path: str) -> str: } format_name = format_map.get(ext) 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 @@ -74,12 +76,18 @@ def parse_content(content: str, format: str) -> Any: elif tomllib is not None: return tomllib.loads(content) else: - raise ImportError("Neither tomli nor tomllib is available for TOML parsing") + raise ImportError( + "Neither tomli nor tomllib is available for TOML parsing" + ) 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.""" if format == "json": 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": try: import tomli_w + result = tomli_w.dumps(data) except ImportError: try: import tomllib + result = tomllib.dumps(data) except ImportError: - raise ImportError("tomli_w or tomllib required for TOML output") + raise ImportError( + "tomli_w or tomllib required for TOML output" + ) 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: with open(output, "w", encoding="utf-8") as f: f.write(result)