Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
417 changes: 113 additions & 304 deletions codegen-on-oss/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Returns:
NetworkX DiGraph representing the dependencies
"""
graph = nx.DiGraph()
graph: nx.DiGraph = nx.DiGraph()

for edge in edges:
source = edge.get("source")
Expand Down Expand Up @@ -65,14 +65,14 @@

for node in graph.nodes():
# Count both incoming and outgoing connections
connection_count = graph.in_degree(node) + graph.out_degree(node)

Check failure on line 68 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported left operand type for + ("DiDegreeView[Any]") [operator]

Check failure on line 68 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported operand types for + ("DiDegreeView[Any]" and "int") [operator]

Check failure on line 68 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported operand types for + ("int" and "DiDegreeView[Any]") [operator]

if connection_count >= threshold:
hubs.append(node)

# Sort by connection count in descending order
hubs.sort(
key=lambda node: graph.in_degree(node) + graph.out_degree(node), reverse=True

Check failure on line 75 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported left operand type for + ("DiDegreeView[Any]") [operator]

Check failure on line 75 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported operand types for + ("DiDegreeView[Any]" and "int") [operator]

Check failure on line 75 in codegen-on-oss/codegen_on_oss/analyzers/context/graph/__init__.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unsupported operand types for + ("int" and "DiDegreeView[Any]") [operator]
)

return hubs
Expand Down
5 changes: 4 additions & 1 deletion codegen-on-oss/codegen_on_oss/analyzers/diff_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ def from_git_diff(cls, git_diff: Diff) -> Self:
if git_diff.a_blob:
old = git_diff.a_blob.data_stream.read()

# Ensure path is never None
path = Path(git_diff.a_path) if git_diff.a_path else Path("")

return cls(
change_type=ChangeType.from_git_change_type(git_diff.change_type),
path=Path(git_diff.a_path) if git_diff.a_path else None,
path=path,
rename_from=Path(git_diff.rename_from) if git_diff.rename_from else None,
rename_to=Path(git_diff.rename_to) if git_diff.rename_to else None,
old_content=old,
Expand Down
18 changes: 9 additions & 9 deletions codegen-on-oss/codegen_on_oss/analyzers/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections.abc import Callable
from dataclasses import asdict, dataclass, field
from enum import Enum
from typing import Any
from typing import Any, Dict, List, Optional

# Configure logging
logging.basicConfig(
Expand Down Expand Up @@ -189,10 +189,10 @@
result["suggestion"] = self.suggestion

if self.related_symbols:
result["related_symbols"] = self.related_symbols
result["related_symbols"] = self.related_symbols # type: ignore

if self.related_locations:
result["related_locations"] = [
result["related_locations"] = [ # type: ignore
loc.to_dict() for loc in self.related_locations
]

Expand Down Expand Up @@ -242,7 +242,7 @@
issues: Initial list of issues
"""
self.issues = issues or []
self._filters = []
self._filters: list[tuple[Callable[[Issue], bool], str]] = []

def add_issue(self, issue: Issue):
"""
Expand Down Expand Up @@ -333,7 +333,7 @@
Returns:
Dictionary mapping severities to lists of issues
"""
result = {severity: [] for severity in IssueSeverity}
result: dict[IssueSeverity, list[Issue]] = {severity: [] for severity in IssueSeverity}

for issue in self.issues:
result[issue.severity].append(issue)
Expand All @@ -347,7 +347,7 @@
Returns:
Dictionary mapping categories to lists of issues
"""
result = {category: [] for category in IssueCategory}
result: dict[IssueCategory, list[Issue]] = {category: [] for category in IssueCategory}

for issue in self.issues:
if issue.category:
Expand All @@ -362,7 +362,7 @@
Returns:
Dictionary mapping file paths to lists of issues
"""
result = {}
result: dict[str, list[Issue]] = {}

for issue in self.issues:
if issue.location.file not in result:
Expand All @@ -381,7 +381,7 @@
"""
by_severity = self.group_by_severity()
by_category = self.group_by_category()
by_status = {status: [] for status in IssueStatus}
by_status: dict[IssueStatus, list[Issue]] = {status: [] for status in IssueStatus}
for issue in self.issues:
by_status[issue.status].append(issue)

Expand Down Expand Up @@ -506,7 +506,7 @@
message=message,
severity=severity,
location=location,
category=category,
category=category if category != "" else None, # type: ignore

Check failure on line 509 in codegen-on-oss/codegen_on_oss/analyzers/issues.py

View workflow job for this annotation

GitHub Actions / mypy

error: Unused "type: ignore" comment [unused-ignore]
symbol=symbol,
suggestion=suggestion,
)
22 changes: 22 additions & 0 deletions codegen-on-oss/codegen_on_oss/visualizers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Visualizers for codebase analysis.

This package contains visualizers for analyzing and visualizing different aspects
of a codebase, such as call graphs, dead code, and more.
"""

from codegen_on_oss.visualizers.call_graph_from_node import (
CallGraphFilter,
CallGraphFromNode,
CallPathsBetweenNodes,
)
from codegen_on_oss.visualizers.codebase_visualizer import CodebaseVisualizer
from codegen_on_oss.visualizers.dead_code import DeadCodeVisualizer

__all__ = [
"CodebaseVisualizer",
"CallGraphFromNode",
"CallGraphFilter",
"CallPathsBetweenNodes",
"DeadCodeVisualizer",
]

Loading
Loading