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:05:14 +01:00
parent a3d23fbd1a
commit e5ccbf6ef1

View File

@ -4,13 +4,19 @@
PYPROJECT_FILE="$(dirname "$0")/pyproject.toml"
VERSION=$(grep -Po '(?<=version = ")[^"]*' "$PYPROJECT_FILE")
NAME=$(grep -Po '(?<=name = ")[^"]*' "$PYPROJECT_FILE")
NAME=$(grep -Po '(?<=name = ")[^"]*' "$PYPROJECT_FILE" | tr -d '\n')
if [[ -z "$VERSION" || -z "$NAME" ]]; then
echo "Error: Could not determine version or name from pyproject.toml"
exit 1
fi
# Ensure NAME is valid (no spaces or newlines)
if ! [[ "$NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "Error: Invalid project name detected: '$NAME'"
exit 1
fi
echo "Using project name: $NAME"
echo "Using version: $VERSION"
@ -35,7 +41,8 @@ java -jar openapi-generator-cli.jar generate \
-i "$(pwd)/openapi.json" \
-o python-client/ \
-g python \
--additional-properties=packageName="${NAME}client",projectName="${NAME}",packageVersion="${VERSION}"
--additional-properties=packageName="${NAME}client",projectName="${NAME}",packageVersion="${VERSION}" \
--additional-properties=authorName="Guillaume Gotthard",authorEmail="guillaume.gotthard@psi.ch"
# Check if the generator succeeded
if [[ ! -d python-client ]]; then