fix: replace datetime.UTC with timezone.utc for Python 3.10 compatibility
datetime.UTC was introduced in Python 3.11. Users on 3.10 get an ImportError. Also lower ruff/mypy target-version from py313 to py310 to match minimum supported version.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from datetime import UTC, datetime
|
from datetime import datetime, timezone
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
@@ -71,7 +71,7 @@ async def save_canvas(
|
|||||||
state = await db.get(CanvasState, 1)
|
state = await db.get(CanvasState, 1)
|
||||||
if state:
|
if state:
|
||||||
state.viewport = body.viewport
|
state.viewport = body.viewport
|
||||||
state.saved_at = datetime.now(UTC)
|
state.saved_at = datetime.now(timezone.utc)
|
||||||
else:
|
else:
|
||||||
db.add(CanvasState(id=1, viewport=body.viewport))
|
db.add(CanvasState(id=1, viewport=body.viewport))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""APScheduler setup for background scan and status check jobs."""
|
"""APScheduler setup for background scan and status check jobs."""
|
||||||
import logging
|
import logging
|
||||||
from datetime import UTC, datetime
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -33,12 +33,12 @@ async def _run_status_checks() -> None:
|
|||||||
if n:
|
if n:
|
||||||
n.status = check_result["status"]
|
n.status = check_result["status"]
|
||||||
n.response_time_ms = check_result["response_time_ms"]
|
n.response_time_ms = check_result["response_time_ms"]
|
||||||
n.last_seen = datetime.now(UTC) if check_result["status"] == "online" else n.last_seen
|
n.last_seen = datetime.now(timezone.utc) if check_result["status"] == "online" else n.last_seen
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await broadcast_status(
|
await broadcast_status(
|
||||||
node_id=node.id,
|
node_id=node.id,
|
||||||
status=check_result["status"],
|
status=check_result["status"],
|
||||||
checked_at=datetime.now(UTC).isoformat(),
|
checked_at=datetime.now(timezone.utc).isoformat(),
|
||||||
response_time_ms=check_result["response_time_ms"],
|
response_time_ms=check_result["response_time_ms"],
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from datetime import UTC, datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
@@ -17,7 +17,7 @@ def hash_password(password: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def create_access_token(subject: str) -> str:
|
def create_access_token(subject: str) -> str:
|
||||||
expire = datetime.now(UTC) + timedelta(minutes=settings.access_token_expire_minutes)
|
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes)
|
||||||
payload = {"sub": subject, "exp": expire}
|
payload = {"sub": subject, "exp": expire}
|
||||||
return str(jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm))
|
return str(jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import UTC, datetime
|
from datetime import datetime, timezone
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from sqlalchemy import JSON, Boolean, DateTime, Float, ForeignKey, Integer, String, Text
|
from sqlalchemy import JSON, Boolean, DateTime, Float, ForeignKey, Integer, String, Text
|
||||||
@@ -9,7 +9,7 @@ from app.db.database import Base
|
|||||||
|
|
||||||
|
|
||||||
def _now() -> datetime:
|
def _now() -> datetime:
|
||||||
return datetime.now(UTC)
|
return datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
def _uuid() -> str:
|
def _uuid() -> str:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
from datetime import UTC, datetime
|
from datetime import datetime, timezone
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
@@ -159,7 +159,7 @@ async def run_scan(ranges: list[str], db: AsyncSession, run_id: str) -> None:
|
|||||||
if run:
|
if run:
|
||||||
run.status = "done"
|
run.status = "done"
|
||||||
run.devices_found = devices_found
|
run.devices_found = devices_found
|
||||||
run.finished_at = datetime.now(UTC)
|
run.finished_at = datetime.now(timezone.utc)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@@ -168,5 +168,5 @@ async def run_scan(ranges: list[str], db: AsyncSession, run_id: str) -> None:
|
|||||||
if run:
|
if run:
|
||||||
run.status = "error"
|
run.status = "error"
|
||||||
run.error = str(exc)
|
run.error = str(exc)
|
||||||
run.finished_at = datetime.now(UTC)
|
run.finished_at = datetime.now(timezone.utc)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
target-version = "py313"
|
target-version = "py310"
|
||||||
line-length = 120
|
line-length = 120
|
||||||
exclude = ["migrations", ".venv"]
|
exclude = ["migrations", ".venv"]
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ ignore = ["B008"]
|
|||||||
"tests/**" = ["E501"]
|
"tests/**" = ["E501"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.13"
|
python_version = "3.10"
|
||||||
strict = true
|
strict = true
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
exclude = ["migrations", ".venv"]
|
exclude = ["migrations", ".venv"]
|
||||||
|
|||||||
Reference in New Issue
Block a user