Skip to content

Commit b34b7f4

Browse files
refactor: refactor codebase to unify server module and update file paths (#142)
* Refactor project into a dedicated 'server' module and update all references accordingly --------- Co-authored-by: Romain Courtois <[email protected]>
1 parent 58dbe2c commit b34b7f4

27 files changed

+102
-104
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ Thanks for your interest in contributing to Gitingest! 🚀 Gitingest aims to be
4848
pytest
4949
```
5050

51-
8. Run the app locally using Docker to test your changes (optional):
51+
8. Navigate to src folder
5252

5353
1. Build the Docker image
5454

5555
``` bash
56-
docker build -t gitingest .
56+
cd src
5757
```
5858

59-
2. Run the Docker container:
59+
2. Run the local web server:
6060

6161
``` bash
62-
docker run -d --name gitingest -p 8000:8000 gitingest
62+
uvicorn server.main:app
6363
```
6464

6565
3. Open your browser and navigate to `http://localhost:8000` to see the app running.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ USER appuser
4141

4242
EXPOSE 8000
4343

44-
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
44+
CMD ["python", "-m", "uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "8000"]

src/gitingest/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import click
88

9-
from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH
9+
from gitingest.config import MAX_FILE_SIZE, OUTPUT_FILE_PATH
1010
from gitingest.repository_ingest import ingest
1111

1212

src/gitingest/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
""" Configuration file for the project. """
2+
3+
from pathlib import Path
4+
5+
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10 MB
6+
MAX_DIRECTORY_DEPTH = 20 # Maximum depth of directory traversal
7+
MAX_FILES = 10_000 # Maximum number of files to process
8+
MAX_TOTAL_SIZE_BYTES = 500 * 1024 * 1024 # 500 MB
9+
10+
OUTPUT_FILE_PATH = "digest.txt"
11+
TMP_BASE_PATH = Path("/tmp/gitingest")

src/gitingest/query_ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import tiktoken
88

9-
from config import MAX_DIRECTORY_DEPTH, MAX_FILES, MAX_TOTAL_SIZE_BYTES
9+
from gitingest.config import MAX_DIRECTORY_DEPTH, MAX_FILES, MAX_TOTAL_SIZE_BYTES
1010
from gitingest.exceptions import (
1111
AlreadyVisitedError,
1212
InvalidNotebookError,

src/gitingest/query_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010
from urllib.parse import unquote, urlparse
1111

12-
from config import MAX_FILE_SIZE, TMP_BASE_PATH
12+
from gitingest.config import MAX_FILE_SIZE, TMP_BASE_PATH
1313
from gitingest.exceptions import InvalidPatternError
1414
from gitingest.ignore_patterns import DEFAULT_IGNORE_PATTERNS
1515
from gitingest.repository_clone import _check_repo_exists, fetch_remote_branch_list
@@ -163,7 +163,7 @@ async def _parse_repo_source(source: str) -> ParsedQuery:
163163

164164
_id = str(uuid.uuid4())
165165
slug = f"{user_name}-{repo_name}"
166-
local_path = Path(TMP_BASE_PATH) / _id / slug
166+
local_path = TMP_BASE_PATH / _id / slug
167167
url = f"https://{host}/{user_name}/{repo_name}"
168168

169169
parsed = ParsedQuery(

src/gitingest/repository_ingest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
import shutil
66

7-
from config import TMP_BASE_PATH
7+
from gitingest.config import TMP_BASE_PATH
88
from gitingest.query_ingestion import run_ingest_query
99
from gitingest.query_parser import ParsedQuery, parse_query
1010
from gitingest.repository_clone import CloneConfig, clone_repo

src/routers/__init__.py

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

src/server/__init__.py

Whitespace-only changes.

src/main.py renamed to src/server/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
from slowapi.errors import RateLimitExceeded
1111
from starlette.middleware.trustedhost import TrustedHostMiddleware
1212

13-
from config import templates
14-
from routers import download, dynamic, index
15-
from server_utils import limiter
16-
from utils import lifespan, rate_limit_exception_handler
13+
from server.routers import download, dynamic, index
14+
from server.server_config import templates
15+
from server.server_utils import lifespan, limiter, rate_limit_exception_handler
1716

1817
# Load environment variables from .env file
1918
load_dotenv()

0 commit comments

Comments
 (0)