Skip to content

Instantly share code, notes, and snippets.

@tcapelle
Last active July 31, 2024 13:19
Show Gist options
  • Save tcapelle/70b66cbd6afe5fc2bfb449cad4f71e07 to your computer and use it in GitHub Desktop.
Save tcapelle/70b66cbd6afe5fc2bfb449cad4f71e07 to your computer and use it in GitHub Desktop.
Dump all weave docs into a single MD file
from dataclasses import dataclass
from pathlib import Path
import simple_parsing
# clone weave:
# git clone https://github.com/wandb/weave
WEAVE_DOCS_PATH = Path("weave/docs/docs")
@dataclass
class ScriptArgs:
weave_docs_path: Path = WEAVE_DOCS_PATH
append_file_path: bool = True
outfile: Path = Path("all_weave_docs.md")
# let's iterate over all markdown files in the WEAVE_DOCS_PATH
def all_md(path: Path) -> list[Path]:
all_md_files = [f for f in path.rglob("**/*.md")]
print(f"Found {len(all_md_files)} markdown files")
return all_md_files
def read_md(path: Path) -> str:
with open(path, "r") as f:
return f.read()
def all_weave_docs(weave_docs_path: Path, append_file_path: bool) -> str:
all_md_files = all_md(weave_docs_path)
all_content = ""
for file in all_md_files:
content = read_md(file)
if append_file_path:
all_content += f"filepath: docs/{file.relative_to(weave_docs_path)}\n\n"
all_content += f"{content}\n\n"
return all_content
if __name__=="__main__":
args = simple_parsing.parse(ScriptArgs)
all_content = all_weave_docs(args.weave_docs_path, args.append_file_path)
with open(args.outfile, "w") as f:
f.write(all_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment