(path: Path, root: Path)
| 119 | |
| 120 | |
| 121 | def parse_file(path: Path, root: Path) -> dict[str, Any] | None: |
| 122 | try: |
| 123 | text = path.read_text(encoding="utf-8") |
| 124 | except UnicodeDecodeError: |
| 125 | return None |
| 126 | |
| 127 | parsed = parse_text(path.name, text) |
| 128 | if parsed is None: |
| 129 | return None |
| 130 | |
| 131 | stat = path.stat() |
| 132 | rel_path = path.relative_to(root).as_posix() |
| 133 | parsed.update( |
| 134 | { |
| 135 | "id": rel_path, |
| 136 | "name": parsed.get("name") or path.stem, |
| 137 | "source": rel_path, |
| 138 | "collectedAt": datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc).isoformat(), |
| 139 | "sizeBytes": stat.st_size, |
| 140 | } |
| 141 | ) |
| 142 | if "stats" not in parsed: |
| 143 | parsed["stats"] = build_stats(parsed.get("overview", {}), parsed.get("series", [])) |
| 144 | return parsed |
| 145 | |
| 146 | |
| 147 | def parse_text(name: str, text: str) -> dict[str, Any] | None: |
no test coverage detected