Skip to content

style: Pylint fixes #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length = 88
extend-ignore = E501
exclude = .venv, frontend
ignore = E203, W503, G004, G200
ignore = E203, W503, G004, G200,B008,ANN,D100,D101,D102,D103,D104,D105,D106,D107
30 changes: 16 additions & 14 deletions src/backend/api/api_routes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""FastAPI API routes for file processing and conversion"""
"""FastAPI API routes for file processing and conversion."""

import asyncio
import io
import zipfile

from api.auth.auth_utils import get_authenticated_user
from api.status_updates import app_connection_manager, close_connection

from common.logger.app_logger import AppLogger
from common.services.batch_service import BatchService

from fastapi import (
APIRouter,
File,
Expand All @@ -24,13 +26,14 @@
logger = AppLogger("APIRoutes")

# start processing the batch
from sql_agents_start import process_batch_async
from sql_agents_start import process_batch_async # noqa: E402


@router.post("/start-processing")
async def start_processing(request: Request):
"""
Start processing files for a given batch
Start processing files for a given batch.

---
tags:
- File Processing
Expand All @@ -50,6 +53,7 @@ async def start_processing(request: Request):
responses:
200:
description: Processing initiated successfully

content:
application/json:
schema:
Expand All @@ -61,6 +65,7 @@ async def start_processing(request: Request):
type: string
400:
description: Invalid processing request

500:
description: Internal server error
"""
Expand Down Expand Up @@ -89,7 +94,7 @@ async def start_processing(request: Request):
)
async def download_files(batch_id: str):
"""
Download files as ZIP
Download files as ZIP.

---
tags:
Expand Down Expand Up @@ -118,7 +123,6 @@ async def download_files(batch_id: str):
type: string
example: Batch not found
"""

# call batch_service get_batch_for_zip to get all files for batch_id
batch_service = BatchService()
await batch_service.initialize_database()
Expand Down Expand Up @@ -172,7 +176,7 @@ async def batch_status_updates(
websocket: WebSocket, batch_id: str
): # , request: Request):
"""
WebSocket endpoint for real-time batch status updates
Web-Socket endpoint for real-time batch status updates.

---
tags:
Expand Down Expand Up @@ -248,7 +252,7 @@ async def batch_status_updates(
@router.get("/batch-story/{batch_id}")
async def get_batch_status(request: Request, batch_id: str):
"""
Retrieve batch history and file statuses
Retrieve batch history and file statuses.

---
tags:
Expand Down Expand Up @@ -371,9 +375,7 @@ async def get_batch_status(request: Request, batch_id: str):

@router.get("/batch-summary/{batch_id}")
async def get_batch_summary(request: Request, batch_id: str):
"""
Retrieve batch summary for a given batch ID.
"""
"""Retrieve batch summary for a given batch ID."""
try:
batch_service = BatchService()
await batch_service.initialize_database()
Expand Down Expand Up @@ -404,7 +406,7 @@ async def upload_file(
request: Request, file: UploadFile = File(...), batch_id: str = Form(...)
):
"""
Upload file for conversion
Upload file for conversion.

---
tags:
Expand Down Expand Up @@ -634,7 +636,7 @@ async def get_file_details(request: Request, file_id: str):
@router.delete("/delete-batch/{batch_id}")
async def delete_batch_details(request: Request, batch_id: str):
"""
delete batch history using batch_id
Delete batch history using batch_id.

---
tags:
Expand Down Expand Up @@ -689,7 +691,7 @@ async def delete_batch_details(request: Request, batch_id: str):
@router.delete("/delete-file/{file_id}")
async def delete_file_details(request: Request, file_id: str):
"""
delete file history using batch_id
Delete file history using batch_id.

---
tags:
Expand Down Expand Up @@ -747,7 +749,7 @@ async def delete_file_details(request: Request, file_id: str):
@router.delete("/delete_all")
async def delete_all_details(request: Request):
"""
delete all the history of batches, files and logs
Delete all the history of batches, files and logs.

---
tags:
Expand Down
12 changes: 7 additions & 5 deletions src/backend/api/auth/auth_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from fastapi import Request, HTTPException
import logging
import base64
import json
import logging
from typing import Dict

from api.auth.sample_user import sample_user

from fastapi import HTTPException, Request

logger = logging.getLogger(__name__)


Expand All @@ -26,19 +28,19 @@ def __init__(self, user_details: Dict):


def get_tenant_id(client_principal_b64: str) -> str:
"""Extract tenant ID from base64 encoded client principal"""
"""Extract tenant ID from base64 encoded client principal."""
try:
decoded_bytes = base64.b64decode(client_principal_b64)
decoded_string = decoded_bytes.decode("utf-8")
user_info = json.loads(decoded_string)
return user_info.get("tid", "")
except Exception as ex:
except Exception :
logger.exception("Error decoding client principal")
return ""


def get_authenticated_user(request: Request) -> UserDetails:
"""Get authenticated user details from request headers"""
"""Get authenticated user details from request headers."""
user_object = {}
headers = dict(request.headers)
# Check if we're in production with real headers
Expand Down
2 changes: 1 addition & 1 deletion src/backend/api/auth/sample_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"x-ms-client-principal-idp": "aad",
"x-ms-token-aad-id-token": "dev.token",
"x-ms-client-principal": "your_base_64_encoded_token"
}
}
2 changes: 2 additions & 0 deletions src/backend/api/status_updates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Holds collection of websocket connections.

from clients registering for status updates.
These socket references are used to send updates to
registered clients from the backend processing code.
Expand All @@ -11,6 +12,7 @@
from typing import Dict

from common.models.api import FileProcessUpdate, FileProcessUpdateJSONEncoder

from fastapi import WebSocket

logger = logging.getLogger(__name__)
Expand Down
14 changes: 7 additions & 7 deletions src/backend/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import uvicorn

# Import our route modules
"""Create and configure the FastAPI application."""
from api.api_routes import router as backend_router

from common.logger.app_logger import AppLogger

from dotenv import load_dotenv

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

import uvicorn
# from agent_services.agents_routes import router as agents_router

# Load environment variables
Expand All @@ -17,9 +19,7 @@


def create_app() -> FastAPI:
"""
Factory function to create and configure the FastAPI application
"""
"""Create and return the FastAPI application instance."""
app = FastAPI(title="Code Gen Accelerator", version="1.0.0")

# Configure CORS
Expand All @@ -37,7 +37,7 @@ def create_app() -> FastAPI:

@app.get("/health")
async def health_check():
"""Health check endpoint"""
"""Health check endpoint."""
return {"status": "healthy"}

return app
Expand Down
1 change: 1 addition & 0 deletions src/backend/common/config/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from azure.identity.aio import ClientSecretCredential, DefaultAzureCredential

from dotenv import load_dotenv

load_dotenv()
Expand Down
16 changes: 8 additions & 8 deletions src/backend/common/database/cosmosdb.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from datetime import datetime, timezone
from enum import Enum
from typing import Dict, List, Optional
from uuid import UUID, uuid4

from azure.cosmos import PartitionKey, exceptions
from azure.cosmos.aio import CosmosClient
from azure.cosmos.aio._database import DatabaseProxy
from azure.cosmos.exceptions import (
CosmosResourceExistsError,
CosmosResourceNotFoundError,
CosmosResourceExistsError
)

from common.database.database_base import DatabaseBase
from common.logger.app_logger import AppLogger
from common.models.api import (
Expand All @@ -20,6 +19,7 @@
LogType,
ProcessStatus,
)

from semantic_kernel.contents import AuthorRole


Expand Down Expand Up @@ -208,7 +208,7 @@ async def get_batch_files(self, batch_id: str) -> List[Dict]:
raise

async def get_batch_from_id(self, batch_id: str) -> Dict:
"""Retrieve a batch from the database using the batch ID"""
"""Retrieve a batch from the database using the batch ID."""
try:
query = "SELECT * FROM c WHERE c.batch_id = @batch_id"
params = [{"name": "@batch_id", "value": batch_id}]
Expand All @@ -225,7 +225,7 @@ async def get_batch_from_id(self, batch_id: str) -> Dict:
raise

async def get_user_batches(self, user_id: str) -> Dict:
"""Retrieve all batches for a given user"""
"""Retrieve all batches for a given user."""
try:
query = "SELECT * FROM c WHERE c.user_id = @user_id"
params = [{"name": "@user_id", "value": user_id}]
Expand All @@ -242,7 +242,7 @@ async def get_user_batches(self, user_id: str) -> Dict:
raise

async def get_file_logs(self, file_id: str) -> List[Dict]:
"""Retrieve all logs for a given file"""
"""Retrieve all logs for a given file."""
try:
query = (
"SELECT * FROM c WHERE c.file_id = @file_id ORDER BY c.timestamp DESC"
Expand Down Expand Up @@ -322,7 +322,7 @@ async def add_file_log(
agent_type: AgentType,
author_role: AuthorRole,
) -> None:
"""Log a file status update"""
"""Log a file status update."""
try:
log_id = uuid4()
log_entry = FileLog(
Expand All @@ -343,7 +343,7 @@ async def add_file_log(
async def update_batch_entry(
self, batch_id: str, user_id: str, status: ProcessStatus, file_count: int
):
"""Update batch status"""
"""Update batch status."""
try:
batch = await self.get_batch(user_id, batch_id)
if not batch:
Expand Down
Loading