Parse a single .h file and return a ParsedFile dict.
(filepath: str, public_root: str)
| 292 | |
| 293 | |
| 294 | def parse_header(filepath: str, public_root: str) -> Optional[dict]: |
| 295 | """Parse a single .h file and return a ParsedFile dict.""" |
| 296 | try: |
| 297 | with open(filepath, 'r', encoding='utf-8', errors='replace') as f: |
| 298 | source = f.read() |
| 299 | except Exception as e: |
| 300 | print(f"[WARN] Could not read {filepath}: {e}", file=sys.stderr) |
| 301 | return None |
| 302 | |
| 303 | rel_path = os.path.relpath(filepath, public_root).replace('\\', '/') |
| 304 | result = ParsedFile( |
| 305 | file=os.path.basename(filepath), |
| 306 | relative_path=rel_path, |
| 307 | ) |
| 308 | |
| 309 | _parse_file(source, result) |
| 310 | return asdict(result) |
| 311 | |
| 312 | |
| 313 | def _parse_file(source: str, result: ParsedFile): |
no test coverage detected