Skip to content

Commit 3c306e2

Browse files
committed
fix: mypy
1 parent 326463d commit 3c306e2

File tree

1 file changed

+19
-19
lines changed
  • api/src/software_metrics_machine/apps/rest

1 file changed

+19
-19
lines changed

api/src/software_metrics_machine/apps/rest/main.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
# type: ignore
2-
31
import holoviews as hv # TODO: remove dependency that is for dashboard only
42
import math
53
from pathlib import Path
64

75
from fastapi import FastAPI, Request
86
from enum import Enum
97
from fastapi import Query
10-
from fastapi.responses import JSONResponse, Response
8+
from fastapi.responses import JSONResponse, Response, FileResponse
119
from fastapi.middleware.cors import CORSMiddleware
1210
from fastapi.staticfiles import StaticFiles
13-
from fastapi.responses import FileResponse
11+
from typing import Callable
1412

1513
from typing import Optional
1614

@@ -158,7 +156,7 @@ def entity_churn(
158156
"""
159157
viewer = EntityChurnViewer(repository=create_codemaat_repository())
160158
result = viewer.render(
161-
top_n=top,
159+
top_n=top or 0,
162160
ignore_files=ignore_files,
163161
include_only=include_only,
164162
start_date=start_date,
@@ -192,7 +190,7 @@ def code_coupling(
192190
Return coupling pairs ranked by coupling degree.
193191
"""
194192
result = CouplingViewer(repository=create_codemaat_repository()).render(
195-
ignore_files=ignore_files, include_only=include_only, top=top
193+
ignore_files=ignore_files, include_only=include_only, top=top or 20
196194
)
197195
return JSONResponse(convert_result_data(result.data))
198196

@@ -226,7 +224,7 @@ def entity_ownership(
226224
"""
227225
viewer = EntityOnershipViewer(repository=create_codemaat_repository())
228226
result = viewer.render(
229-
top_n=top,
227+
top_n=top or 0,
230228
ignore_files=ignore_files,
231229
authors=authors,
232230
include_only=include_only,
@@ -265,10 +263,10 @@ def pipeline_jobs_by_status(
265263
"""
266264
view = ViewJobsByStatus(repository=create_pipelines_repository())
267265
result = view.main(
268-
job_name=job_name,
266+
job_name=job_name or "",
269267
workflow_path=workflow_path,
270-
with_pipeline=with_pipeline,
271-
aggregate_by_week=aggregate_by_week,
268+
with_pipeline=with_pipeline or False,
269+
aggregate_by_week=aggregate_by_week or False,
272270
pipeline_raw_filters=raw_filters,
273271
start_date=start_date,
274272
end_date=end_date,
@@ -285,7 +283,7 @@ def pipeline_summary(
285283
"""
286284
view = WorkflowRunSummary(repository=create_pipelines_repository())
287285
result = view.print_summary(
288-
max_workflows=None,
286+
max_workflows=100,
289287
start_date=start_date,
290288
end_date=end_date,
291289
output_format="json",
@@ -309,7 +307,7 @@ def pipeline_runs_duration(
309307
workflow_path=workflow_path,
310308
start_date=start_date,
311309
end_date=end_date,
312-
max_runs=max_runs,
310+
max_runs=max_runs or 100,
313311
raw_filters=raw_filters,
314312
)
315313
return JSONResponse(convert_result_data(result.data))
@@ -328,8 +326,8 @@ def pipeline_deployment_frequency(
328326
pipelines_repository = create_pipelines_repository()
329327
view = ViewDeploymentFrequency(repository=pipelines_repository)
330328
result = view.plot(
331-
workflow_path=pipelines_repository.configuration.deployment_frequency_target_pipeline or workflow_path,
332-
job_name=pipelines_repository.configuration.deployment_frequency_target_job or job_name,
329+
workflow_path=pipelines_repository.configuration.deployment_frequency_target_pipeline or workflow_path or "",
330+
job_name=pipelines_repository.configuration.deployment_frequency_target_job or job_name or "",
333331
start_date=start_date,
334332
end_date=end_date,
335333
)
@@ -350,7 +348,7 @@ def pipeline_runs_by(
350348
"""
351349
view = ViewWorkflowRunsByWeekOrMonth(repository=create_pipelines_repository())
352350
result = view.main(
353-
aggregate_by=aggregate_by,
351+
aggregate_by=aggregate_by or "week",
354352
workflow_path=workflow_path,
355353
start_date=start_date,
356354
end_date=end_date,
@@ -709,14 +707,16 @@ def configuration():
709707
break
710708

711709
if static_path:
712-
print(f"Serving static files from: {static_path}")
713-
app.mount("/", StaticFiles(directory=str(static_path), html=True), name="dashboard")
710+
# Capture the narrowed type for use in the middleware closure
711+
active_static_path = static_path
712+
print(f"Serving static files from: {active_static_path}")
713+
app.mount("/", StaticFiles(directory=str(active_static_path), html=True), name="dashboard")
714714

715715
@app.middleware("http")
716-
async def catch_404(request: Request, call_next: Response):
716+
async def catch_404(request: Request, call_next: Callable) -> Response:
717717
response = await call_next(request)
718718
if response.status_code == 404:
719-
file_response = str(static_path / "index.html")
719+
file_response = str(active_static_path / "index.html")
720720
print(f"Returning index.html for 404 response {request.url} {file_response}")
721721
return FileResponse(file_response, headers={"Cache-Control": "no-cache"})
722722
return response

0 commit comments

Comments
 (0)