Skip to content

Commit c302727

Browse files
Merge pull request #6 from XKNX/dev-setup-and-publishing
Dev setup and publishing
2 parents c922600 + 8e3b6f2 commit c302727

5 files changed

Lines changed: 68 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
run: |
2727
ruff check .
2828
29+
- name: Type check with Mypy
30+
run: |
31+
mypy src/knx_telegram_store
32+
2933
- name: Run Tests with Pytest
3034
run: |
3135
export PYTHONPATH=src

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
name: Build distribution 📦
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.12"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: python3 -m build
26+
- name: Store the distribution packages
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: python-package-distributions
30+
path: dist/
31+
32+
publish-to-pypi:
33+
name: >-
34+
Publish Python 🐍 distribution 📦 to PyPI
35+
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
36+
needs:
37+
- build
38+
runs-on: ubuntu-latest
39+
environment:
40+
name: pypi
41+
url: https://pypi.org/p/knx-telegram-store
42+
permissions:
43+
id-token: write # IMPORTANT: mandatory for trusted publishing
44+
steps:
45+
- name: Download all the dists
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: python-package-distributions
49+
path: dist/
50+
- name: Publish distribution 📦 to PyPI
51+
uses: pypa/gh-action-pypi-publish@release/v1

pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,34 @@ version = "0.1.0"
88
description = "A standalone, host-agnostic Python library for KNX telegram persistence."
99
readme = "README.md"
1010
requires-python = ">=3.12"
11-
license = {text = "MIT"}
11+
license = "MIT"
1212
authors = [
1313
{name = "Martin Hoefling"}
1414
]
1515
keywords = ["knx", "home-assistant", "persistence", "storage", "telegram"]
1616
classifiers = [
1717
"Development Status :: 3 - Alpha",
1818
"Intended Audience :: Developers",
19-
"License :: OSI Approved :: MIT License",
2019
"Programming Language :: Python :: 3.12",
2120
"Topic :: Home Automation",
2221
"Framework :: AsyncIO",
2322
]
2423
dependencies = []
2524

2625
[project.urls]
27-
Homepage = "https://github.com/martinhoefling/knx-telegram-store"
28-
Bug-Tracker = "https://github.com/martinhoefling/knx-telegram-store/issues"
26+
Homepage = "https://github.com/XKNX/knx-telegram-store"
27+
Bug-Tracker = "https://github.com/XKNX/knx-telegram-store/issues"
28+
29+
[tool.setuptools]
30+
include-package-data = true
2931

3032
[tool.setuptools.packages.find]
3133
where = ["src"]
3234
include = ["knx_telegram_store*"]
3335

36+
[tool.setuptools.package-data]
37+
knx_telegram_store = ["py.typed"]
38+
3439
[project.optional-dependencies]
3540
sqlite = ["aiosqlite>=0.20", "sqlalchemy[asyncio]>=2.0"]
3641
postgres = ["asyncpg>=0.29", "sqlalchemy[asyncio]>=2.0"]
@@ -39,6 +44,7 @@ dev = [
3944
"pytest-asyncio>=0.23",
4045
"pytest-cov>=4.1",
4146
"ruff>=0.3",
47+
"mypy>=1.9",
4248
"aiosqlite>=0.20"
4349
]
4450

src/knx_telegram_store/backends/base_sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def query(self, query: TelegramQuery) -> TelegramQueryResult:
138138
stmt = select(self.telegrams)
139139

140140
# 1. Base Filters
141-
filters = []
141+
filters: list[Any] = []
142142
if query.sources:
143143
filters.append(self.telegrams.c.source.in_(query.sources))
144144
if query.destinations:
@@ -225,7 +225,7 @@ async def query(self, query: TelegramQuery) -> TelegramQueryResult:
225225
for row in rows
226226
]
227227

228-
limit_reached = total_count > (query.offset + query.limit)
228+
limit_reached = (total_count or 0) > (query.offset + query.limit)
229229

230230
return TelegramQueryResult(
231231
telegrams=telegrams,
@@ -236,7 +236,7 @@ async def query(self, query: TelegramQuery) -> TelegramQueryResult:
236236
async def count(self) -> int:
237237
"""Return the total number of stored telegrams."""
238238
async with self.engine.connect() as conn:
239-
return await conn.scalar(select(func.count()).select_from(self.telegrams))
239+
return await conn.scalar(select(func.count()).select_from(self.telegrams)) or 0
240240

241241
async def clear(self) -> None:
242242
"""Remove all stored telegrams."""

src/knx_telegram_store/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)