Sync project metadata with pyproject.toml

Updated scripts and backend to dynamically retrieve project name and version from `pyproject.toml`. This ensures consistent metadata across the OpenAPI client generation and the FastAPI application.
This commit is contained in:
GotthardG 2024-12-17 10:40:39 +01:00
parent 6a172296d4
commit e44316c5b9

View File

@ -2,7 +2,6 @@
import sys
import os
import json
import tomllib
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@ -26,14 +25,20 @@ from app.database import Base, engine, SessionLocal, load_sample_data
# Utility function to fetch metadata from pyproject.toml
def get_project_metadata():
from pathlib import Path
import tomllib
# Dynamically resolve the correct path to pyproject.toml
root_dir = (
Path(__file__).resolve().parent.parent.parent
) # Adjust path to project root
pyproject_path = root_dir / "pyproject.toml"
# Print the resolved path for debugging
print(f"Looking for pyproject.toml at: {pyproject_path}")
if not pyproject_path.exists():
raise FileNotFoundError(f"pyproject.toml not found at {pyproject_path}")
raise FileNotFoundError(f"{pyproject_path} not found")
with open(pyproject_path, "rb") as f:
pyproject = tomllib.load(f)