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:21:08 +01:00
parent 98dfc2af4a
commit adf811437d
2 changed files with 35 additions and 6 deletions

View File

@ -2,6 +2,7 @@
import sys
import os
import json
import tomllib
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@ -22,7 +23,23 @@ from app.routers import (
)
from app.database import Base, engine, SessionLocal, load_sample_data
app = FastAPI()
# Utility function to fetch metadata from pyproject.toml
def get_project_metadata():
with open("pyproject.toml", "rb") as f:
pyproject = tomllib.load(f)
name = pyproject["project"]["name"]
version = pyproject["project"]["version"]
return name, version
# Get project metadata from pyproject.toml
project_name, project_version = get_project_metadata()
app = FastAPI(
title=project_name, # Syncs with project `name`
description="Backend for next-gen sample management system",
version=project_version, # Syncs with project `version`
)
# Determine environment and configuration file path
environment = os.getenv("ENVIRONMENT", "dev")