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 11:54:32 +01:00
parent 7d6168a197
commit 8cb2154740
3 changed files with 30 additions and 35 deletions

View File

@ -41,8 +41,6 @@ lint:
deploy: deploy:
stage: deploy stage: deploy
only:
- main
variables: variables:
CI: "true" # Mark this as a CI run CI: "true" # Mark this as a CI run
ENVIRONMENT: test # Use test environment settings ENVIRONMENT: test # Use test environment settings
@ -52,9 +50,8 @@ deploy:
- source $VIRTUAL_ENV/bin/activate - source $VIRTUAL_ENV/bin/activate
- pip install -r requirements.txt - pip install -r requirements.txt
- echo "Starting the application to test startup with SSL..." - echo "Starting the application to test startup with SSL..."
- cd backend - cd $CI_PROJECT_DIR/backend # Use GitLab-provided dynamic root path
- python -m main # App will start, validate, and exit - python -m main # Run the main module dynamically
- echo "Application startup validation completed successfully."
release: release:
stage: release stage: release

View File

@ -2,6 +2,7 @@
import sys import sys
import os import os
import json import json
import tomllib
from pathlib import Path from pathlib import Path
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
@ -25,25 +26,22 @@ from app.database import Base, engine, SessionLocal, load_sample_data
# Utility function to fetch metadata from pyproject.toml # Utility function to fetch metadata from pyproject.toml
def get_project_metadata(): def get_project_metadata():
from pathlib import Path # Start from the current script's directory and search for pyproject.toml
import tomllib script_dir = Path(__file__).resolve().parent
for parent in script_dir.parents:
# Dynamically resolve the project root folder correctly. pyproject_path = parent / "pyproject.toml"
# Assume that `pyproject.toml` is located in the heidi-v2 root folder if pyproject_path.exists():
root_dir = Path(__file__).resolve().parent.parent.parent
pyproject_path = root_dir / "heidi-v2" / "pyproject.toml"
print(f"Looking for pyproject.toml at: {pyproject_path}") # Debugging output
if not pyproject_path.exists():
raise FileNotFoundError(f"{pyproject_path} not found")
with open(pyproject_path, "rb") as f: with open(pyproject_path, "rb") as f:
pyproject = tomllib.load(f) pyproject = tomllib.load(f)
name = pyproject["project"]["name"] name = pyproject["project"]["name"]
version = pyproject["project"]["version"] version = pyproject["project"]["version"]
return name, version return name, version
# If no pyproject.toml is found, raise FileNotFoundError
raise FileNotFoundError(
f"pyproject.toml not found in any parent directory of {script_dir}"
)
# Get project metadata from pyproject.toml # Get project metadata from pyproject.toml
project_name, project_version = get_project_metadata() project_name, project_version = get_project_metadata()

View File

@ -26,8 +26,8 @@ dependencies = [
"mysqlclient~=2.1.1", "mysqlclient~=2.1.1",
"python-multipart~=0.0.6", "python-multipart~=0.0.6",
"uvicorn==0.23.1", "uvicorn==0.23.1",
"python-dateutil~=2.8.2" "python-dateutil~=2.8.2",
"tomli>=2.0.1"
] ]
[tool.pytest.ini_options] [tool.pytest.ini_options]
norecursedirs = ["backend/python-client"] norecursedirs = ["backend/python-client"]