Rename FastAPI server to EOS. ()

Rename FastAPI server to `eos` and FastHTML server to `eosdash`.

Make an user easily identify what server is meant. FastAPI and FastHTML are
implementation details that may confuse the non-technical user.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte 2025-01-09 16:54:49 +01:00 committed by GitHub
parent 1d1fa9585a
commit 34d8e88771
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 130 additions and 134 deletions

View File

@ -19,8 +19,8 @@ help:
@echo " read-docs - Read HTML documentation in your browser."
@echo " gen-docs - Generate openapi.json and docs/_generated/*.""
@echo " clean-docs - Remove generated documentation.""
@echo " run - Run FastAPI production server in the virtual environment."
@echo " run-dev - Run FastAPI development server in the virtual environment (automatically reloads)."
@echo " run - Run EOS production server in the virtual environment."
@echo " run-dev - Run EOS development server in the virtual environment (automatically reloads)."
@echo " dist - Create distribution (in dist/)."
@echo " clean - Remove generated documentation, distribution and virtual environment."
@ -84,12 +84,12 @@ clean: clean-docs
@echo "Deletion complete."
run:
@echo "Starting FastAPI server, please wait..."
.venv/bin/fastapi run --port 8503 src/akkudoktoreos/server/fastapi_server.py
@echo "Starting EOS server, please wait..."
.venv/bin/fastapi run --port 8503 src/akkudoktoreos/server/eos.py
run-dev:
@echo "Starting FastAPI development server, please wait..."
.venv/bin/fastapi dev --port 8503 src/akkudoktoreos/server/fastapi_server.py
@echo "Starting EOS development server, please wait..."
.venv/bin/fastapi dev --port 8503 src/akkudoktoreos/server/eos.py
# Target to setup tests.
test-setup: pip-dev

View File

@ -37,13 +37,13 @@ Finally, start EOS fastapi server:
Linux:
```bash
.venv/bin/fastapi run --port 8503 src/akkudoktoreos/server/fastapi_server.py
.venv/bin/fastapi run --port 8503 src/akkudoktoreos/server/eos.py
```
Windows:
```
.venv\Scripts\fastapi run --port 8503 src/akkudoktoreos/server/fastapi_server.py
.venv\Scripts\fastapi run --port 8503 src/akkudoktoreos/server/eos.py
```
### Docker

View File

@ -287,12 +287,12 @@
| Name | Type | Read-Only | Default | Description |
| ---- | ---- | --------- | ------- | ----------- |
| `server_fastapi_host` | `Optional[pydantic.networks.IPvAnyAddress]` | `rw` | `0.0.0.0` | FastAPI server IP address. |
| `server_fastapi_port` | `Optional[int]` | `rw` | `8503` | FastAPI server IP port number. |
| `server_fastapi_startup_server_fasthtml` | `Optional[bool]` | `rw` | `True` | FastAPI server to startup application FastHTML server. |
| `server_fastapi_verbose` | `Optional[bool]` | `rw` | `False` | Enable debug output |
| `server_fasthtml_host` | `Optional[pydantic.networks.IPvAnyAddress]` | `rw` | `0.0.0.0` | FastHTML server IP address. |
| `server_fasthtml_port` | `Optional[int]` | `rw` | `8504` | FastHTML server IP port number. |
| `server_eos_host` | `Optional[pydantic.networks.IPvAnyAddress]` | `rw` | `0.0.0.0` | EOS server IP address. |
| `server_eos_port` | `Optional[int]` | `rw` | `8503` | EOS server IP port number. |
| `server_eos_startup_eosdash` | `Optional[bool]` | `rw` | `True` | EOS server to start EOSdash server. |
| `server_eos_verbose` | `Optional[bool]` | `rw` | `False` | Enable debug output |
| `server_eosdash_host` | `Optional[pydantic.networks.IPvAnyAddress]` | `rw` | `0.0.0.0` | EOSdash server IP address. |
| `server_eosdash_port` | `Optional[int]` | `rw` | `8504` | EOSdash server IP port number. |
:::
## Weather Forecast Configuration

View File

@ -202,17 +202,17 @@ Returns:
**Parameters**:
- `server_fastapi_host` (query, optional): FastAPI server IP address.
- `server_eos_host` (query, optional): EOS server IP address.
- `server_fastapi_port` (query, optional): FastAPI server IP port number.
- `server_eos_port` (query, optional): EOS server IP port number.
- `server_fastapi_verbose` (query, optional): Enable debug output
- `server_eos_verbose` (query, optional): Enable debug output
- `server_fastapi_startup_server_fasthtml` (query, optional): FastAPI server to startup application FastHTML server.
- `server_eos_startup_eosdash` (query, optional): EOS server to start EOSdash server.
- `server_fasthtml_host` (query, optional): FastHTML server IP address.
- `server_eosdash_host` (query, optional): EOSdash server IP address.
- `server_fasthtml_port` (query, optional): FastHTML server IP port number.
- `server_eosdash_port` (query, optional): EOSdash server IP port number.
- `weatherimport_file_path` (query, optional): Path to the file to import weather data from.

View File

@ -38,13 +38,13 @@ Start the EOS fastapi server:
.. code-block:: powershell
.venv\Scripts\fastapi run src/akkudoktoreos/server/fastapi_server.py
.venv\Scripts\fastapi run src/akkudoktoreos/server/eos.py
.. tab:: Linux
.. code-block:: bash
.venv/bin/fastapi run src/akkudoktoreos/server/fastapi_server.py
.venv/bin/fastapi run src/akkudoktoreos/server/eos.py
```

View File

@ -137,7 +137,7 @@
"operationId": "fastapi_config_put_v1_config_put",
"parameters": [
{
"name": "server_fastapi_host",
"name": "server_eos_host",
"in": "query",
"required": false,
"schema": {
@ -150,14 +150,14 @@
"type": "null"
}
],
"description": "FastAPI server IP address.",
"description": "EOS server IP address.",
"default": "0.0.0.0",
"title": "Server Fastapi Host"
"title": "Server Eos Host"
},
"description": "FastAPI server IP address."
"description": "EOS server IP address."
},
{
"name": "server_fastapi_port",
"name": "server_eos_port",
"in": "query",
"required": false,
"schema": {
@ -169,14 +169,14 @@
"type": "null"
}
],
"description": "FastAPI server IP port number.",
"description": "EOS server IP port number.",
"default": 8503,
"title": "Server Fastapi Port"
"title": "Server Eos Port"
},
"description": "FastAPI server IP port number."
"description": "EOS server IP port number."
},
{
"name": "server_fastapi_verbose",
"name": "server_eos_verbose",
"in": "query",
"required": false,
"schema": {
@ -190,12 +190,12 @@
],
"description": "Enable debug output",
"default": false,
"title": "Server Fastapi Verbose"
"title": "Server Eos Verbose"
},
"description": "Enable debug output"
},
{
"name": "server_fastapi_startup_server_fasthtml",
"name": "server_eos_startup_eosdash",
"in": "query",
"required": false,
"schema": {
@ -207,14 +207,14 @@
"type": "null"
}
],
"description": "FastAPI server to startup application FastHTML server.",
"description": "EOS server to start EOSdash server.",
"default": true,
"title": "Server Fastapi Startup Server Fasthtml"
"title": "Server Eos Startup Eosdash"
},
"description": "FastAPI server to startup application FastHTML server."
"description": "EOS server to start EOSdash server."
},
{
"name": "server_fasthtml_host",
"name": "server_eosdash_host",
"in": "query",
"required": false,
"schema": {
@ -227,14 +227,14 @@
"type": "null"
}
],
"description": "FastHTML server IP address.",
"description": "EOSdash server IP address.",
"default": "0.0.0.0",
"title": "Server Fasthtml Host"
"title": "Server Eosdash Host"
},
"description": "FastHTML server IP address."
"description": "EOSdash server IP address."
},
{
"name": "server_fasthtml_port",
"name": "server_eosdash_port",
"in": "query",
"required": false,
"schema": {
@ -246,11 +246,11 @@
"type": "null"
}
],
"description": "FastHTML server IP port number.",
"description": "EOSdash server IP port number.",
"default": 8504,
"title": "Server Fasthtml Port"
"title": "Server Eosdash Port"
},
"description": "FastHTML server IP port number."
"description": "EOSdash server IP port number."
},
{
"name": "weatherimport_file_path",
@ -3947,7 +3947,7 @@
"schemas": {
"ConfigEOS": {
"properties": {
"server_fastapi_host": {
"server_eos_host": {
"anyOf": [
{
"type": "string",
@ -3957,11 +3957,11 @@
"type": "null"
}
],
"title": "Server Fastapi Host",
"description": "FastAPI server IP address.",
"title": "Server Eos Host",
"description": "EOS server IP address.",
"default": "0.0.0.0"
},
"server_fastapi_port": {
"server_eos_port": {
"anyOf": [
{
"type": "integer"
@ -3970,11 +3970,11 @@
"type": "null"
}
],
"title": "Server Fastapi Port",
"description": "FastAPI server IP port number.",
"title": "Server Eos Port",
"description": "EOS server IP port number.",
"default": 8503
},
"server_fastapi_verbose": {
"server_eos_verbose": {
"anyOf": [
{
"type": "boolean"
@ -3983,11 +3983,11 @@
"type": "null"
}
],
"title": "Server Fastapi Verbose",
"title": "Server Eos Verbose",
"description": "Enable debug output",
"default": false
},
"server_fastapi_startup_server_fasthtml": {
"server_eos_startup_eosdash": {
"anyOf": [
{
"type": "boolean"
@ -3996,11 +3996,11 @@
"type": "null"
}
],
"title": "Server Fastapi Startup Server Fasthtml",
"description": "FastAPI server to startup application FastHTML server.",
"title": "Server Eos Startup Eosdash",
"description": "EOS server to start EOSdash server.",
"default": true
},
"server_fasthtml_host": {
"server_eosdash_host": {
"anyOf": [
{
"type": "string",
@ -4010,11 +4010,11 @@
"type": "null"
}
],
"title": "Server Fasthtml Host",
"description": "FastHTML server IP address.",
"title": "Server Eosdash Host",
"description": "EOSdash server IP address.",
"default": "0.0.0.0"
},
"server_fasthtml_port": {
"server_eosdash_port": {
"anyOf": [
{
"type": "integer"
@ -4023,8 +4023,8 @@
"type": "null"
}
],
"title": "Server Fasthtml Port",
"description": "FastHTML server IP port number.",
"title": "Server Eosdash Port",
"description": "EOSdash server IP port number.",
"default": 8504
},
"weatherimport_file_path": {
@ -6626,7 +6626,7 @@
},
"SettingsEOS": {
"properties": {
"server_fastapi_host": {
"server_eos_host": {
"anyOf": [
{
"type": "string",
@ -6636,11 +6636,11 @@
"type": "null"
}
],
"title": "Server Fastapi Host",
"description": "FastAPI server IP address.",
"title": "Server Eos Host",
"description": "EOS server IP address.",
"default": "0.0.0.0"
},
"server_fastapi_port": {
"server_eos_port": {
"anyOf": [
{
"type": "integer"
@ -6649,11 +6649,11 @@
"type": "null"
}
],
"title": "Server Fastapi Port",
"description": "FastAPI server IP port number.",
"title": "Server Eos Port",
"description": "EOS server IP port number.",
"default": 8503
},
"server_fastapi_verbose": {
"server_eos_verbose": {
"anyOf": [
{
"type": "boolean"
@ -6662,11 +6662,11 @@
"type": "null"
}
],
"title": "Server Fastapi Verbose",
"title": "Server Eos Verbose",
"description": "Enable debug output",
"default": false
},
"server_fastapi_startup_server_fasthtml": {
"server_eos_startup_eosdash": {
"anyOf": [
{
"type": "boolean"
@ -6675,11 +6675,11 @@
"type": "null"
}
],
"title": "Server Fastapi Startup Server Fasthtml",
"description": "FastAPI server to startup application FastHTML server.",
"title": "Server Eos Startup Eosdash",
"description": "EOS server to start EOSdash server.",
"default": true
},
"server_fasthtml_host": {
"server_eosdash_host": {
"anyOf": [
{
"type": "string",
@ -6689,11 +6689,11 @@
"type": "null"
}
],
"title": "Server Fasthtml Host",
"description": "FastHTML server IP address.",
"title": "Server Eosdash Host",
"description": "EOSdash server IP address.",
"default": "0.0.0.0"
},
"server_fasthtml_port": {
"server_eosdash_port": {
"anyOf": [
{
"type": "integer"
@ -6702,8 +6702,8 @@
"type": "null"
}
],
"title": "Server Fasthtml Port",
"description": "FastHTML server IP port number.",
"title": "Server Eosdash Port",
"description": "EOSdash server IP port number.",
"default": 8504
},
"weatherimport_file_path": {

View File

@ -1,5 +1,5 @@
#!.venv/bin/python
"""This module generates the OpenAPI specification for the FastAPI application defined in `akkudoktoreos.server.fastapi_server`.
"""This module generates the OpenAPI specification for the EOS application defined in `akkudoktoreos.server.eos`.
The script can be executed directly to generate the OpenAPI specification
either to the standard output or to a specified file.
@ -20,7 +20,7 @@ import sys
from fastapi.openapi.utils import get_openapi
from akkudoktoreos.server.fastapi_server import app
from akkudoktoreos.server.eos import app
def generate_openapi() -> dict:

View File

@ -289,7 +289,7 @@ class ConfigEOS(SingletonMixin, SettingsEOS):
Example:
>>> config = get_config()
>>> new_data = {"prediction_hours": 24, "server_fastapi_port": 8000}
>>> new_data = {"prediction_hours": 24, "server_eos_port": 8000}
>>> config.merge_settings_from_dict(new_data)
"""
# Create new settings instance with reset optional fields and merged data

View File

@ -103,11 +103,11 @@
"pvforecast4_userhorizon": null,
"pvforecast_provider": null,
"pvforecastimport_file_path": null,
"server_fastapi_startup_server_fasthtml": true,
"server_fastapi_host": "0.0.0.0",
"server_fastapi_port": 8503,
"server_fasthtml_host": "0.0.0.0",
"server_fasthtml_port": 8504,
"server_eos_startup_eosdash": true,
"server_eos_host": "0.0.0.0",
"server_eos_port": 8503,
"server_eosdash_host": "0.0.0.0",
"server_eosdash_port": 8504,
"weather_provider": null,
"weatherimport_file_path": null
}

View File

@ -129,10 +129,10 @@ def create_error_page(
)
def start_fasthtml_server() -> subprocess.Popen:
def start_eosdash() -> subprocess.Popen:
"""Start the fasthtml server as a subprocess."""
server_process = subprocess.Popen(
[sys.executable, str(server_dir.joinpath("fasthtml_server.py"))],
[sys.executable, str(server_dir.joinpath("eosdash.py"))],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
@ -144,14 +144,14 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
"""Lifespan manager for the app."""
# On startup
if (
config_eos.server_fastapi_startup_server_fasthtml
and config_eos.server_fasthtml_host
and config_eos.server_fasthtml_port
config_eos.server_eos_startup_eosdash
and config_eos.server_eosdash_host
and config_eos.server_eosdash_port
):
try:
fasthtml_process = start_fasthtml_server()
fasthtml_process = start_eosdash()
except Exception as e:
logger.error(f"Failed to start FastHTML server. Error: {e}")
logger.error(f"Failed to start EOSdash server. Error: {e}")
sys.exit(1)
# Handover to application
yield
@ -172,7 +172,7 @@ app = FastAPI(
)
# That's the problem
opt_class = optimization_problem(verbose=bool(config_eos.server_fastapi_verbose))
opt_class = optimization_problem(verbose=bool(config_eos.server_eos_verbose))
server_dir = Path(__file__).parent.resolve()
@ -812,9 +812,9 @@ async def proxy_put(request: Request, path: str) -> Response:
async def proxy(request: Request, path: str) -> Union[Response | RedirectResponse | HTMLResponse]:
if config_eos.server_fasthtml_host and config_eos.server_fasthtml_port:
if config_eos.server_eosdash_host and config_eos.server_eosdash_port:
# Proxy to fasthtml server
url = f"http://{config_eos.server_fasthtml_host}:{config_eos.server_fasthtml_port}/{path}"
url = f"http://{config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}/{path}"
headers = dict(request.headers)
data = await request.body()
@ -834,11 +834,11 @@ async def proxy(request: Request, path: str) -> Union[Response | RedirectRespons
status_code="404",
error_title="Page Not Found",
error_message=f"""<pre>
Application server not reachable: '{url}'
Did you start the application server
or set 'server_fastapi_startup_server_fasthtml'?
EOSdash server not reachable: '{url}'
Did you start the EOSdash server
or set 'server_eos_startup_eosdash'?
If there is no application server intended please
set 'server_fasthtml_host' or 'server_fasthtml_port' to None.
set 'server_eosdash_host' or 'server_eosdash_port' to None.
</pre>
""",
error_details=f"{e}",
@ -855,22 +855,22 @@ set 'server_fasthtml_host' or 'server_fasthtml_port' to None.
return RedirectResponse(url="/docs")
def start_fastapi_server() -> None:
"""Start FastAPI server."""
def start_eos() -> None:
"""Start EOS server."""
try:
uvicorn.run(
app,
host=str(config_eos.server_fastapi_host),
port=config_eos.server_fastapi_port,
host=str(config_eos.server_eos_host),
port=config_eos.server_eos_port,
log_level="debug",
access_log=True,
)
except Exception as e:
logger.error(
f"Could not bind to host {config_eos.server_fastapi_host}:{config_eos.server_fastapi_port}. Error: {e}"
f"Could not bind to host {config_eos.server_eos_host}:{config_eos.server_eos_port}. Error: {e}"
)
sys.exit(1)
if __name__ == "__main__":
start_fastapi_server()
start_eos()

View File

@ -41,20 +41,18 @@ def config_table() -> Table:
@rt("/")
def get(): # type: ignore
return Titled("EOS Config App", H1("Configuration"), config_table())
return Titled("EOS Dashboard", H1("Configuration"), config_table())
if __name__ == "__main__":
try:
logger.info(
f"Starting {config_eos.server_fasthtml_host}:{config_eos.server_fasthtml_port}."
)
logger.info(f"Starting {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}.")
uvicorn.run(
app, host=str(config_eos.server_fasthtml_host), port=config_eos.server_fasthtml_port
app, host=str(config_eos.server_eosdash_host), port=config_eos.server_eosdash_port
)
except Exception as e:
# Error handling for binding issues
logger.error(
f"Could not bind to host {config_eos.server_fasthtml_host}:{config_eos.server_fasthtml_port}. Error: {e}"
f"Could not bind to host {config_eos.server_eosdash_host}:{config_eos.server_eosdash_port}. Error: {e}"
)
exit(1)

View File

@ -17,24 +17,22 @@ class ServerCommonSettings(SettingsBaseModel):
To be added
"""
server_fastapi_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="FastAPI server IP address."
server_eos_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="EOS server IP address."
)
server_fastapi_port: Optional[int] = Field(
default=8503, description="FastAPI server IP port number."
server_eos_port: Optional[int] = Field(default=8503, description="EOS server IP port number.")
server_eos_verbose: Optional[bool] = Field(default=False, description="Enable debug output")
server_eos_startup_eosdash: Optional[bool] = Field(
default=True, description="EOS server to start EOSdash server."
)
server_fastapi_verbose: Optional[bool] = Field(default=False, description="Enable debug output")
server_fastapi_startup_server_fasthtml: Optional[bool] = Field(
default=True, description="FastAPI server to startup application FastHTML server."
server_eosdash_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="EOSdash server IP address."
)
server_fasthtml_host: Optional[IPvAnyAddress] = Field(
default="0.0.0.0", description="FastHTML server IP address."
)
server_fasthtml_port: Optional[int] = Field(
default=8504, description="FastHTML server IP port number."
server_eosdash_port: Optional[int] = Field(
default=8504, description="EOSdash server IP port number."
)
@field_validator("server_fastapi_port", "server_fasthtml_port")
@field_validator("server_eos_port", "server_eosdash_port")
def validate_server_port(cls, value: Optional[int]) -> Optional[int]:
if value is not None and not (1024 <= value <= 49151):
raise ValueError("Server port number must be between 1024 and 49151.")

View File

@ -170,7 +170,7 @@ def server(xprocess, config_eos, config_default_dirs):
# assure server to be installed
try:
subprocess.run(
[sys.executable, "-c", "import akkudoktoreos.server.fastapi_server"],
[sys.executable, "-c", "import akkudoktoreos.server.eos"],
check=True,
env=env,
stdout=subprocess.PIPE,
@ -186,7 +186,7 @@ def server(xprocess, config_eos, config_default_dirs):
)
# command to start server process
args = [sys.executable, "-m", "akkudoktoreos.server.fastapi_server"]
args = [sys.executable, "-m", "akkudoktoreos.server.eos"]
# startup pattern
pattern = "Application startup complete."

View File

@ -17,7 +17,7 @@ def test_openapi_spec_current(config_eos):
with open(expected_spec_path) as f_expected:
expected_spec = json.load(f_expected)
# Patch get_config and import within guard to patch global variables within the fastapi_server module.
# Patch get_config and import within guard to patch global variables within the eos module.
with patch("akkudoktoreos.config.config.get_config", return_value=config_eos):
# Ensure the script works correctly as part of a package
root_dir = Path(__file__).resolve().parent.parent
@ -50,7 +50,7 @@ def test_openapi_md_current(config_eos):
with open(expected_spec_md_path, encoding="utf8") as f_expected:
expected_spec_md = f_expected.read()
# Patch get_config and import within guard to patch global variables within the fastapi_server module.
# Patch get_config and import within guard to patch global variables within the eos module.
with patch("akkudoktoreos.config.config.get_config", return_value=config_eos):
# Ensure the script works correctly as part of a package
root_dir = Path(__file__).resolve().parent.parent
@ -79,7 +79,7 @@ def test_config_md_current(config_eos):
with open(expected_config_md_path, encoding="utf8") as f_expected:
expected_config_md = f_expected.read()
# Patch get_config and import within guard to patch global variables within the fastapi_server module.
# Patch get_config and import within guard to patch global variables within the eos module.
with patch("akkudoktoreos.config.config.get_config", return_value=config_eos):
# Ensure the script works correctly as part of a package
root_dir = Path(__file__).resolve().parent.parent

View File

@ -101,10 +101,10 @@
"pvforecast4_userhorizon": null,
"pvforecast_provider": null,
"pvforecastimport_file_path": null,
"server_fastapi_host": "0.0.0.0",
"server_fastapi_port": 8503,
"server_fasthtml_host": "0.0.0.0",
"server_fasthtml_port": 8504,
"server_eos_host": "0.0.0.0",
"server_eos_port": 8503,
"server_eosdash_host": "0.0.0.0",
"server_eosdash_port": 8504,
"weather_provider": null,
"weatherimport_file_path": null
}