diff --git a/backend/main.py b/backend/main.py index a2f2a8b..243c7b3 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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") diff --git a/make_openapi_client.sh b/make_openapi_client.sh index 1b411e5..9bc16c2 100755 --- a/make_openapi_client.sh +++ b/make_openapi_client.sh @@ -1,5 +1,18 @@ #!/bin/bash -VERSION=0.1.0 + +# Extract values from pyproject.toml +PYPROJECT_FILE="$(dirname "$0")/../pyproject.toml" + +VERSION=$(grep -Po '(?<=version = ")[^"]*' "$PYPROJECT_FILE") +NAME=$(grep -Po '(?<=name = ")[^"]*' "$PYPROJECT_FILE") + +if [[ -z "$VERSION" || -z "$NAME" ]]; then + echo "Error: Could not determine version or name from pyproject.toml" + exit 1 +fi + +echo "Using project name: $NAME" +echo "Using version: $VERSION" # Navigate to project root cd "$(dirname "$0")/backend" || exit @@ -17,12 +30,12 @@ if [[ ! -f openapi-generator-cli.jar ]]; then wget "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${OPENAPI_VERSION}/openapi-generator-cli-${OPENAPI_VERSION}.jar" -O openapi-generator-cli.jar fi -# Run OpenAPI generator +# Run OpenAPI generator with synced name and version java -jar openapi-generator-cli.jar generate \ -i "$(pwd)/openapi.json" \ -o python-client/ \ -g python \ - --additional-properties=packageName=aareDBclient,projectName=aareDB,packageVersion=${VERSION} + --additional-properties=packageName="${NAME}client",projectName="${NAME}",packageVersion="${VERSION}" # Check if the generator succeeded if [[ ! -d python-client ]]; then @@ -38,5 +51,4 @@ pip install -U pip build python -m build # Skip uploading the package. This will happen in the release stage. -echo "Python client generated and package built successfully." -echo "git.psi.ch pushed" \ No newline at end of file +echo "Python client generated and package built successfully." \ No newline at end of file