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

Function main

scripts/utils/ruffen-docs.py:50–74  ·  view source on GitHub ↗
(argv: Sequence[str] | None = None)

Source from the content-addressed store, hash-verified

48
49
50def main(argv: Sequence[str] | None = None) -> int:
51 parser = argparse.ArgumentParser()
52 parser.add_argument("filenames", nargs="*")
53 args = parser.parse_args(argv)
54
55 contents: dict[str, str] = {}
56 for filename in args.filenames:
57 with open(filename, encoding="UTF-8") as f:
58 contents[filename] = f.read()
59
60 formatted = format_code_blocks(
61 [textwrap.dedent(match["code"]) for src in contents.values() for match in MD_RE.finditer(src)]
62 )
63
64 def _md_match(match: Match[str]) -> str:
65 code = textwrap.indent(formatted[textwrap.dedent(match["code"])], match["indent"])
66 return f"{match['before']}{code}{match['after']}"
67
68 for filename, src in contents.items():
69 new_contents = MD_RE.sub(_md_match, src)
70 if src != new_contents:
71 print(f"{filename}: Rewriting...")
72 with open(filename, "w", encoding="UTF-8") as f:
73 f.write(new_contents)
74 return 0
75
76
77if __name__ == "__main__":

Callers 1

ruffen-docs.pyFile · 0.70

Calls 3

format_code_blocksFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected