MCPcopy Index your code
hub / github.com/python/cpython / parse_file

Function parse_file

Tools/clinic/libclinic/cli.py:49–86  ·  view source on GitHub ↗
(
        filename: str,
        *,
        limited_capi: bool,
        output: str | None = None,
        verify: bool = True,
)

Source from the content-addressed store, hash-verified

47
48
49def 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
89def create_cli() -> argparse.ArgumentParser:

Callers 2

run_clinicFunction · 0.70

Calls 8

parseMethod · 0.95
ClinicErrorClass · 0.90
BlockParserClass · 0.90
ClinicClass · 0.90
splitextMethod · 0.80
openFunction · 0.50
readMethod · 0.45
searchMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…