Skip to content

Commit b99fe30

Browse files
style: run black formatter on all cli and test files
Fix pre-existing formatting issues flagged by CI black --check. Made-with: Cursor
1 parent e414c52 commit b99fe30

15 files changed

Lines changed: 175 additions & 91 deletions

cli/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def get_github_token() -> Optional[str]:
1919
# Fallback: use GitHub CLI token (has SSO auth for orgs)
2020
try:
2121
import subprocess
22+
2223
result = subprocess.run(
2324
["gh", "auth", "token"],
2425
capture_output=True,
@@ -117,11 +118,7 @@ def get_bedrock_config() -> tuple[str, str]:
117118
"""
118119
from .constants import DEFAULT_BEDROCK_MODEL
119120

120-
region = (
121-
os.getenv("BEDROCK_REGION")
122-
or os.getenv("AWS_REGION")
123-
or "us-east-1"
124-
)
121+
region = os.getenv("BEDROCK_REGION") or os.getenv("AWS_REGION") or "us-east-1"
125122
model_id = os.getenv("BEDROCK_MODEL_ID") or DEFAULT_BEDROCK_MODEL
126123
return (region, model_id)
127124

cli/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,9 @@ def update_complexity_label(
975975

976976
# Post explanation as comment if provided
977977
if explanation and explanation.strip():
978-
comment_body = f"## Complexity Analysis\n\n**Score:** {complexity}/10\n\n{explanation.strip()}"
978+
comment_body = (
979+
f"## Complexity Analysis\n\n**Score:** {complexity}/10\n\n{explanation.strip()}"
980+
)
979981
add_pr_comment(owner, repo, pr, comment_body, token, timeout)
980982

981983
return new_label
@@ -1123,9 +1125,7 @@ def list_user_repos(
11231125
# Parse ISO format
11241126
if pushed_at.endswith("Z"):
11251127
pushed_at = pushed_at[:-1] + "+00:00"
1126-
dt = datetime.fromisoformat(
1127-
pushed_at.replace("Z", "+00:00")
1128-
)
1128+
dt = datetime.fromisoformat(pushed_at.replace("Z", "+00:00"))
11291129
# Make pushed_since timezone-aware for comparison
11301130
since_aware = (
11311131
pushed_since

cli/llm_bedrock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def analyze_complexity(
9999
f"diff_excerpt:\n{diff_excerpt}\n\nstats_json:\n{stats_json}\n\ntitle:\n{title}"
100100
)
101101

102-
json_instruction = (
103-
"\n\nRespond with ONLY a valid JSON object: {\"complexity\": <int 1-10>, \"explanation\": \"<string>\"}"
104-
)
102+
json_instruction = '\n\nRespond with ONLY a valid JSON object: {"complexity": <int 1-10>, "explanation": "<string>"}'
105103

106104
messages = [
107105
{"role": "user", "content": [{"text": user_content}]},
@@ -114,7 +112,9 @@ def analyze_complexity(
114112
kwargs: Dict[str, Any] = {
115113
"modelId": self._model,
116114
"messages": messages,
117-
"system": [{"text": prompt + ("" if use_structured_output else json_instruction)}],
115+
"system": [
116+
{"text": prompt + ("" if use_structured_output else json_instruction)}
117+
],
118118
"inferenceConfig": {
119119
"maxTokens": 2048,
120120
"temperature": 0.0,

cli/main.py

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,14 @@ def analyze_pr(
465465
github_token: Optional[str] = typer.Option(None, "--github-token", help="GitHub token"),
466466
verbose: bool = typer.Option(False, "--verbose", "-v", help="Enable verbose logging"),
467467
provider: Optional[str] = typer.Option(
468-
None, "--provider", help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)"
468+
None,
469+
"--provider",
470+
help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)",
469471
),
470472
bedrock_model: Optional[str] = typer.Option(
471-
None, "--bedrock-model", help="Bedrock model ID (e.g. anthropic.claude-sonnet-4-5-20250929-v1:0)"
473+
None,
474+
"--bedrock-model",
475+
help="Bedrock model ID (e.g. anthropic.claude-sonnet-4-5-20250929-v1:0)",
472476
),
473477
bedrock_region: Optional[str] = typer.Option(
474478
None, "--bedrock-region", help="AWS region for Bedrock (default: AWS_REGION or us-east-1)"
@@ -518,10 +522,15 @@ def batch_analyze(
518522
None, "--input-file", "-i", help="File containing PR URLs (one per line)"
519523
),
520524
repos_file: Optional[Path] = typer.Option(
521-
None, "--repos-file", "-r", help="File containing repo names (owner/repo per line) for date range search"
525+
None,
526+
"--repos-file",
527+
"-r",
528+
help="File containing repo names (owner/repo per line) for date range search",
522529
),
523530
all_repos: bool = typer.Option(
524-
False, "--all-repos", help="Dynamically scan all repos the authenticated user has access to (use with --since/--until or --days)"
531+
False,
532+
"--all-repos",
533+
help="Dynamically scan all repos the authenticated user has access to (use with --since/--until or --days)",
525534
),
526535
org: Optional[str] = typer.Option(
527536
None, "--org", help="Organization name (for date range search)"
@@ -533,7 +542,10 @@ def batch_analyze(
533542
None, "--until", help="End date (YYYY-MM-DD) for date range search"
534543
),
535544
days: Optional[int] = typer.Option(
536-
None, "--days", "-d", help="Shortcut: last N days (e.g. --days 5 for last 5 days). Use with --all-repos."
545+
None,
546+
"--days",
547+
"-d",
548+
help="Shortcut: last N days (e.g. --days 5 for last 5 days). Use with --all-repos.",
537549
),
538550
output_file: Optional[Path] = typer.Option(
539551
None, "--output", "-o", help="Output CSV file path (required unless --label is used)"
@@ -579,11 +591,11 @@ def batch_analyze(
579591
"Can also be set via GH_TOKENS or GITHUB_TOKENS environment variables.",
580592
),
581593
provider: Optional[str] = typer.Option(
582-
None, "--provider", help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)"
583-
),
584-
bedrock_model: Optional[str] = typer.Option(
585-
None, "--bedrock-model", help="Bedrock model ID"
594+
None,
595+
"--provider",
596+
help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)",
586597
),
598+
bedrock_model: Optional[str] = typer.Option(None, "--bedrock-model", help="Bedrock model ID"),
587599
bedrock_region: Optional[str] = typer.Option(
588600
None, "--bedrock-region", help="AWS region for Bedrock"
589601
),
@@ -594,7 +606,10 @@ def batch_analyze(
594606
None, "--limit", "-n", help="Maximum number of PRs to process (e.g. --limit 10)"
595607
),
596608
overwrite: bool = typer.Option(
597-
False, "--overwrite", "--full-sync", help="Ignore existing CSV; fetch full date range (default: incremental fetch from latest CSV data)"
609+
False,
610+
"--overwrite",
611+
"--full-sync",
612+
help="Ignore existing CSV; fetch full date range (default: incremental fetch from latest CSV data)",
598613
),
599614
fetch_only: bool = typer.Option(
600615
False, "--fetch-only", help="Only fetch PR URLs to cache; skip analysis and labeling"
@@ -637,13 +652,24 @@ def batch_analyze(
637652
raise typer.Exit(1)
638653

639654
if sum(bool(x) for x in [org, repos_file, all_repos]) > 1:
640-
typer.echo("Error: Cannot specify more than one of --org, --repos-file, --all-repos", err=True)
655+
typer.echo(
656+
"Error: Cannot specify more than one of --org, --repos-file, --all-repos", err=True
657+
)
641658
raise typer.Exit(1)
642659

643660
has_date_range = org and (bool(since and until) or (days is not None and days > 0))
644-
has_repos_date_range = repos_file and (bool(since and until) or (days is not None and days > 0))
645-
has_all_repos_date_range = all_repos and (bool(since and until) or (days is not None and days > 0))
646-
if not input_file and not has_date_range and not has_repos_date_range and not has_all_repos_date_range:
661+
has_repos_date_range = repos_file and (
662+
bool(since and until) or (days is not None and days > 0)
663+
)
664+
has_all_repos_date_range = all_repos and (
665+
bool(since and until) or (days is not None and days > 0)
666+
)
667+
if (
668+
not input_file
669+
and not has_date_range
670+
and not has_repos_date_range
671+
and not has_all_repos_date_range
672+
):
647673
typer.echo(
648674
"Error: Must specify either --input-file OR (--org, --since/--until or --days) OR (--repos-file, --since/--until or --days) OR (--all-repos, --since/--until or --days)",
649675
err=True,
@@ -652,7 +678,9 @@ def batch_analyze(
652678

653679
# Require output_file unless --label or --fetch-only is used
654680
if not label and not output_file and not fetch_only:
655-
typer.echo("Error: --output is required unless --label or --fetch-only is used", err=True)
681+
typer.echo(
682+
"Error: --output is required unless --label or --fetch-only is used", err=True
683+
)
656684
raise typer.Exit(1)
657685

658686
# When labeling, default to writing CSV as well (override with --output)
@@ -663,14 +691,19 @@ def batch_analyze(
663691
openai_key = get_openai_api_key() if not fetch_only else None
664692

665693
if not fetch_only and provider == "openai" and not openai_key:
666-
typer.echo("Error: OPENAI_API_KEY environment variable is required for openai provider", err=True)
694+
typer.echo(
695+
"Error: OPENAI_API_KEY environment variable is required for openai provider",
696+
err=True,
697+
)
667698
typer.echo("Set it with: export OPENAI_API_KEY='your-key'", err=True)
668699
raise typer.Exit(1)
669700
if not fetch_only and provider == "anthropic" and not get_anthropic_api_key():
670701
typer.echo("Error: ANTHROPIC_API_KEY is required for anthropic provider", err=True)
671702
raise typer.Exit(1)
672703
if not fetch_only and provider == "bedrock":
673-
typer.echo("Using Bedrock provider. Ensure AWS_PROFILE and AWS_REGION are set.", err=True)
704+
typer.echo(
705+
"Using Bedrock provider. Ensure AWS_PROFILE and AWS_REGION are set.", err=True
706+
)
674707

675708
# Get GitHub tokens - CLI option takes precedence over environment
676709
token_list: List[str] = []
@@ -758,7 +791,10 @@ def batch_analyze(
758791

759792
if all_repos:
760793
if not github_token:
761-
typer.echo("Error: GitHub token required for --all-repos. Set GH_TOKEN or run `gh auth login`", err=True)
794+
typer.echo(
795+
"Error: GitHub token required for --all-repos. Set GH_TOKEN or run `gh auth login`",
796+
err=True,
797+
)
762798
raise typer.Exit(1)
763799
pr_urls = generate_pr_list_from_all_repos(
764800
since=since_dt,
@@ -887,7 +923,10 @@ def export_labels(
887923
DEFAULT_SLEEP_SECONDS, "--sleep-seconds", help="Sleep between GitHub API calls"
888924
),
889925
overwrite: bool = typer.Option(
890-
False, "--overwrite", "--full-sync", help="Ignore existing CSV; fetch full date range (default: incremental fetch from latest CSV data)"
926+
False,
927+
"--overwrite",
928+
"--full-sync",
929+
help="Ignore existing CSV; fetch full date range (default: incremental fetch from latest CSV data)",
891930
),
892931
):
893932
"""
@@ -921,7 +960,9 @@ def export_labels(
921960

922961
github_token = get_github_token()
923962
if not github_token:
924-
typer.echo("Error: GitHub token required. Set GH_TOKEN or run `gh auth login`", err=True)
963+
typer.echo(
964+
"Error: GitHub token required. Set GH_TOKEN or run `gh auth login`", err=True
965+
)
925966
raise typer.Exit(1)
926967

927968
if input_file:
@@ -1026,9 +1067,7 @@ def export_labels(
10261067

10271068
@app.command(name="generate-reports")
10281069
def generate_reports(
1029-
csv_path: Path = typer.Option(
1030-
"complexity-report.csv", "--input", "-i", help="Input CSV path"
1031-
),
1070+
csv_path: Path = typer.Option("complexity-report.csv", "--input", "-i", help="Input CSV path"),
10321071
output_dir: Path = typer.Option(
10331072
"reports", "--output", "-o", help="Output directory for report images"
10341073
),
@@ -1065,7 +1104,10 @@ def migrate_csv(
10651104
"complexity-report.csv", "--output", "-o", help="Output CSV path (can be same as input)"
10661105
),
10671106
background: bool = typer.Option(
1068-
False, "--background", "-b", help="Run migration in background, log to reports/migration.log"
1107+
False,
1108+
"--background",
1109+
"-b",
1110+
help="Run migration in background, log to reports/migration.log",
10691111
),
10701112
sleep_seconds: float = typer.Option(
10711113
DEFAULT_SLEEP_SECONDS, "--sleep-seconds", help="Sleep between GitHub API calls"
@@ -1082,7 +1124,9 @@ def migrate_csv(
10821124

10831125
github_token = get_github_token()
10841126
if not github_token:
1085-
typer.echo("Warning: GH_TOKEN not set. GitHub API calls may fail for private repos.", err=True)
1127+
typer.echo(
1128+
"Warning: GH_TOKEN not set. GitHub API calls may fail for private repos.", err=True
1129+
)
10861130

10871131
if background:
10881132
pid = run_migration_background(
@@ -1123,9 +1167,7 @@ def verify_settings(
11231167
csv_path: Optional[Path] = typer.Option(
11241168
None, "--csv", "-c", help="Path to complexity CSV (default: complexity-report.csv)"
11251169
),
1126-
csv_required: bool = typer.Option(
1127-
False, "--csv-required", help="Fail when CSV is missing"
1128-
),
1170+
csv_required: bool = typer.Option(False, "--csv-required", help="Fail when CSV is missing"),
11291171
):
11301172
"""
11311173
Verify settings required to pull data and generate reports.
@@ -1150,7 +1192,10 @@ def verify_settings(
11501192

11511193
failed = sum(1 for _, ok, _ in results if not ok)
11521194
if failed > 0:
1153-
typer.echo(f"{failed} check(s) failed. Fix missing settings before running batch-analyze or generate-reports.", err=True)
1195+
typer.echo(
1196+
f"{failed} check(s) failed. Fix missing settings before running batch-analyze or generate-reports.",
1197+
err=True,
1198+
)
11541199
raise typer.Exit(1)
11551200
except typer.Exit:
11561201
raise
@@ -1244,11 +1289,11 @@ def label_pr(
12441289
openai_api_key: Optional[str] = typer.Option(None, "--openai-api-key", help="OpenAI API key"),
12451290
github_token: Optional[str] = typer.Option(None, "--github-token", help="GitHub token"),
12461291
provider: Optional[str] = typer.Option(
1247-
None, "--provider", help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)"
1248-
),
1249-
bedrock_model: Optional[str] = typer.Option(
1250-
None, "--bedrock-model", help="Bedrock model ID"
1292+
None,
1293+
"--provider",
1294+
help="LLM provider: openai, anthropic, or bedrock (auto-detected from .env if not set)",
12511295
),
1296+
bedrock_model: Optional[str] = typer.Option(None, "--bedrock-model", help="Bedrock model ID"),
12521297
bedrock_region: Optional[str] = typer.Option(
12531298
None, "--bedrock-region", help="AWS region for Bedrock"
12541299
),

cli/migrate.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def _load_csv_rows(path: Path) -> List[Dict[str, str]]:
3636
)
3737
normalized["pr_url"] = str(pr_url or "").strip()
3838
normalized["complexity"] = str(row.get("complexity") or "").strip()
39-
normalized["developer"] = str(
40-
row.get("developer") or row.get("author") or ""
41-
).strip()
39+
normalized["developer"] = str(row.get("developer") or row.get("author") or "").strip()
4240
normalized["date"] = str(row.get("date") or "").strip()
4341
normalized["team"] = str(row.get("team") or "").strip()
4442
normalized["merged_at"] = str(row.get("merged_at") or "").strip()
@@ -82,6 +80,7 @@ def run_migration(
8280
Returns:
8381
Number of rows enriched
8482
"""
83+
8584
def log(msg: str) -> None:
8685
if progress_callback:
8786
progress_callback(msg)
@@ -122,7 +121,9 @@ def log(msg: str) -> None:
122121
timeout=DEFAULT_TIMEOUT,
123122
)
124123
meta = fetch_pr_metadata(
125-
owner, repo, int(pr),
124+
owner,
125+
repo,
126+
int(pr),
126127
token=token,
127128
timeout=DEFAULT_TIMEOUT,
128129
check_rate_limit_first=False,
@@ -192,9 +193,14 @@ def run_migration_background(
192193
env["GH_TOKEN"] = token
193194

194195
cmd = [
195-
sys.executable, "-m", "cli.main", "migrate-csv",
196-
"--input", str(input_path),
197-
"--output", str(output_path),
196+
sys.executable,
197+
"-m",
198+
"cli.main",
199+
"migrate-csv",
200+
"--input",
201+
str(input_path),
202+
"--output",
203+
str(output_path),
198204
]
199205

200206
with log_file.open("a", encoding="utf-8") as log_handle:

cli/verify.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def run_verify_settings(
5050
if openai_key:
5151
results.append(_check("OPENAI_API_KEY", True))
5252
else:
53-
results.append(
54-
_check("OPENAI_API_KEY", False, "Set OPENAI_API_KEY for --provider openai")
55-
)
53+
results.append(_check("OPENAI_API_KEY", False, "Set OPENAI_API_KEY for --provider openai"))
5654

5755
# Check Anthropic API key
5856
anthropic_key = get_anthropic_api_key()
@@ -91,7 +89,11 @@ def run_verify_settings(
9189
else:
9290
ok = not csv_required
9391
results.append(
94-
_check("CSV path", ok, f"Not found: {csv_file}" if csv_required else f"Optional: {csv_file}")
92+
_check(
93+
"CSV path",
94+
ok,
95+
f"Not found: {csv_file}" if csv_required else f"Optional: {csv_file}",
96+
)
9597
)
9698

9799
# Check team config
@@ -100,7 +102,9 @@ def run_verify_settings(
100102
results.append(_check("Team config (teams.yaml)", True, f"{len(mapping)} mappings"))
101103
else:
102104
results.append(
103-
_check("Team config (teams.yaml)", True, "Optional: copy teams.yaml.example to teams.yaml")
105+
_check(
106+
"Team config (teams.yaml)", True, "Optional: copy teams.yaml.example to teams.yaml"
107+
)
104108
)
105109

106110
# Check required columns in CSV (if exists)

0 commit comments

Comments
 (0)