(
filename: str,
*,
limited_capi: bool,
output: str | None = None,
verify: bool = True,
)
| 47 | |
| 48 | |
| 49 | def parse_file( |
| 50 | filename: str, |
| 51 | *, |
| 52 | limited_capi: bool, |
| 53 | output: str | None = None, |
| 54 | verify: bool = True, |
| 55 | ) -> None: |
| 56 | if not output: |
| 57 | output = filename |
| 58 | |
| 59 | extension = os.path.splitext(filename)[1][1:] |
| 60 | if not extension: |
| 61 | raise ClinicError(f"Can't extract file type for file {filename!r}") |
| 62 | |
| 63 | try: |
| 64 | language = extensions[extension](filename) |
| 65 | except KeyError: |
| 66 | raise ClinicError(f"Can't identify file type for file {filename!r}") |
| 67 | |
| 68 | with open(filename, encoding="utf-8") as f: |
| 69 | raw = f.read() |
| 70 | |
| 71 | # exit quickly if there are no clinic markers in the file |
| 72 | find_start_re = BlockParser("", language).find_start_re |
| 73 | if not find_start_re.search(raw): |
| 74 | return |
| 75 | |
| 76 | if LIMITED_CAPI_REGEX.search(raw): |
| 77 | limited_capi = True |
| 78 | |
| 79 | assert isinstance(language, CLanguage) |
| 80 | clinic = Clinic(language, |
| 81 | verify=verify, |
| 82 | filename=filename, |
| 83 | limited_capi=limited_capi) |
| 84 | cooked = clinic.parse(raw) |
| 85 | |
| 86 | libclinic.write_file(output, cooked) |
| 87 | |
| 88 | |
| 89 | def create_cli() -> argparse.ArgumentParser: |
searching dependent graphs…