fix: resolve CI/CD test and lint failures
This commit is contained in:
@@ -30,9 +30,7 @@ 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(
|
raise ValueError(f"Unsupported file extension: {ext}. Supported formats: {', '.join(SUPPORTED_FORMATS)}")
|
||||||
f"Unsupported file extension: {ext}. Supported formats: {', '.join(SUPPORTED_FORMATS)}"
|
|
||||||
)
|
|
||||||
return format_name
|
return format_name
|
||||||
|
|
||||||
|
|
||||||
@@ -76,18 +74,12 @@ 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(
|
raise ImportError("Neither tomli nor tomllib is available for TOML parsing")
|
||||||
"Neither tomli nor tomllib is available for TOML parsing"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}")
|
||||||
f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def dump_data(
|
def dump_data(data: Any, format: str, output: Optional[str] = None, indent: int = 2) -> str:
|
||||||
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)
|
||||||
@@ -96,22 +88,16 @@ def dump_data(
|
|||||||
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(
|
raise ImportError("tomli_w or tomllib required for TOML output")
|
||||||
"tomli_w or tomllib required for TOML output"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(f"Unsupported format: {format}. Supported formats: {', '.join(SUPPORTED_FORMATS)}")
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user