tenets.core.examiner
Package¶
Code examination and inspection package.
This package provides comprehensive code analysis capabilities including metrics calculation, complexity analysis, ownership tracking, and hotspot detection. It extracts the core examination logic from CLI commands to provide a reusable, testable API.
The examiner package works in conjunction with the analyzer package, adding higher-level insights and aggregations on top of basic file analysis.
Main components: - Examiner: Main orchestrator for code examination - MetricsCalculator: Calculate code metrics and statistics - ComplexityAnalyzer: Analyze code complexity patterns - OwnershipTracker: Track code ownership and contribution patterns - HotspotDetector: Identify frequently changed or problematic areas
Example usage
from tenets.core.examiner import Examiner from tenets.config import TenetsConfig
config = TenetsConfig() examiner = Examiner(config)
Comprehensive examination¶
results = examiner.examine_project( ... path=Path("./src"), ... deep=True, ... include_git=True ... )
print(f"Total files: {results.total_files}") print(f"Average complexity: {results.metrics.avg_complexity}") print(f"Top contributors: {results.ownership.top_contributors}")
Classes¶
ComplexityAnalyzer¶
Analyzer for code complexity metrics.
Provides comprehensive complexity analysis including cyclomatic complexity, cognitive complexity, and various other metrics to assess code maintainability and identify refactoring opportunities.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
complexity_cache | Cache of computed complexities |
Initialize complexity analyzer.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
complexity_cacheinstance-attribute
¶
Functions¶
analyze¶
Analyze complexity for a list of files.
Performs comprehensive complexity analysis across all provided files, calculating various metrics and identifying problem areas.
PARAMETER | DESCRIPTION |
---|---|
files | List of analyzed file objects |
threshold | Complexity threshold for flagging TYPE: |
deep | Whether to perform deep analysis TYPE: |
RETURNS | DESCRIPTION |
---|---|
ComplexityReport | Comprehensive complexity analysis TYPE: |
Example
analyzer = ComplexityAnalyzer(config) report = analyzer.analyze(files, threshold=10) print(f"Average complexity: {report.avg_complexity}")
ComplexityReportdataclass
¶
ComplexityReport(total_files: int = 0, total_functions: int = 0, total_classes: int = 0, avg_complexity: float = 0.0, max_complexity: int = 0, median_complexity: float = 0.0, std_dev_complexity: float = 0.0, high_complexity_count: int = 0, very_high_complexity_count: int = 0, files: List[FileComplexity] = list(), top_complex_functions: List[FunctionComplexity] = list(), top_complex_classes: List[ClassComplexity] = list(), top_complex_files: List[FileComplexity] = list(), complexity_distribution: Dict[str, int] = dict(), refactoring_candidates: List[Dict[str, Any]] = list(), technical_debt_hours: float = 0.0, trend_direction: str = 'stable', recommendations: List[str] = list(), _override_complexity_score: Optional[float] = None)
Comprehensive complexity analysis report.
Aggregates complexity analysis across an entire codebase, providing statistics, trends, and actionable insights.
ATTRIBUTE | DESCRIPTION |
---|---|
total_files | Total files analyzed TYPE: |
total_functions | Total functions analyzed TYPE: |
total_classes | Total classes analyzed TYPE: |
avg_complexity | Average cyclomatic complexity TYPE: |
max_complexity | Maximum cyclomatic complexity found TYPE: |
median_complexity | Median cyclomatic complexity TYPE: |
std_dev_complexity | Standard deviation of complexity TYPE: |
high_complexity_count | Count of high complexity items TYPE: |
very_high_complexity_count | Count of very high complexity items TYPE: |
files | List of file complexity analyses TYPE: |
top_complex_functions | Most complex functions TYPE: |
top_complex_classes | Most complex classes TYPE: |
top_complex_files | Most complex files TYPE: |
complexity_distribution | Distribution of complexity values |
refactoring_candidates | Items recommended for refactoring |
technical_debt_hours | Estimated hours to address complexity TYPE: |
trend_direction | Whether complexity is increasing/decreasing TYPE: |
recommendations | List of actionable recommendations |
Attributes¶
total_filesclass-attribute
instance-attribute
¶
total_functionsclass-attribute
instance-attribute
¶
total_classesclass-attribute
instance-attribute
¶
avg_complexityclass-attribute
instance-attribute
¶
max_complexityclass-attribute
instance-attribute
¶
median_complexityclass-attribute
instance-attribute
¶
std_dev_complexityclass-attribute
instance-attribute
¶
high_complexity_countclass-attribute
instance-attribute
¶
very_high_complexity_countclass-attribute
instance-attribute
¶
filesclass-attribute
instance-attribute
¶
top_complex_functionsclass-attribute
instance-attribute
¶
top_complex_classesclass-attribute
instance-attribute
¶
top_complex_filesclass-attribute
instance-attribute
¶
complexity_distributionclass-attribute
instance-attribute
¶
refactoring_candidatesclass-attribute
instance-attribute
¶
technical_debt_hoursclass-attribute
instance-attribute
¶
trend_directionclass-attribute
instance-attribute
¶
recommendationsclass-attribute
instance-attribute
¶
complexity_scoreproperty
¶
Calculate overall complexity score (0-100).
Lower scores indicate better (less complex) code.
RETURNS | DESCRIPTION |
---|---|
float | Complexity score TYPE: |
Functions¶
ExaminationResultdataclass
¶
ExaminationResult(root_path: Path, total_files: int = 0, total_lines: int = 0, languages: List[str] = list(), files: List[Any] = list(), metrics: Optional[MetricsReport] = None, complexity: Optional[ComplexityReport] = None, ownership: Optional[OwnershipReport] = None, hotspots: Optional[HotspotReport] = None, git_analysis: Optional[Any] = None, summary: Dict[str, Any] = dict(), timestamp: datetime = datetime.now(), duration: float = 0.0, config: Optional[TenetsConfig] = None, errors: List[str] = list(), excluded_files: List[str] = list(), excluded_count: int = 0, ignored_patterns: List[str] = list())
Comprehensive examination results for a codebase.
This dataclass aggregates all examination findings including metrics, complexity analysis, ownership patterns, and detected hotspots. It provides a complete picture of codebase health and structure.
ATTRIBUTE | DESCRIPTION |
---|---|
root_path | Root directory that was examined TYPE: |
total_files | Total number of files analyzed TYPE: |
total_lines | Total lines of code across all files TYPE: |
languages | List of programming languages detected |
files | List of analyzed file objects |
metrics | Detailed metrics report TYPE: |
complexity | Complexity analysis report TYPE: |
ownership | Code ownership report TYPE: |
hotspots | Detected hotspot report TYPE: |
git_analysis | Git repository analysis if available |
summary | High-level summary statistics |
timestamp | When examination was performed TYPE: |
duration | How long examination took in seconds TYPE: |
config | Configuration used for examination TYPE: |
errors | Any errors encountered during examination |
Attributes¶
root_pathinstance-attribute
¶
total_filesclass-attribute
instance-attribute
¶
total_linesclass-attribute
instance-attribute
¶
languagesclass-attribute
instance-attribute
¶
filesclass-attribute
instance-attribute
¶
metricsclass-attribute
instance-attribute
¶
complexityclass-attribute
instance-attribute
¶
ownershipclass-attribute
instance-attribute
¶
hotspotsclass-attribute
instance-attribute
¶
git_analysisclass-attribute
instance-attribute
¶
summaryclass-attribute
instance-attribute
¶
timestampclass-attribute
instance-attribute
¶
durationclass-attribute
instance-attribute
¶
configclass-attribute
instance-attribute
¶
errorsclass-attribute
instance-attribute
¶
excluded_filesclass-attribute
instance-attribute
¶
excluded_countclass-attribute
instance-attribute
¶
ignored_patternsclass-attribute
instance-attribute
¶
has_issuesproperty
¶
Check if examination found any issues.
RETURNS | DESCRIPTION |
---|---|
bool | True if any issues were detected TYPE: |
health_scoreproperty
¶
Calculate overall codebase health score.
Computes a health score from 0-100 based on various metrics including complexity, test coverage, documentation, and hotspots.
RETURNS | DESCRIPTION |
---|---|
float | Health score between 0 and 100 TYPE: |
Functions¶
to_dict¶
Examiner¶
Main orchestrator for code examination operations.
The Examiner class coordinates all examination activities, managing the analysis pipeline from file discovery through final reporting. It integrates various analyzers and trackers to provide comprehensive codebase insights.
This class serves as the primary API for examination functionality, handling configuration, error recovery, and result aggregation.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
analyzer | Code analyzer instance TYPE: |
scanner | File scanner instance |
metrics_calculator | Metrics calculation instance |
complexity_analyzer | Complexity analysis instance |
ownership_tracker | Ownership tracking instance |
hotspot_detector | Hotspot detection instance |
Initialize the Examiner with configuration.
Sets up all required components for examination including analyzers, scanners, and specialized examination modules.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance with examination settings TYPE: |
Attributes¶
analyzerproperty
writable
¶
configinstance-attribute
¶
loggerinstance-attribute
¶
scannerinstance-attribute
¶
metrics_calculatorinstance-attribute
¶
complexity_analyzerinstance-attribute
¶
ownership_trackerinstance-attribute
¶
hotspot_detectorinstance-attribute
¶
cacheinstance-attribute
¶
Functions¶
examine_project¶
examine_project(path: Path, deep: bool = False, include_git: bool = True, include_metrics: bool = True, include_complexity: bool = True, include_ownership: bool = True, include_hotspots: bool = True, include_patterns: Optional[List[str]] = None, exclude_patterns: Optional[List[str]] = None, max_files: Optional[int] = None) -> ExaminationResult
Perform comprehensive project examination.
Conducts a full examination of the specified project, running all requested analysis types and aggregating results into a comprehensive report.
PARAMETER | DESCRIPTION |
---|---|
path | Path to project directory TYPE: |
deep | Whether to perform deep AST-based analysis TYPE: |
include_git | Whether to include git repository analysis TYPE: |
include_metrics | Whether to calculate code metrics TYPE: |
include_complexity | Whether to analyze code complexity TYPE: |
include_ownership | Whether to track code ownership TYPE: |
include_hotspots | Whether to detect code hotspots TYPE: |
include_patterns | File patterns to include (e.g., ['*.py']) |
exclude_patterns | File patterns to exclude (e.g., ['test_*']) |
max_files | Maximum number of files to analyze |
RETURNS | DESCRIPTION |
---|---|
ExaminationResult | Comprehensive examination findings TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If path doesn't exist or isn't a directory |
Example
examiner = Examiner(config) result = examiner.examine_project( ... Path("./src"), ... deep=True, ... include_git=True ... ) print(f"Health score: {result.health_score}")
examine_file¶
Examine a single file in detail.
Performs focused analysis on a single file, extracting all available metrics, complexity measures, and structural information.
PARAMETER | DESCRIPTION |
---|---|
file_path | Path to the file to examine TYPE: |
deep | Whether to perform deep AST-based analysis TYPE: |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dict[str, Any]: Detailed file examination results |
RAISES | DESCRIPTION |
---|---|
ValueError | If file doesn't exist or isn't a file |
Example
examiner = Examiner(config) result = examiner.examine_file(Path("main.py"), deep=True) print(f"Complexity: {result['complexity']}")
HotspotDetector¶
Detector for code hotspots.
Analyzes code repository to identify hotspots - areas that change frequently, have high complexity, or show other problematic patterns.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
git_analyzer | Git analyzer instance TYPE: |
Initialize hotspot detector.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
git_analyzerinstance-attribute
¶
Functions¶
detect¶
detect(repo_path: Path, files: Optional[List[Any]] = None, since_days: int = 90, threshold: int = 10, include_stable: bool = False) -> HotspotReport
Detect hotspots in a repository.
Analyzes git history and code metrics to identify problematic areas that need attention or refactoring.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
files | Optional list of analyzed file objects |
since_days | Days of history to analyze TYPE: |
threshold | Minimum score to consider as hotspot TYPE: |
include_stable | Whether to include stable files in report TYPE: |
RETURNS | DESCRIPTION |
---|---|
HotspotReport | Comprehensive hotspot analysis TYPE: |
Example
detector = HotspotDetector(config) report = detector.detect(Path("."), since_days=30) print(f"Found {report.total_hotspots} hotspots")
HotspotReportdataclass
¶
HotspotReport(total_files_analyzed: int = 0, total_hotspots: int = 0, critical_count: int = 0, high_count: int = 0, file_hotspots: List[FileHotspot] = list(), module_hotspots: List[ModuleHotspot] = list(), coupling_clusters: List[List[str]] = list(), temporal_patterns: Dict[str, Any] = dict(), hotspot_trends: Dict[str, Any] = dict(), top_problems: List[Tuple[str, int]] = list(), estimated_effort: float = 0.0, recommendations: List[str] = list(), risk_matrix: Dict[str, List[str]] = dict(), _health_score_override: Optional[float] = None)
Comprehensive hotspot analysis report.
Provides detailed insights into code hotspots, including problematic files, modules, trends, and recommendations for improvement.
ATTRIBUTE | DESCRIPTION |
---|---|
total_files_analyzed | Total files analyzed TYPE: |
total_hotspots | Total hotspots detected TYPE: |
critical_count | Number of critical hotspots TYPE: |
high_count | Number of high-risk hotspots TYPE: |
file_hotspots | List of file-level hotspots TYPE: |
module_hotspots | List of module-level hotspots TYPE: |
coupling_clusters | Groups of tightly coupled files |
temporal_patterns | Time-based patterns detected |
hotspot_trends | Trends in hotspot evolution |
top_problems | Most common problem types |
estimated_effort | Estimated effort to address hotspots TYPE: |
recommendations | Actionable recommendations |
risk_matrix | Risk assessment matrix |
Attributes¶
total_files_analyzedclass-attribute
instance-attribute
¶
total_hotspotsclass-attribute
instance-attribute
¶
critical_countclass-attribute
instance-attribute
¶
high_countclass-attribute
instance-attribute
¶
file_hotspotsclass-attribute
instance-attribute
¶
module_hotspotsclass-attribute
instance-attribute
¶
coupling_clustersclass-attribute
instance-attribute
¶
temporal_patternsclass-attribute
instance-attribute
¶
hotspot_trendsclass-attribute
instance-attribute
¶
top_problemsclass-attribute
instance-attribute
¶
estimated_effortclass-attribute
instance-attribute
¶
recommendationsclass-attribute
instance-attribute
¶
risk_matrixclass-attribute
instance-attribute
¶
health_scoreproperty
writable
¶
Calculate overall codebase health score.
Lower scores indicate more hotspots and problems.
RETURNS | DESCRIPTION |
---|---|
float | Health score (0-100) TYPE: |
Functions¶
MetricsCalculator¶
Calculator for code metrics extraction and aggregation.
Processes analyzed files to compute comprehensive metrics including size measurements, complexity statistics, quality indicators, and distributional analysis.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
Initialize metrics calculator with configuration.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance with metrics settings TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
Functions¶
calculate¶
Calculate comprehensive metrics for analyzed files.
Processes a list of analyzed file objects to extract and aggregate various code metrics, producing a complete metrics report.
PARAMETER | DESCRIPTION |
---|---|
files | List of analyzed file objects |
RETURNS | DESCRIPTION |
---|---|
MetricsReport | Comprehensive metrics analysis TYPE: |
Example
calculator = MetricsCalculator(config) report = calculator.calculate(analyzed_files) print(f"Average complexity: {report.avg_complexity}")
calculate_file_metrics¶
Calculate metrics for a single file.
Extracts detailed metrics from a single file analysis object, providing file-specific measurements and statistics.
PARAMETER | DESCRIPTION |
---|---|
file_analysis | Analyzed file object TYPE: |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dict[str, Any]: File-specific metrics |
Example
metrics = calculator.calculate_file_metrics(file_analysis) print(f"File complexity: {metrics['complexity']}")
MetricsReportdataclass
¶
MetricsReport(total_files: int = 0, total_lines: int = 0, total_blank_lines: int = 0, total_comment_lines: int = 0, total_code_lines: int = 0, total_functions: int = 0, total_classes: int = 0, total_imports: int = 0, avg_file_size: float = 0.0, avg_complexity: float = 0.0, max_complexity: float = 0.0, min_complexity: float = float('inf'), complexity_std_dev: float = 0.0, documentation_ratio: float = 0.0, test_coverage: float = 0.0, code_duplication_ratio: float = 0.0, technical_debt_score: float = 0.0, maintainability_index: float = 0.0, languages: Dict[str, Dict[str, Any]] = dict(), file_types: Dict[str, int] = dict(), size_distribution: Dict[str, int] = dict(), complexity_distribution: Dict[str, int] = dict(), largest_files: List[Dict[str, Any]] = list(), most_complex_files: List[Dict[str, Any]] = list(), most_imported_modules: List[Tuple[str, int]] = list())
Comprehensive metrics report for analyzed code.
Aggregates various code metrics to provide quantitative insights into codebase characteristics, including size, complexity, documentation, and quality indicators.
ATTRIBUTE | DESCRIPTION |
---|---|
total_files | Total number of files analyzed TYPE: |
total_lines | Total lines of code across all files TYPE: |
total_blank_lines | Total blank lines TYPE: |
total_comment_lines | Total comment lines TYPE: |
total_code_lines | Total actual code lines (excluding blanks/comments) TYPE: |
total_functions | Total number of functions/methods TYPE: |
total_classes | Total number of classes TYPE: |
total_imports | Total number of import statements TYPE: |
avg_file_size | Average file size in lines TYPE: |
avg_complexity | Average cyclomatic complexity TYPE: |
max_complexity | Maximum cyclomatic complexity found TYPE: |
min_complexity | Minimum cyclomatic complexity found TYPE: |
complexity_std_dev | Standard deviation of complexity TYPE: |
documentation_ratio | Ratio of comment lines to code lines TYPE: |
test_coverage | Estimated test coverage (if test files found) TYPE: |
languages | Dictionary of language-specific metrics |
file_types | Distribution of file types |
size_distribution | File size distribution buckets |
complexity_distribution | Complexity distribution buckets |
largest_files | List of largest files by line count |
most_complex_files | List of files with highest complexity |
most_imported_modules | Most frequently imported modules |
code_duplication_ratio | Estimated code duplication ratio TYPE: |
technical_debt_score | Calculated technical debt score TYPE: |
maintainability_index | Overall maintainability index TYPE: |
Attributes¶
total_filesclass-attribute
instance-attribute
¶
total_linesclass-attribute
instance-attribute
¶
total_blank_linesclass-attribute
instance-attribute
¶
total_comment_linesclass-attribute
instance-attribute
¶
total_code_linesclass-attribute
instance-attribute
¶
total_functionsclass-attribute
instance-attribute
¶
total_classesclass-attribute
instance-attribute
¶
total_importsclass-attribute
instance-attribute
¶
avg_file_sizeclass-attribute
instance-attribute
¶
avg_complexityclass-attribute
instance-attribute
¶
max_complexityclass-attribute
instance-attribute
¶
min_complexityclass-attribute
instance-attribute
¶
complexity_std_devclass-attribute
instance-attribute
¶
documentation_ratioclass-attribute
instance-attribute
¶
code_duplication_ratioclass-attribute
instance-attribute
¶
technical_debt_scoreclass-attribute
instance-attribute
¶
maintainability_indexclass-attribute
instance-attribute
¶
languagesclass-attribute
instance-attribute
¶
file_typesclass-attribute
instance-attribute
¶
size_distributionclass-attribute
instance-attribute
¶
complexity_distributionclass-attribute
instance-attribute
¶
largest_filesclass-attribute
instance-attribute
¶
most_complex_filesclass-attribute
instance-attribute
¶
most_imported_modulesclass-attribute
instance-attribute
¶
code_to_comment_ratioproperty
¶
Calculate code to comment ratio.
RETURNS | DESCRIPTION |
---|---|
float | Ratio of code lines to comment lines TYPE: |
avg_file_complexityproperty
¶
Calculate average complexity per file.
RETURNS | DESCRIPTION |
---|---|
float | Average complexity across all files TYPE: |
quality_scoreproperty
¶
Calculate overall code quality score (0-100).
Combines various metrics to produce a single quality indicator.
RETURNS | DESCRIPTION |
---|---|
float | Quality score between 0 and 100 TYPE: |
Functions¶
OwnershipReportdataclass
¶
OwnershipReport(total_contributors: int = 0, total_files_analyzed: int = 0, active_contributors: int = 0, contributors: List[ContributorInfo] = list(), file_ownership: Dict[str, FileOwnership] = dict(), orphaned_files: List[str] = list(), high_risk_files: List[Dict[str, Any]] = list(), knowledge_silos: List[Dict[str, Any]] = list(), bus_factor: int = 0, team_ownership: Optional[TeamOwnership] = None, ownership_distribution: Dict[str, float] = dict(), collaboration_graph: Dict[Tuple[str, str], int] = dict(), expertise_map: Dict[str, List[str]] = dict(), recommendations: List[str] = list(), risk_score: float = 0.0)
Comprehensive code ownership analysis report.
Provides detailed insights into code ownership patterns, knowledge distribution, bus factor risks, and team dynamics.
ATTRIBUTE | DESCRIPTION |
---|---|
total_contributors | Total number of contributors TYPE: |
active_contributors | Currently active contributors TYPE: |
contributors | List of contributor information TYPE: |
file_ownership | Ownership by file TYPE: |
orphaned_files | Files without active maintainers |
high_risk_files | Files with bus factor risks |
knowledge_silos | Areas with concentrated knowledge |
bus_factor | Overall project bus factor TYPE: |
team_ownership | Team-level ownership patterns TYPE: |
ownership_distribution | Distribution of ownership |
collaboration_graph | Collaboration relationships |
expertise_map | Map of expertise areas |
recommendations | Actionable recommendations |
risk_score | Overall ownership risk score TYPE: |
Attributes¶
total_contributorsclass-attribute
instance-attribute
¶
total_files_analyzedclass-attribute
instance-attribute
¶
active_contributorsclass-attribute
instance-attribute
¶
contributorsclass-attribute
instance-attribute
¶
file_ownershipclass-attribute
instance-attribute
¶
orphaned_filesclass-attribute
instance-attribute
¶
high_risk_filesclass-attribute
instance-attribute
¶
knowledge_silosclass-attribute
instance-attribute
¶
bus_factorclass-attribute
instance-attribute
¶
team_ownershipclass-attribute
instance-attribute
¶
ownership_distributionclass-attribute
instance-attribute
¶
collaboration_graphclass-attribute
instance-attribute
¶
expertise_mapclass-attribute
instance-attribute
¶
recommendationsclass-attribute
instance-attribute
¶
risk_scoreclass-attribute
instance-attribute
¶
health_scoreproperty
¶
Calculate ownership health score.
Higher scores indicate better knowledge distribution.
RETURNS | DESCRIPTION |
---|---|
float | Health score (0-100) TYPE: |
Functions¶
OwnershipTracker¶
Tracker for code ownership patterns.
Analyzes git history to understand code ownership, knowledge distribution, and collaboration patterns within a codebase.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
git_analyzer | Git analyzer instance TYPE: |
Initialize ownership tracker.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
git_analyzerinstance-attribute
¶
Functions¶
track¶
track(repo_path: Path, since_days: int = 365, include_tests: bool = True, team_mapping: Optional[Dict[str, List[str]]] = None) -> OwnershipReport
Track code ownership for a repository.
Analyzes git history to determine ownership patterns, identify risks, and provide insights into knowledge distribution.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
since_days | Days of history to analyze TYPE: |
include_tests | Whether to include test files TYPE: |
team_mapping | Optional mapping of team names to members |
RETURNS | DESCRIPTION |
---|---|
OwnershipReport | Comprehensive ownership analysis TYPE: |
Example
tracker = OwnershipTracker(config) report = tracker.track(Path("."), since_days=90) print(f"Bus factor: {report.bus_factor}")
analyze_ownership¶
Analyze ownership for a repository path.
This is an alias for the track() method to maintain backward compatibility.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to repository TYPE: |
**kwargs | Additional arguments passed to track() TYPE: |
RETURNS | DESCRIPTION |
---|---|
OwnershipReport | Comprehensive ownership analysis TYPE: |
Functions¶
examine_project¶
examine_project(path: Path, deep: bool = False, include_git: bool = True, include_metrics: bool = True, include_complexity: bool = True, include_ownership: bool = True, include_hotspots: bool = True, config: Optional[Any] = None) -> ExaminationResult
Examine a project comprehensively.
This is a convenience function that creates an Examiner instance and performs a full examination of the specified project.
PARAMETER | DESCRIPTION |
---|---|
path | Path to project directory TYPE: |
deep | Whether to perform deep analysis with AST parsing TYPE: |
include_git | Whether to include git analysis TYPE: |
include_metrics | Whether to calculate detailed metrics TYPE: |
include_complexity | Whether to analyze complexity TYPE: |
include_ownership | Whether to track code ownership TYPE: |
include_hotspots | Whether to detect hotspots TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
ExaminationResult | ExaminationResult with comprehensive analysis |
Example
from tenets.core.examiner import examine_project
results = examine_project( ... Path("./my_project"), ... deep=True, ... include_git=True ... )
Access various reports¶
print(f"Files analyzed: {results.total_files}") print(f"Languages: {results.languages}") print(f"Top complex files: {results.complexity.top_files}")
examine_file¶
examine_file(file_path: Path, deep: bool = False, config: Optional[Any] = None) -> Dict[str, Any]
Examine a single file.
Performs detailed analysis on a single file including complexity, metrics, and structure analysis.
PARAMETER | DESCRIPTION |
---|---|
file_path | Path to file TYPE: |
deep | Whether to perform deep analysis TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with file examination results |
Example
from tenets.core.examiner import examine_file
results = examine_file(Path("main.py"), deep=True) print(f"Complexity: {results['complexity']}") print(f"Lines: {results['lines']}")
calculate_metrics¶
Calculate metrics for a list of files.
PARAMETER | DESCRIPTION |
---|---|
files | List of FileAnalysis objects |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
MetricsReport | MetricsReport with calculated metrics |
Example
from tenets.core.examiner import calculate_metrics
metrics = calculate_metrics(analyzed_files) print(f"Total lines: {metrics.total_lines}") print(f"Average complexity: {metrics.avg_complexity}")
analyze_complexity¶
analyze_complexity(files: List[Any], threshold: int = 10, config: Optional[Any] = None) -> ComplexityReport
Analyze complexity patterns in files.
PARAMETER | DESCRIPTION |
---|---|
files | List of FileAnalysis objects |
threshold | Minimum complexity threshold TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
ComplexityReport | ComplexityReport with analysis results |
Example
from tenets.core.examiner import analyze_complexity
complexity = analyze_complexity(files, threshold=10) for file in complexity.high_complexity_files: print(f"{file.path}: {file.complexity}")
track_ownership¶
track_ownership(repo_path: Path, since_days: int = 90, config: Optional[Any] = None) -> OwnershipReport
Track code ownership patterns.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
since_days | Days to look back TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
OwnershipReport | OwnershipReport with ownership data |
Example
from tenets.core.examiner import track_ownership
ownership = track_ownership(Path("."), since_days=30) for author in ownership.top_contributors: print(f"{author.name}: {author.commits}")
detect_hotspots¶
detect_hotspots(repo_path: Path, files: Optional[List[Any]] = None, threshold: int = 5, config: Optional[Any] = None) -> HotspotReport
Detect code hotspots (frequently changed areas).
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
files | Optional list of FileAnalysis objects |
threshold | Minimum change count for hotspot TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
HotspotReport | HotspotReport with detected hotspots |
Example
from tenets.core.examiner import detect_hotspots
hotspots = detect_hotspots(Path("."), threshold=10) for hotspot in hotspots.files: print(f"{hotspot.path}: {hotspot.change_count} changes")
Modules¶
complexity
- Complexity moduleexaminer
- Examiner modulehotspots
- Hotspots modulemetrics
- Metrics moduleownership
- Ownership module