Skip to content

Commit 03d648d

Browse files
committed
introducing project class and some endpoints tests
1 parent 6f02ce4 commit 03d648d

20 files changed

+1171
-624
lines changed

app.py

Lines changed: 0 additions & 473 deletions
This file was deleted.

code_graph/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from .info import *
22
from .graph import *
3+
from .project import *
34
from .entities import *
45
from .git_utils import *
6+
from .app import create_app
57
from .code_coverage import *
68
from .analyzers.source_analyzer import *
7-
from. auto_complete import prefix_search
9+
from .auto_complete import prefix_search

code_graph/analyzers/c/analyzer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import io
2-
from typing import Union, Optional
3-
from pathlib import Path
2+
import os
43
from ..utils import *
4+
from pathlib import Path
55
from ...entities import *
66
from ...graph import Graph
7+
from typing import Union, Optional
78
from ..analyzer import AbstractAnalyzer
89

910
import tree_sitter_c as tsc
@@ -347,7 +348,7 @@ def first_pass(self, path: Path, f: io.TextIOWrapper, graph:Graph) -> None:
347348
logger.info(f"Processing {path}")
348349

349350
# Create file entity
350-
file = File(str(path.parent), path.name, path.suffix)
351+
file = File(os.path.dirname(path), path.name, path.suffix)
351352
graph.add_file(file)
352353

353354
# Parse file
@@ -416,7 +417,7 @@ def second_pass(self, path: Path, f: io.TextIOWrapper, graph: Graph) -> None:
416417
logger.info(f"Processing {path}")
417418

418419
# Get file entity
419-
file = graph.get_file(str(path.parent), path.name, path.suffix)
420+
file = graph.get_file(os.path.dirname(path), path.name, path.suffix)
420421
if file is None:
421422
logger.error(f"File entity not found for: {path}")
422423
return

code_graph/analyzers/python/analyzer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import io
2-
from typing import Union, Optional
3-
from pathlib import Path
2+
import os
43
from ..utils import *
4+
from pathlib import Path
55
from ...entities import *
66
from ...graph import Graph
7+
from typing import Union, Optional
78
from ..analyzer import AbstractAnalyzer
89

910
import tree_sitter_python as tspython
@@ -226,7 +227,7 @@ def first_pass(self, path: Path, f: io.TextIOWrapper, graph:Graph) -> None:
226227
logger.info(f"Python Processing {path}")
227228

228229
# Create file entity
229-
file = File(str(path.parent), path.name, path.suffix)
230+
file = File(os.path.dirname(path), path.name, path.suffix)
230231
graph.add_file(file)
231232

232233
# Parse file
@@ -367,7 +368,7 @@ def second_pass(self, path: Path, f: io.TextIOWrapper, graph: Graph) -> None:
367368
logger.info(f"Processing {path}")
368369

369370
# Get file entity
370-
file = graph.get_file(str(path.parent), path.name, path.suffix)
371+
file = graph.get_file(os.path.dirname(path), path.name, path.suffix)
371372
if file is None:
372373
logger.error(f"File entity not found for: {path}")
373374
return

code_graph/analyzers/source_analyzer.py

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import subprocess
43
import concurrent.futures
54

65
from git import Repo
@@ -20,6 +19,12 @@
2019
'.py': PythonAnalyzer()}
2120

2221
class SourceAnalyzer():
22+
23+
def supported_types(self) -> List[str]:
24+
"""
25+
"""
26+
return list(analyzers.keys())
27+
2328
def first_pass(self, ignore: List[str], executor: concurrent.futures.Executor) -> None:
2429
"""
2530
Perform the first pass analysis on source files in the given directory tree.
@@ -53,6 +58,7 @@ def first_pass(self, ignore: List[str], executor: concurrent.futures.Executor) -
5358
continue
5459

5560
logger.info(f'Processing file: {file_path}')
61+
print(f'Processing file: {file_path}')
5662

5763
def process_file(path: Path) -> None:
5864
with open(path, 'rb') as f:
@@ -111,6 +117,17 @@ def process_file(path: Path) -> None:
111117
# Wait for all tasks to complete
112118
concurrent.futures.wait(tasks)
113119

120+
def analyze_file(self, path: Path, graph: Graph) -> None:
121+
ext = path.suffix
122+
print(f"analyze_file: path: {path}")
123+
print(f"analyze_file: ext: {ext}")
124+
if ext not in analyzers:
125+
return
126+
127+
with open(path, 'rb') as f:
128+
analyzers[ext].first_pass(path, f, graph)
129+
analyzers[ext].second_pass(path, f, graph)
130+
114131
def analyze_sources(self, ignore: List[str]) -> None:
115132
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
116133
# First pass analysis of the source code
@@ -119,62 +136,9 @@ def analyze_sources(self, ignore: List[str]) -> None:
119136
# Second pass analysis of the source code
120137
self.second_pass(ignore, executor)
121138

122-
def analyze_github_repository(
123-
self,
124-
url: str,
125-
repo_path: Path,
126-
repo_name: str,
127-
ignore: Optional[List[str]] = []
128-
) -> None:
139+
def analyze(self, path: str, g: Graph, ignore: Optional[List[str]] = []) -> None:
129140
"""
130-
Analyze a Git repository given its URL.
131-
132-
Args:
133-
url: The URL of the Git repository to analyze
134-
ignore_patterns: List of patterns to ignore during analysis
135-
136-
Raises:
137-
subprocess.SubprocessError: If git clone fails
138-
OSError: If there are filesystem operation errors
139-
"""
140-
141-
# Extract repository name more reliably
142-
# Delete local repository if exists
143-
if repo_path.exists():
144-
shutil.rmtree(repo_path)
145-
146-
# Create directory
147-
repo_path.mkdir(parents=True, exist_ok=True)
148-
149-
# Clone repository
150-
# Prepare the git clone command
151-
command = ["git", "clone", url, repo_path]
152-
153-
# Run the git clone command and wait for it to finish
154-
result = subprocess.run(command, check=True, capture_output=True, text=True)
155-
156-
# Store original working directory
157-
original_dir = Path.cwd()
158-
159-
# change working directory to local repository
160-
os.chdir(repo_path)
161-
162-
try:
163-
# Initialize the graph and analyzer
164-
self.graph = Graph(repo_name)
165-
166-
# Analyze repository
167-
self.analyze_sources(ignore)
168-
169-
logging.info(f"Successfully processed repository: {repo_name}")
170-
171-
finally:
172-
# Ensure we always return to the original directory
173-
os.chdir(original_dir)
174-
175-
def analyze_local_folder(self, path: str, ignore: Optional[List[str]] = []) -> Graph:
176-
"""
177-
Analyze a local folder.
141+
Analyze path.
178142
179143
Args:
180144
path (str): Path to a local folder containing source files to process
@@ -184,18 +148,13 @@ def analyze_local_folder(self, path: str, ignore: Optional[List[str]] = []) -> G
184148
# change working directory to path
185149
os.chdir(path)
186150

187-
proj_name = os.path.split(os.path.normpath(path))[-1]
188-
logger.debug(f'proj_name: {proj_name}')
189-
190151
# Initialize the graph and analyzer
191-
self.graph = Graph(proj_name)
152+
self.graph = g
192153

193154
# Analyze source files
194155
self.analyze_sources(ignore)
195156

196-
logger.info("Done processing folder")
197-
198-
return self.graph
157+
logger.info("Done analyzing path")
199158

200159
def analyze_local_repository(self, path: str, ignore: Optional[List[str]] = []) -> Graph:
201160
"""

0 commit comments

Comments
 (0)