From 8186d226f213137aaf29c7fc610c4f8a7161ded4 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 00:08:11 +0000 Subject: [PATCH] fix: resolve CI/CD issues - Poetry setup, type annotations, MyPy errors --- codechunk/cli.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/codechunk/cli.py b/codechunk/cli.py index 8e1316f..68739f5 100644 --- a/codechunk/cli.py +++ b/codechunk/cli.py @@ -1,6 +1,6 @@ import os from pathlib import Path -from typing import Optional, List +from typing import Optional, List, cast import click from rich.console import Console @@ -24,8 +24,8 @@ logger = get_logger(__name__) @click.pass_context def main(ctx: click.Context, verbose: bool, config: Optional[str]) -> None: ctx.ensure_object(dict) - ctx.obj["verbose"] = verbose - ctx.obj["config_path"] = config + ctx.obj["verbose"] = verbose # type: ignore[index] + ctx.obj["config_path"] = config # type: ignore[index] if verbose: logger.setLevel("DEBUG") @@ -43,8 +43,9 @@ def main(ctx: click.Context, verbose: bool, config: Optional[str]) -> None: def generate(ctx: click.Context, path: str, output: Optional[str], format: str, max_tokens: int, include: tuple, exclude: tuple) -> None: """Generate optimized context bundle for LLM.""" - config_path = ctx.obj.get("config_path") - verbose = ctx.obj.get("verbose", False) + ctx_obj = cast(dict, ctx.obj) + config_path = ctx_obj.get("config_path") + verbose = ctx_obj.get("verbose", False) try: config = load_config(config_path) if config_path else Config() @@ -98,7 +99,8 @@ def generate(ctx: click.Context, path: str, output: Optional[str], format: str, @click.pass_context def analyze(ctx: click.Context, path: str, json: bool) -> None: """Analyze codebase and report statistics.""" - verbose = ctx.obj.get("verbose", False) + ctx_obj = cast(dict, ctx.obj) + verbose = ctx_obj.get("verbose", False) try: project_path = Path(path) @@ -113,24 +115,34 @@ def analyze(ctx: click.Context, path: str, json: bool) -> None: chunker = CodeChunker(config.chunking) chunks = chunker.chunk_all(chunks) - stats = { + stats: dict[str, int] = { "total_files": len(parser.files), "total_chunks": len(chunks), - "files_by_language": {}, - "chunks_by_type": {}, "total_lines": sum(c.metadata.line_count for c in chunks), "total_functions": sum(1 for c in chunks if c.chunk_type == "function"), "total_classes": sum(1 for c in chunks if c.chunk_type == "class"), } + files_by_lang: dict[str, int] = {} + chunks_by_type: dict[str, int] = {} + for chunk in chunks: lang = chunk.metadata.language - stats["files_by_language"][lang] = stats["files_by_language"].get(lang, 0) + 1 - stats["chunks_by_type"][chunk.chunk_type] = stats["chunks_by_type"].get(chunk.chunk_type, 0) + 1 + files_by_lang[lang] = files_by_lang.get(lang, 0) + 1 + chunks_by_type[chunk.chunk_type] = chunks_by_type.get(chunk.chunk_type, 0) + 1 if json: import json as json_module - console.print(json_module.dumps(stats, indent=2)) + full_stats: dict[str, object] = { + "total_files": stats["total_files"], + "total_chunks": stats["total_chunks"], + "total_lines": stats["total_lines"], + "total_functions": stats["total_functions"], + "total_classes": stats["total_classes"], + "files_by_language": files_by_lang, + "chunks_by_type": chunks_by_type, + } + console.print(json_module.dumps(full_stats, indent=2)) else: console.print(Panel( Text.from_markup(f""" @@ -143,10 +155,10 @@ Total Functions: {stats['total_functions']} Total Classes: {stats['total_classes']} [b]Files by Language[/b] -{chr(10).join(f' - {lang}: {count}' for lang, count in stats['files_by_language'].items())} +{chr(10).join(f' - {lang}: {count}' for lang, count in files_by_lang.items())} [b]Chunks by Type[/b] -{chr(10).join(f' - {type_}: {count}' for type_, count in stats['chunks_by_type'].items())} +{chr(10).join(f' - {type_}: {count}' for type_, count in chunks_by_type.items())} """), title="Analysis Results", expand=False