Skip to content

Commit

Permalink
Merge pull request #231 from BrewBlox/develop
Browse files Browse the repository at this point in the history
Edge release
  • Loading branch information
steersbob authored Feb 23, 2024
2 parents 4ae6378 + 90fe69a commit 23a4066
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Get image metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}

- name: ghcr.io login
uses: docker/login-action@v2
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
Expand All @@ -53,7 +53,7 @@ jobs:
poetry run invoke build
- name: Build Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "buildbot32.local",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
]
}
],
"compounds": []
}
8 changes: 8 additions & 0 deletions brewblox_history/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def create_app() -> FastAPI:
config = utils.get_config()
setup_logging(config.debug)

if config.debugger: # pragma: no cover
import faulthandler
faulthandler.enable()

import debugpy
debugpy.listen(('0.0.0.0', 5678))
LOGGER.info('Debugger is enabled and listening on 5678')

# Call setup functions for modules
mqtt.setup()
redis.setup()
Expand Down
1 change: 1 addition & 0 deletions brewblox_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ServiceConfig(BaseSettings):

name: str = 'history'
debug: bool = False
debugger: bool = False

mqtt_protocol: Literal['mqtt', 'mqtts'] = 'mqtt'
mqtt_host: str = 'eventbus'
Expand Down
3 changes: 1 addition & 2 deletions brewblox_history/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ciso8601
from pytimeparse.timeparse import timeparse

from . import utils
from .models import ServiceConfig

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -137,7 +136,7 @@ def select_timeframe(start: DatetimeSrc_,
`duration` is formatted as `{value}s`.
"""
config = utils.get_config()
config = get_config()
dt_start: datetime | None = None
dt_end: datetime | None = None

Expand Down
2 changes: 1 addition & 1 deletion parse_appenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_cmd_args(raw_args: list[str]) -> tuple[argparse.Namespace, list[str]]:
args, unknown = parse_cmd_args(sys.argv[1:])
if unknown:
print(f'WARNING: ignoring unknown CMD arguments: {unknown}', file=sys.stderr)
output = [f'brewblox_{k}={shlex.quote(str(v))}'
output = [f'brewblox_history_{k}={shlex.quote(str(v))}'
for k, v in vars(args).items()
if v is not None and v is not False]
print(*output, sep='\n')
51 changes: 39 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ pytimeparse = "^1.1.8"
redis = "^5.0.0"
ujson = "^5.8.0"
sortedcontainers = "^2.4.0"
fastapi = "^0.104.1"
fastapi = "^0.109.1"
uvicorn = { extras = ["standard"], version = "^0.24.0.post1" }
pydantic-settings = "^2.1.0"
fastapi-mqtt = "^2.0.0"
httpx = "^0.25.2"
websockets = "^12.0"
debugpy = "^1.8.0"

[tool.poetry.group.dev.dependencies]
pytest-cov = "*"
Expand Down
8 changes: 4 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import asyncio
import logging
from collections.abc import Generator
from pathlib import Path
from typing import AsyncGenerator, Generator

import pytest
from asgi_lifespan import LifespanManager
Expand Down Expand Up @@ -56,7 +56,7 @@ def config(monkeypatch: pytest.MonkeyPatch,
cfg = TestConfig(
debug=True,
mqtt_host='localhost',
mqtt_port=docker_services.port_for('mqtt', 1883),
mqtt_port=docker_services.port_for('eventbus', 1883),
redis_host='localhost',
redis_port=docker_services.port_for('redis', 6379),
victoria_host='localhost',
Expand Down Expand Up @@ -101,7 +101,7 @@ def app() -> FastAPI:


@pytest.fixture
async def manager(app: FastAPI) -> Generator[LifespanManager, None, None]:
async def manager(app: FastAPI) -> AsyncGenerator[LifespanManager, None]:
"""
AsyncClient does not automatically send ASGI lifespan events to the app
https://asgi.readthedocs.io/en/latest/specs/lifespan.html
Expand All @@ -115,7 +115,7 @@ async def manager(app: FastAPI) -> Generator[LifespanManager, None, None]:


@pytest.fixture
async def client(app: FastAPI, manager: LifespanManager) -> Generator[AsyncClient, None, None]:
async def client(app: FastAPI, manager: LifespanManager) -> AsyncGenerator[AsyncClient, None]:
"""
The default test client for making REST API calls.
Using this fixture will also guarantee that lifespan startup has happened.
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
mqtt:
eventbus:
image: ghcr.io/brewblox/mosquitto:develop
ports:
- "1883"
Expand Down

0 comments on commit 23a4066

Please sign in to comment.