Skip to content

Commit e666308

Browse files
authored
Merge pull request #17 from nuclearcat/fix-imports
Arrange imports properly
2 parents 4089f90 + 0506c0f commit e666308

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

main.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import json
88
import asyncio
99
from datetime import datetime
10+
from pathlib import Path
1011
from typing import List
1112
from contextlib import asynccontextmanager
13+
from urllib.parse import quote
14+
15+
import aiohttp
1216
from fastapi import (
1317
FastAPI,
1418
Request,
@@ -63,8 +67,10 @@
6367
from db_constraints import (
6468
validate_single_running_staging,
6569
enforce_single_running_staging,
70+
get_running_staging_count,
6671
)
6772
from scheduler import register_cron_jobs
73+
from github_integration import GitHubWorkflowManager
6874

6975

7076
# Pydantic models for API requests
@@ -80,7 +86,7 @@ class PasswordChangeRequest(BaseModel):
8086
configure_discord_webhook(get_setting(DISCORD_WEBHOOK_URL))
8187

8288
# Import orchestrator after database is initialized
83-
from orchestrator import orchestrator
89+
from orchestrator import orchestrator, StagingOrchestrator
8490

8591

8692
# Background task to run orchestrator
@@ -98,8 +104,6 @@ async def run_orchestrator():
98104
@asynccontextmanager
99105
async def lifespan(app: FastAPI):
100106
# Startup
101-
from orchestrator import StagingOrchestrator
102-
103107
orchestrator = StagingOrchestrator()
104108

105109
# Run startup recovery to handle steps that can't survive restart
@@ -168,7 +172,6 @@ def get_real_ip(request: Request) -> str:
168172
@app.get("/ajax.png")
169173
async def get_ajax_icon():
170174
"""Serve the AJAX loading icon directly"""
171-
import os
172175

173176
file_path = os.path.join(os.path.dirname(__file__), "templates", "ajax.png")
174177
return FileResponse(file_path, media_type="image/png")
@@ -177,7 +180,6 @@ async def get_ajax_icon():
177180
@app.get("/robots.txt")
178181
async def get_robots_txt():
179182
"""Serve robots.txt to deny all crawlers"""
180-
import os
181183

182184
file_path = os.path.join(os.path.dirname(__file__), "robots.txt")
183185
return FileResponse(file_path, media_type="text/plain")
@@ -890,9 +892,6 @@ async def get_staging_nodes(
890892

891893
# Fetch nodes from KernelCI staging API
892894
try:
893-
import aiohttp
894-
from urllib.parse import quote
895-
896895
api_url = f"https://staging.kernelci.org:9000/latest/nodes?treeid={quote(staging_run.treeid)}&limit=10000"
897896

898897
async with aiohttp.ClientSession() as session:
@@ -1004,8 +1003,6 @@ async def get_staging_tested_prs(
10041003
}
10051004

10061005
try:
1007-
from github_integration import GitHubWorkflowManager
1008-
10091006
github_manager = GitHubWorkflowManager(github_token)
10101007
applied_prs = await github_manager.get_applied_prs_from_logs(
10111008
str(github_actions_id)
@@ -1066,9 +1063,6 @@ async def cancel_staging_run(
10661063

10671064
try:
10681065
# Cancel any running GitHub workflows
1069-
from github_integration import GitHubWorkflowManager
1070-
from settings import get_setting, GITHUB_TOKEN
1071-
10721066
# Find GitHub workflow steps that might need cancellation
10731067
for step in staging_run.steps:
10741068
if (
@@ -1149,9 +1143,6 @@ async def get_changelog(current_user: User = Depends(get_current_user_optional))
11491143
if not current_user:
11501144
raise HTTPException(status_code=401, detail="Authentication required")
11511145

1152-
import os
1153-
from pathlib import Path
1154-
11551146
# Look for CHANGELOG.md in the current directory
11561147
changelog_path = Path("CHANGELOG.md")
11571148

@@ -1191,9 +1182,6 @@ async def get_staging_status(
11911182
if not current_user:
11921183
raise HTTPException(status_code=401, detail="Authentication required")
11931184

1194-
from db_constraints import get_running_staging_count
1195-
from datetime import datetime
1196-
11971185
running_staging = validate_single_running_staging(db)
11981186
running_count = get_running_staging_count(db)
11991187

@@ -1228,8 +1216,6 @@ async def check_workflow_status(
12281216
}
12291217

12301218
try:
1231-
from github_integration import GitHubWorkflowManager
1232-
12331219
github_manager = GitHubWorkflowManager(github_token)
12341220
running_workflows = await github_manager.get_running_workflows()
12351221

0 commit comments

Comments
 (0)