mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-09-13 07:21:16 +00:00
Migrate from Flask to FastAPI (#163)
* Migrate from Flask to FastAPI * FastAPI migration: - Use pydantic model classes as input parameters to the data/calculation classes. - Interface field names changed to constructor parameter names (for simplicity only during transition, should be updated in a followup PR). - Add basic interface requirements (e.g. some values > 0, etc.). * Update tests for new data format. * Python requirement down to 3.9 (TypeGuard no longer needed) * Makefile: Add helpful targets (e.g. development server with reload) * Move API doc from README to pydantic model classes (swagger) * Link to swagger.io with own openapi.yml. * Commit openapi.json and check with pytest for changes so the documentation is always up-to-date. * Streamline docker * FastAPI: Run startup action on dev server * Fix config for /strompreis, endpoint still broken however. * test_openapi: Compare against docs/.../openapi.json * Move fastapi to server/ submodule * See #187 for new repository structure.
This commit is contained in:
committed by
GitHub
parent
ed3226e522
commit
f61665669f
20
Makefile
20
Makefile
@@ -1,5 +1,5 @@
|
||||
# Define the targets
|
||||
.PHONY: help venv pip install dist test test-full docker-run docs read-docs clean
|
||||
.PHONY: help venv pip install dist test test-full docker-run docker-build docs read-docs clean format run run-dev
|
||||
|
||||
# Default target
|
||||
all: help
|
||||
@@ -10,12 +10,14 @@ help:
|
||||
@echo " venv - Set up a Python 3 virtual environment."
|
||||
@echo " pip - Install dependencies from requirements.txt."
|
||||
@echo " pip-dev - Install dependencies from requirements-dev.txt."
|
||||
@echo " format - Format source code."
|
||||
@echo " install - Install EOS in editable form (development mode) into virtual environment."
|
||||
@echo " docker-run - Run entire setup on docker"
|
||||
@echo " docker-build - Rebuild docker image"
|
||||
@echo " docs - Generate HTML documentation (in build/docs/html/)."
|
||||
@echo " read-docs - Read HTML documentation in your browser."
|
||||
@echo " run - Run flask_server in the virtual environment (needs install before)."
|
||||
@echo " run - Run FastAPI server in the virtual environment (needs install before)."
|
||||
@echo " run-dev - Run FastAPI development server in the virtual environment (automatically reloads)."
|
||||
@echo " dist - Create distribution (in dist/)."
|
||||
@echo " clean - Remove generated documentation, distribution and virtual environment."
|
||||
|
||||
@@ -66,8 +68,12 @@ clean:
|
||||
@echo "Deletion complete."
|
||||
|
||||
run:
|
||||
@echo "Starting flask server, please wait..."
|
||||
.venv/bin/python -m akkudoktoreosserver.flask_server
|
||||
@echo "Starting FastAPI server, please wait..."
|
||||
.venv/bin/python -m akkudoktoreos.server.fastapi_server
|
||||
|
||||
run-dev:
|
||||
@echo "Starting FastAPI development server, please wait..."
|
||||
.venv/bin/fastapi dev src/akkudoktoreos/server/fastapi_server.py
|
||||
|
||||
# Target to setup tests.
|
||||
test-setup: pip-dev
|
||||
@@ -83,9 +89,13 @@ test-full:
|
||||
@echo "Running all tests..."
|
||||
.venv/bin/pytest --full-run
|
||||
|
||||
# Target to format code.
|
||||
format:
|
||||
pre-commit run --all-files
|
||||
|
||||
# Run entire setup on docker
|
||||
docker-run:
|
||||
@docker compose up --remove-orphans
|
||||
|
||||
docker-build:
|
||||
@docker compose build
|
||||
@docker compose build --pull
|
||||
|
Reference in New Issue
Block a user