Skip to content

Commit 60b9f89

Browse files
committed
fix: resolve all pre-commit hook issues and lint warnings
1 parent 50d5b0f commit 60b9f89

File tree

11 files changed

+132
-89
lines changed

11 files changed

+132
-89
lines changed

src/gitingest/entrypoint.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from types import TracebackType
2929

3030
from gitingest.schemas import IngestionQuery
31-
from gitingest.schemas import ContextV1
3231

3332
# Initialize logger for this module
3433
logger = get_logger(__name__)
@@ -138,7 +137,6 @@ async def ingest_async(
138137
_apply_gitignores(query)
139138

140139
logger.info("Processing files and generating output")
141-
summary, tree, content = ingest_query(query)
142140

143141
if output:
144142
logger.debug("Writing output to file", extra={"output_path": output})
@@ -205,19 +203,20 @@ def ingest(
205203
``ingest_async`` : The asynchronous version of this function.
206204
207205
"""
208-
digest = asyncio.run(ingest_async(
209-
source,
210-
max_file_size=max_file_size,
211-
include_patterns=include_patterns,
212-
exclude_patterns=exclude_patterns,
213-
branch=branch,
214-
tag=tag,
215-
include_gitignored=include_gitignored,
216-
include_submodules=include_submodules,
217-
token=token,
218-
output=output,
219-
))
220-
return digest
206+
return asyncio.run(
207+
ingest_async(
208+
source,
209+
max_file_size=max_file_size,
210+
include_patterns=include_patterns,
211+
exclude_patterns=exclude_patterns,
212+
branch=branch,
213+
tag=tag,
214+
include_gitignored=include_gitignored,
215+
include_submodules=include_submodules,
216+
token=token,
217+
output=output,
218+
),
219+
)
221220

222221

223222
def _override_branch_and_tag(query: IngestionQuery, branch: str | None, tag: str | None) -> None:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{ SEPARATOR }}
22
DEBUG: {{ class_name }}
33
Fields: {{ fields_str }}
4-
{{ SEPARATOR }}
4+
{{ SEPARATOR }}

src/gitingest/format/DefaultFormatter/FileSystemDirectory.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
{% endif -%}
55
{%- for child in node.children -%}
66
{{ formatter.format(child, query) }}
7-
{%- endfor -%}
7+
{%- endfor -%}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{ SEPARATOR }}
22
{{ node.name }}
33
{{ SEPARATOR }}
4-
{{ node.content }}
4+
{{ node.content }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{ SEPARATOR }}
22
{{ node.name }}{% if node.target %} -> {{ node.target }}{% endif %}
3-
{{ SEPARATOR }}
3+
{{ SEPARATOR }}

src/gitingest/format/DefaultFormatter/GitRepository.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
{% endif -%}
55
{%- for child in node.children -%}
66
{{ formatter.format(child, query) }}
7-
{%- endfor -%}
7+
{%- endfor -%}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Directory structure:
2-
{{ node.tree }}
2+
{{ node.tree }}

src/gitingest/ingestion.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ def _is_git_repository(path: Path) -> bool:
2626
def ingest_query(query: IngestionQuery) -> ContextV1:
2727
"""Run the ingestion process for a parsed query.
2828
29-
This is the main entry point for analyzing a codebase directory or single file. It processes the query
30-
parameters, reads the file or directory content, and returns a ContextV1 object that can generate the final output digest on demand.
29+
This is the main entry point for analyzing a codebase directory or single file.
30+
31+
It processes the query parameters, reads the file or directory content, and returns
32+
a ContextV1 object that can generate the final output digest on demand.
3133
3234
Parameters
3335
----------
@@ -37,7 +39,9 @@ def ingest_query(query: IngestionQuery) -> ContextV1:
3739
Returns
3840
-------
3941
ContextV1
40-
A ContextV1 object representing the ingested file system nodes. Use generate_digest(context) to get the summary, directory structure, and file contents.
42+
A ContextV1 object representing the ingested file system nodes.
43+
Use generate_digest(context) to get the summary, directory structure,
44+
and file contents.
4145
4246
Raises
4347
------
@@ -126,7 +130,7 @@ def ingest_query(query: IngestionQuery) -> ContextV1:
126130
return ContextV1([root_node], query)
127131

128132

129-
def _process_node(node: FileSystemNode, query: IngestionQuery, stats: FileSystemStats) -> None:
133+
def _process_node(node: FileSystemNode, query: IngestionQuery, stats: FileSystemStats) -> None: # noqa: C901
130134
"""Process a file or directory item within a directory.
131135
132136
This function handles each file or directory item, checking if it should be included or excluded based on the

src/server/query_processor.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from gitingest.clone import clone_repo
1010
from gitingest.ingestion import ingest_query
11-
from gitingest.output_formatter import DebugFormatter, DefaultFormatter, SummaryFormatter
11+
from gitingest.output_formatter import DefaultFormatter, SummaryFormatter, generate_digest
1212
from gitingest.query_parser import parse_remote_repo
1313
from gitingest.utils.git_utils import resolve_commit, validate_github_token
1414
from gitingest.utils.logging_config import get_logger
@@ -23,7 +23,6 @@
2323
upload_metadata_to_s3,
2424
upload_to_s3,
2525
)
26-
from gitingest.schemas import ContextV1
2726
from server.server_config import MAX_DISPLAY_SIZE
2827

2928
# Initialize logger for this module
@@ -314,17 +313,18 @@ async def process_query(
314313
source=query.url,
315314
user_name=cast("str", query.user_name),
316315
repo_name=cast("str", query.repo_name),
316+
subpath=query.subpath,
317317
commit=query.commit,
318318
include_patterns=query.include_patterns,
319319
ignore_patterns=query.ignore_patterns,
320320
)
321-
s3_url = upload_to_s3(content=context.digest, s3_file_path=s3_file_path, ingest_id=query.id)
321+
s3_url = upload_to_s3(content=generate_digest(context), s3_file_path=s3_file_path, ingest_id=query.id)
322322
# Store S3 URL in query for later use
323323
query.s3_url = s3_url
324324
else:
325325
# Store locally
326326
local_txt_file = Path(clone_config.local_path).with_suffix(".txt")
327-
print(f"Writing to {local_txt_file}")
327+
logger.info("Writing digest to local file", extra={"file_path": str(local_txt_file)})
328328
with local_txt_file.open("w", encoding="utf-8") as f:
329329
f.write(digest)
330330

@@ -340,14 +340,6 @@ async def process_query(
340340
"download full ingest to see more)\n" + digest[:MAX_DISPLAY_SIZE]
341341
)
342342

343-
# _print_success(
344-
# url=query.url,
345-
# max_file_size=max_file_size,
346-
# pattern_type=pattern_type,
347-
# pattern=pattern,
348-
# summary=digest,
349-
# )
350-
351343
digest_url = _generate_digest_url(query)
352344

353345
# Clean up the repository after successful processing
@@ -358,7 +350,7 @@ async def process_query(
358350
short_repo_url=short_repo_url,
359351
summary=summary,
360352
digest_url=digest_url,
361-
tree=context.sources[0].tree, # TODO: this is a hack to get the tree of the first source
353+
tree=context.sources[0].tree, # TODO: this is a hack to get the tree of the first source
362354
content=digest,
363355
default_max_file_size=max_file_size,
364356
pattern_type=pattern_type,

src/server/routers_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
from fastapi import status
99
from fastapi.responses import JSONResponse
1010

11+
from gitingest.utils.logging_config import get_logger
1112
from server.models import IngestErrorResponse, IngestSuccessResponse, PatternType
1213
from server.query_processor import process_query
1314

15+
# Initialize logger for this module
16+
logger = get_logger(__name__)
17+
1418
COMMON_INGEST_RESPONSES: dict[int | str, dict[str, Any]] = {
1519
status.HTTP_200_OK: {"model": IngestSuccessResponse, "description": "Successful ingestion"},
1620
status.HTTP_400_BAD_REQUEST: {"model": IngestErrorResponse, "description": "Bad request or processing error"},
@@ -41,8 +45,8 @@ async def _perform_ingestion(
4145
)
4246

4347
if isinstance(result, IngestErrorResponse):
44-
# print stack trace to console for debugging
45-
print(traceback.format_exc())
48+
# Log stack trace for debugging
49+
logger.error("Ingest processing failed", extra={"traceback": traceback.format_exc()})
4650
# Return structured error response with 400 status code
4751
return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, content=result.model_dump())
4852

@@ -52,13 +56,13 @@ async def _perform_ingestion(
5256
except ValueError as ve:
5357
# Handle validation errors with 400 status code
5458
error_response = IngestErrorResponse(error=f"Validation error: {ve!s}")
55-
# print stack trace to console for debugging
56-
print(traceback.format_exc())
59+
# Log stack trace for debugging
60+
logger.exception("Validation error during ingest", extra={"error": str(ve)})
5761
return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, content=error_response.model_dump())
5862

5963
except Exception as exc:
6064
# Handle unexpected errors with 500 status code
6165
error_response = IngestErrorResponse(error=f"Internal server error: {exc!s}")
62-
# print stack trace to console for debugging
63-
print(traceback.format_exc())
66+
# Log stack trace for debugging
67+
logger.exception("Unexpected error during ingest", extra={"error": str(exc)})
6468
return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=error_response.model_dump())

0 commit comments

Comments
 (0)