Skip to content

Commit d021576

Browse files
authored
Merge pull request #35 from FalkorDB/process-local-dir
Process local folder
2 parents 8d450ff + 49c2f16 commit d021576

File tree

4 files changed

+118
-75
lines changed

4 files changed

+118
-75
lines changed

.gitignore

Lines changed: 31 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,44 @@
1-
# Python
1+
# Byte-compiled files
22
*.pyc
33
*.pyo
44
*.pyd
55
__pycache__/
6-
*.env
7-
.venv/
8-
env/
9-
venv/
10-
ENV/
11-
*.egg-info/
12-
*.egg
13-
pip-log.txt
14-
15-
# Flask
16-
instance/
17-
*.sqlite3
18-
*.db
19-
*.bak
20-
instance/config.py
21-
instance/*.secret
22-
23-
# Environment Variables
24-
.env
25-
.env.*
266

27-
# Logs
28-
logs/
29-
*.log
30-
*.out
31-
*.err
7+
# Virtual environments
8+
venv/
9+
env/
10+
.virtualenv/
3211

33-
# Pytest and Coverage
34-
.pytest_cache/
35-
.coverage
36-
.tox/
37-
nosetests.xml
38-
coverage.xml
39-
*.cover
40-
.cache
12+
# Distribution/build files
13+
build/
14+
dist/
15+
*.egg-info/
16+
.eggs/
4117

42-
# IDEs and Editors
18+
# IDE settings
4319
.vscode/
44-
.idea/.env
45-
.vercel
46-
47-
# ignore the .pyc files
48-
*.pyc
49-
50-
dist/
51-
# Node (if using npm/yarn for assets)
52-
node_modules/
53-
*.lock
20+
.idea/
21+
*.swp
5422

55-
# Static assets (if generated)
56-
static/
57-
dist/
58-
build/
23+
# Logs and debugging
24+
*.log
25+
*.trace
5926

60-
# Docker
61-
*.pid
62-
docker-compose.override.yml
27+
# OS-specific files
28+
.DS_Store
29+
Thumbs.db
6330

64-
# Heroku
65-
*.buildpacks
66-
*.env.local
67-
*.env.production
68-
*.env.*.local
31+
# Testing and coverage
32+
htmlcov/
33+
*.cover
34+
.coverage
35+
.cache/
36+
pytest_cache/
6937

70-
# Miscellaneous
71-
*.bak
72-
*.tmp
73-
*.log.*
74-
Thumbs.db
38+
# Jupyter Notebook checkpoints
39+
.ipynb_checkpoints/
7540

76-
# Vercel
77-
.vercel
41+
# Custom settings
42+
.env
43+
*.sqlite3
44+
.vercel

README.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,44 @@
55
## Getting Started
66
[Live Demo](https://code-graph.falkordb.com/)
77

8+
## Running locally
89

10+
### Run FalkorDB
11+
Free cloud instance: https://app.falkordb.cloud/signup
12+
13+
Or by running locally with docker:
914
```bash
10-
flask --app code_graph run --debug
15+
docker run -p 6379:6379 -p 3000:3000 -it --rm falkordb/falkordb:latest
1116
```
1217

13-
Process local git repository, ignoring specific folder(s)
18+
### Config
19+
Create your own `.env` file from the `.env.template` file
1420

21+
Start the server:
1522
```bash
16-
curl -X POST http://127.0.0.1:5000/process_local_repo -H "Content-Type: application/json" -d '{"repo": "/Users/roilipman/Dev/FalkorDB", "ignore": ["./.github", "./sbin", "./.git","./deps", "./bin", "./build"]}'
23+
flask --app api/index.py run --debug
1724
```
1825

19-
Process code coverage
20-
26+
### Creating a graph
27+
Process a local source folder:
2128
```bash
22-
curl -X POST http://127.0.0.1:5000/process_code_coverage -H "Content-Type: application/json" -d '{"lcov": "/Users/roilipman/Dev/code_graph/code_graph/code_coverage/lcov/falkordb.lcov", "repo": "FalkorDB"}'
29+
curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "<FULL_PATH_TO_FOLDER>", "ignore": [<OPTIONAL_IGNORE_LIST>]}' -H "Authorization: <.ENV_SECRET_TOKEN>"
2330
```
2431

25-
Process git information
26-
32+
For example:
2733
```bash
28-
curl -X POST http://127.0.0.1:5000/process_git_history -H "Content-Type: application/json" -d '{"repo": "/Users/roilipman/Dev/falkorDB"}'
34+
curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "/Users/roilipman/Dev/GraphRAG-SDK", "ignore": ["./.github", "./build"]}' -H "Authorization: OpenSesame"
2935
```
36+
## Working with your graph
37+
Once the source code analysis completes your FalkorDB DB will be populated with
38+
a graph representation of your source code, the graph name should be the same as
39+
the name of the folder you've requested to analyze, for the example above a graph named:
40+
"GraphRAG-SDK".
41+
42+
At the moment only the Python and C languages are supported, we do intend to support additional languages.
43+
44+
At this point you can explore and query your source code using various tools
45+
Here are several options:
46+
1. FalkorDB built-in UI
47+
2. One of FalkorDB's [clients](https://docs.falkordb.com/clients.html)
48+
3. Use FalkorDB [GraphRAG-SDK](https://github.com/FalkorDB/GraphRAG-SDK) to connect an LLM for natural language exploration.

api/analyzers/source_analyzer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def analyze_sources(self, ignore: List[str]) -> None:
135135
# Second pass analysis of the source code
136136
self.second_pass(ignore, executor)
137137

138-
def analyze(self, path: str, g: Graph, ignore: Optional[List[str]] = []) -> None:
138+
def analyze_local_folder(self, path: str, g: Graph, ignore: Optional[List[str]] = []) -> None:
139139
"""
140140
Analyze path.
141141
@@ -144,6 +144,8 @@ def analyze(self, path: str, g: Graph, ignore: Optional[List[str]] = []) -> None
144144
ignore (List(str)): List of paths to skip
145145
"""
146146

147+
logging.info(f"Analyzing local folder {path}")
148+
147149
# Save original working directory for later restore
148150
original_dir = Path.cwd()
149151

@@ -179,4 +181,4 @@ def analyze_local_repository(self, path: str, ignore: Optional[List[str]] = [])
179181
self.graph.set_graph_commit(head.hexsha)
180182

181183
return self.graph
182-
184+

api/index.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import datetime
33
from api import *
4+
from pathlib import Path
45
from typing import Optional
56
from functools import wraps
67
from falkordb import FalkorDB
@@ -309,3 +310,57 @@ def chat():
309310
response = { 'status': 'success', 'response': answer }
310311

311312
return jsonify(response), 200
313+
314+
@app.route('/analyze_folder', methods=['POST'])
315+
@token_required # Apply token authentication decorator
316+
def analyze_folder():
317+
"""
318+
Endpoint to analyze local source code
319+
Expects 'path' and optionally an ignore list.
320+
321+
Returns:
322+
JSON response with status and error message if applicable
323+
Status codes:
324+
200: Success
325+
400: Invalid input
326+
500: Internal server error
327+
"""
328+
329+
# Get JSON data from the request
330+
data = request.get_json()
331+
332+
# Get query parameters
333+
path = data.get('path')
334+
ignore = data.get('ignore', [])
335+
336+
# Validate input parameters
337+
if not path:
338+
logging.error("'path' is missing from the request.")
339+
return jsonify({"status": "'path' is required."}), 400
340+
341+
# Validate path exists and is a directory
342+
if not os.path.isdir(path):
343+
logging.error(f"Path '{path}' does not exist or is not a directory")
344+
return jsonify({"status": "Invalid path: must be an existing directory"}), 400
345+
346+
# Validate ignore list contains valid paths
347+
if not isinstance(ignore, list):
348+
logging.error("'ignore' must be a list of paths")
349+
return jsonify({"status": "'ignore' must be a list of paths"}), 400
350+
351+
proj_name = Path(path).name
352+
353+
# Initialize the graph with the provided project name
354+
g = Graph(proj_name)
355+
356+
# Analyze source code within given folder
357+
analyzer = SourceAnalyzer()
358+
analyzer.analyze_local_folder(path, g, ignore)
359+
360+
# Return response
361+
response = {
362+
'status': 'success',
363+
'project': proj_name
364+
}
365+
return jsonify(response), 200
366+

0 commit comments

Comments
 (0)