Files
document_analyzer/skills/ir_generation_skill/scripts/print_ir.py
pzhang_zywl 40567a4fb6
CI / test (push) Successful in 30s
Initial commit: document_analyzer with CI/CD pipeline
- 4 skill pipeline (doc_parser, conflict_detection, ir_generation, resolution_application)
- CI workflow on push/PR (.gitea/workflows/ci.yml)
- Auto-issue on CI failure (.gitea/workflows/auto-issue.yml)
- Pytest smoke tests (tests/test_sample.py)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 20:00:26 +08:00

50 lines
1.6 KiB
Python

import argparse
import sys
import yaml
def print_ir(yaml_path: str) -> None:
with open(yaml_path, "r", encoding="utf-8") as f:
data = yaml.safe_load(f)
if not isinstance(data, list):
print(f"Expected a YAML list, got {type(data).__name__}")
sys.exit(1)
for i, item in enumerate(data):
yc = item.get("converted")
if yc is None:
continue
# yaml_content is a raw string that happens to look like YAML —
# parse it then pretty-print it back
if isinstance(yc, str):
stripped = yc.strip()
# Strip markdown code fences: ```yaml / ``` at start, ``` at end
if stripped.startswith("```"):
first_newline = stripped.find("\n")
stripped = stripped[first_newline + 1:] if first_newline != -1 else stripped[3:]
if stripped.endswith("```"):
stripped = stripped[:-3]
try:
parsed = yaml.safe_load(stripped)
except yaml.YAMLError:
print(yc)
raise
else:
parsed = yc
if isinstance(parsed, (dict, list)):
print(yaml.dump(parsed, allow_unicode=True, default_flow_style=False, sort_keys=False).rstrip())
else:
print(str(parsed))
print("=" * 60)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Pretty-print yaml_content fields from an analysis YAML file.")
parser.add_argument("input", metavar="file.yaml", help="Path to a _文字.yaml or _图片.yaml file")
args = parser.parse_args()
print_ir(args.input)