MCPcopy
hub / github.com/openai/openai-python / format_file

Function format_file

scripts/utils/ruffen-docs.py:122–140  ·  view source on GitHub ↗
(
    filename: str,
    skip_errors: bool,
)

Source from the content-addressed store, hash-verified

120
121
122def format_file(
123 filename: str,
124 skip_errors: bool,
125) -> int:
126 with open(filename, encoding="UTF-8") as f:
127 contents = f.read()
128 new_contents, errors = format_str(contents)
129 for error in errors:
130 lineno = contents[: error.offset].count("\n") + 1
131 print(f"{filename}:{lineno}: code block parse error {error.exc}")
132 if errors and not skip_errors:
133 return 1
134 if contents != new_contents:
135 print(f"{filename}: Rewriting...")
136 with open(filename, "w", encoding="UTF-8") as f:
137 f.write(new_contents)
138 return 0
139 else:
140 return 0
141
142
143def main(argv: Sequence[str] | None = None) -> int:

Callers 1

mainFunction · 0.85

Calls 3

format_strFunction · 0.85
readMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected