Skip to content

Commit bd46361

Browse files
committed
feat: add version to GET /
1 parent d89fa08 commit bd46361

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from contextlib import asynccontextmanager
3+
from importlib.metadata import PackageNotFoundError, version
34

45
from dotenv import dotenv_values
56
from fastapi import FastAPI
@@ -74,7 +75,7 @@ async def lifespan(app: FastAPI):
7475

7576
@app.get("/")
7677
def public_route():
77-
return {"message": "AAI Backend API"}
78+
return {"message": "AAI Backend API", "version": SERVICE_VERSION}
7879

7980

8081
app.include_router(admin.router)
@@ -85,3 +86,12 @@ def public_route():
8586
app.include_router(sbp_register.router)
8687
app.include_router(utils.router)
8788
app.include_router(biocommons_groups.router)
89+
try:
90+
SERVICE_VERSION = version("aai-backend")
91+
except PackageNotFoundError:
92+
VERSION_FILE = os.path.join(os.path.dirname(__file__), "VERSION")
93+
try:
94+
with open(VERSION_FILE, "r", encoding="utf-8") as version_fp:
95+
SERVICE_VERSION = version_fp.read().strip()
96+
except FileNotFoundError:
97+
SERVICE_VERSION = "unknown"

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
def test_root(test_client):
99
response = test_client.get("/")
1010
assert response.status_code == 200
11-
assert response.json() == {"message": "AAI Backend API"}
11+
assert response.json()["message"] == "AAI Backend API"
12+
assert response.json().keys() == {"message", "version"}

0 commit comments

Comments
 (0)