Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev CLI #292

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ cython_debug/

# ControlFlow
src/controlflow/_version.py
all_code.md
all_docs.md
1 change: 1 addition & 0 deletions all_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

45 changes: 45 additions & 0 deletions src/controlflow/cli/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pathlib import Path

import typer

dev_app = typer.Typer(no_args_is_help=True)


@dev_app.command()
def generate_ai_files(
output_path: str = typer.Option(
".",
"--output",
"-o",
help="The path where output files will be written. Defaults to current directory.",
),
):
try:
# Get the absolute path of the ControlFlow main repo
repo_root = Path(__file__).resolve().parents[3]
src_path = repo_root / "src"
docs_path = repo_root / "docs"
output_dir = Path(output_path).resolve()

typer.echo(f"Repo root: {repo_root}")
typer.echo(f"src_path: {src_path}")
typer.echo(f"docs_path: {docs_path}")
typer.echo(f"output_dir: {output_dir}")

def generate_file_content(file_paths, output_file):
with open(output_dir / output_file, "w") as f:
for file_path in file_paths:
f.write(f"# ControlFlow Source File: {file_path.absolute()}\n\n")
f.write(file_path.read_text())
f.write("\n\n")

code_files = list(src_path.rglob("*.py")) + list(src_path.rglob("*.jinja"))
doc_files = list(docs_path.rglob("*.mdx")) + list(docs_path.glob("mint.json"))

generate_file_content(code_files, "all_code.md")
generate_file_content(doc_files, "all_docs.md")

typer.echo(f"Generated all_code.md and all_docs.md in {output_dir}")
except Exception as e:
typer.echo(f"An error occurred: {str(e)}", err=True)
raise typer.Exit(code=1)
4 changes: 4 additions & 0 deletions src/controlflow/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from controlflow import __version__
from controlflow.utilities.rich import console

from .dev import dev_app

app = typer.Typer(no_args_is_help=True)

app.add_typer(dev_app, name="dev")


@app.command()
def version(ctx: Context):
Expand Down
Loading