feat: implement automatic selection of the most recently updated benchmark directory when using --stats without dirnames

This commit is contained in:
Paul Gauthier (aider) 2024-09-25 12:18:39 -07:00
parent e6c938c489
commit 8d90df1ebc

View file

@ -6,13 +6,14 @@ import random
import re import re
import shutil import shutil
import subprocess import subprocess
import sys
import time import time
import traceback import traceback
from collections import defaultdict from collections import defaultdict
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from pathlib import Path from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
from typing import List from typing import List, Optional
import git import git
import lox import lox
@ -40,6 +41,20 @@ NUM_TESTS = (89, 133)
load_dotenv(override=True) load_dotenv(override=True)
def find_latest_benchmark_dir():
benchmark_dirs = [d for d in BENCHMARK_DNAME.iterdir() if d.is_dir()]
if not benchmark_dirs:
print("Error: No benchmark directories found under tmp.benchmarks.")
sys.exit(1)
latest_dir = max(
benchmark_dirs,
key=lambda d: max(f.stat().st_mtime for f in d.rglob('*') if f.is_file()),
)
print(f"Using the most recently updated benchmark directory: {latest_dir.name}")
return latest_dir
def show_stats(dirnames, graphs): def show_stats(dirnames, graphs):
raw_rows = [] raw_rows = []
for dirname in dirnames: for dirname in dirnames:
@ -106,7 +121,9 @@ def resolve_dirname(dirname, use_single_prior, make_new):
@app.command() @app.command()
def main( def main(
dirnames: List[str] = typer.Argument(..., help="Directory names"), dirnames: Optional[List[str]] = typer.Argument(
None, help="Directory names"
),
graphs: bool = typer.Option(False, "--graphs", help="Generate graphs"), graphs: bool = typer.Option(False, "--graphs", help="Generate graphs"),
model: str = typer.Option("gpt-3.5-turbo", "--model", "-m", help="Model name"), model: str = typer.Option("gpt-3.5-turbo", "--model", "-m", help="Model name"),
edit_format: str = typer.Option(None, "--edit-format", "-e", help="Edit format"), edit_format: str = typer.Option(None, "--edit-format", "-e", help="Edit format"),
@ -149,6 +166,13 @@ def main(
if repo.is_dirty(): if repo.is_dirty():
commit_hash += "-dirty" commit_hash += "-dirty"
if stats_only and not dirnames:
latest_dir = find_latest_benchmark_dir()
dirnames = [str(latest_dir)]
if dirnames is None:
dirnames = []
if len(dirnames) > 1 and not (stats_only or diffs_only): if len(dirnames) > 1 and not (stats_only or diffs_only):
print("Only provide 1 dirname unless running with --stats or --diffs") print("Only provide 1 dirname unless running with --stats or --diffs")
return 1 return 1