Move imports to top of file per PEP 8 guidelines

- Moved os, uuid, pathlib imports from inside loop to top of file
- Moved celery task import to module level
- Improves readability and avoids re-import overhead
This commit is contained in:
Claude 2025-11-18 22:36:19 +00:00
parent 8b0c76d46c
commit 66b7b8fce0
No known key found for this signature in database

View file

@ -1,5 +1,8 @@
# Force asyncio to use standard event loop before unstructured imports # Force asyncio to use standard event loop before unstructured imports
import asyncio import asyncio
import os
import uuid
from pathlib import Path
from fastapi import APIRouter, Depends, Form, HTTPException, UploadFile from fastapi import APIRouter, Depends, Form, HTTPException, UploadFile
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
@ -23,6 +26,7 @@ from app.schemas import (
) )
from app.users import current_active_user from app.users import current_active_user
from app.utils.check_ownership import check_ownership from app.utils.check_ownership import check_ownership
from app.tasks.celery_tasks.document_tasks import process_file_upload_task
try: try:
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
@ -108,11 +112,6 @@ async def create_documents_file_upload(
for file in files: for file in files:
try: try:
# Save file to persistent uploads directory
import os
import uuid
from pathlib import Path
# Create uploads directory if it doesn't exist # Create uploads directory if it doesn't exist
uploads_dir = Path(os.getenv("UPLOADS_DIR", "./uploads")) uploads_dir = Path(os.getenv("UPLOADS_DIR", "./uploads"))
uploads_dir.mkdir(parents=True, exist_ok=True) uploads_dir.mkdir(parents=True, exist_ok=True)
@ -127,10 +126,6 @@ async def create_documents_file_upload(
with open(temp_path, "wb") as f: with open(temp_path, "wb") as f:
f.write(content) f.write(content)
from app.tasks.celery_tasks.document_tasks import (
process_file_upload_task,
)
process_file_upload_task.delay( process_file_upload_task.delay(
temp_path, file.filename, search_space_id, str(user.id) temp_path, file.filename, search_space_id, str(user.id)
) )