MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / format_file

Function format_file

scripts/utils/ruffen-docs.py:155–174  ·  view source on GitHub ↗
(
    filename: str,
    skip_errors: bool,
    format_code_block: Callable[[str], str],
)

Source from the content-addressed store, hash-verified

153
154
155def format_file(
156 filename: str,
157 skip_errors: bool,
158 format_code_block: Callable[[str], str],
159) -> int:
160 with open(filename, encoding="UTF-8") as f:
161 contents = f.read()
162 new_contents, errors = format_str(contents, format_code_block)
163 for error in errors:
164 lineno = contents[: error.offset].count("\n") + 1
165 print(f"{filename}:{lineno}: code block parse error {error.exc}")
166 if errors and not skip_errors:
167 return 1
168 if contents != new_contents:
169 print(f"{filename}: Rewriting...")
170 with open(filename, "w", encoding="UTF-8") as f:
171 f.write(new_contents)
172 return 0
173 else:
174 return 0
175
176
177def main(argv: Sequence[str] | None = None) -> int:

Callers 1

mainFunction · 0.85

Calls 3

format_strFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected