Add framework detector and setup generator
This commit is contained in:
44
src/contextgen/analyzers/convention_extractor.py
Normal file
44
src/contextgen/analyzers/convention_extractor.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
"""Convention extractor for analyzing coding style patterns."""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from contextgen.analyzers.base import BaseAnalyzer
|
||||||
|
from contextgen.analyzers.naming_analyzer import NamingConventionAnalyzer
|
||||||
|
from contextgen.analyzers.style_analyzer import StyleAnalyzer
|
||||||
|
from contextgen.analyzers.documentation_analyzer import DocumentationPatternAnalyzer
|
||||||
|
|
||||||
|
|
||||||
|
class ConventionExtractor(BaseAnalyzer):
|
||||||
|
"""Extracts coding conventions from project files."""
|
||||||
|
|
||||||
|
def __init__(self, project_path: Path):
|
||||||
|
super().__init__(project_path)
|
||||||
|
self.naming_analyzer = NamingConventionAnalyzer(project_path)
|
||||||
|
self.style_analyzer = StyleAnalyzer(project_path)
|
||||||
|
self.documentation_analyzer = DocumentationPatternAnalyzer(project_path)
|
||||||
|
|
||||||
|
def analyze(self) -> dict[str, Any]:
|
||||||
|
"""Run all convention analyzers and aggregate results."""
|
||||||
|
naming = self.naming_analyzer.analyze()
|
||||||
|
style = self.style_analyzer.analyze()
|
||||||
|
documentation = self.documentation_analyzer.analyze()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"naming": naming,
|
||||||
|
"style": style,
|
||||||
|
"documentation": documentation,
|
||||||
|
"summary": self._generate_summary(naming, style, documentation),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _generate_summary(
|
||||||
|
self, naming: dict[str, Any], style: dict[str, Any], documentation: dict[str, Any]
|
||||||
|
) -> dict[str, str]:
|
||||||
|
"""Generate a human-readable summary of conventions."""
|
||||||
|
return {
|
||||||
|
"naming_convention": naming.get("dominant_style", "unknown"),
|
||||||
|
"indentation": f"{style.get('indentation', 'unknown')} spaces",
|
||||||
|
"quote_style": style.get("quote_style", "unknown"),
|
||||||
|
"line_endings": style.get("line_endings", "unknown"),
|
||||||
|
"docstring_style": documentation.get("style", "unknown"),
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user