generated from pufereq/python-template
Compare commits
11 Commits
dd4b8b0eb2
...
0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c25ee1ebdf | ||
|
ffc4ed1897
|
|||
|
bc1bf46388
|
|||
|
9b5b104061
|
|||
|
|
cccda80784 | ||
|
fd070b1763
|
|||
|
df55e0c5cb
|
|||
|
762d09ea9b
|
|||
|
b90653b3fd
|
|||
|
|
180e7e4c02 | ||
|
8af71dd552
|
104
.github/workflows/commit_checks.yaml
vendored
104
.github/workflows/commit_checks.yaml
vendored
@@ -1,104 +0,0 @@
|
|||||||
name: Commit Checks
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: 🔀 checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
submodules: 'recursive'
|
|
||||||
|
|
||||||
- name: 📦 install uv
|
|
||||||
uses: astral-sh/setup-uv@v5
|
|
||||||
|
|
||||||
- name: 🐍 python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version-file: "pyproject.toml"
|
|
||||||
|
|
||||||
- name: 📦 sync depedencies
|
|
||||||
run: |
|
|
||||||
uv sync
|
|
||||||
uv sync --group test
|
|
||||||
|
|
||||||
- name: 🧪 run tests
|
|
||||||
id: test
|
|
||||||
run: |
|
|
||||||
uv run pytest -v
|
|
||||||
coverage:
|
|
||||||
name: Check coverage
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: 🔀 checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
submodules: 'recursive'
|
|
||||||
|
|
||||||
- name: 📦 install uv
|
|
||||||
uses: astral-sh/setup-uv@v5
|
|
||||||
|
|
||||||
- name: 🐍 python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version-file: "pyproject.toml"
|
|
||||||
|
|
||||||
- name: 📦 sync depedencies
|
|
||||||
run: |
|
|
||||||
uv sync
|
|
||||||
uv sync --group test
|
|
||||||
|
|
||||||
- name: 🧪 run tests
|
|
||||||
id: test
|
|
||||||
run: |
|
|
||||||
uv run pytest -v --cov
|
|
||||||
|
|
||||||
- name: 📊 generate coverage report
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
uv run coverage json
|
|
||||||
cov_percent=$(jq '.totals.percent_covered' coverage.json)
|
|
||||||
cov_percent_rounded=$(python3 -c "print(round(${cov_percent}, 2))")
|
|
||||||
cov_lines=$(jq '.totals.covered_lines' coverage.json)
|
|
||||||
cov_missing=$(jq '.totals.missing_lines' coverage.json)
|
|
||||||
cov_total=$(jq '.totals.num_statements' coverage.json)
|
|
||||||
cov_excluded=$(jq '.totals.excluded_lines' coverage.json)
|
|
||||||
report_success=$(python3 -c "print(str(${cov_percent} == 100).lower())")
|
|
||||||
|
|
||||||
if (( $(echo "$cov_percent >= 100" | bc -l) )); then
|
|
||||||
badge_color="brightgreen"
|
|
||||||
elif (( $(echo "$cov_percent >= 90" | bc -l) )); then
|
|
||||||
badge_color="yellow"
|
|
||||||
else
|
|
||||||
badge_color="red"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "## 📊 Coverage Report" >> $GITHUB_STEP_SUMMARY
|
|
||||||
|
|
||||||
echo "" >> $GITHUB_STEP_SUMMARY
|
|
||||||
|
|
||||||
echo "| Total Lines | Covered | Missing | Excluded |" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "|-------------|---------|---------|----------|" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "| $cov_total | $cov_lines | $cov_missing | $cov_excluded |" >> $GITHUB_STEP_SUMMARY
|
|
||||||
|
|
||||||
echo "<details>" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "<summary>Details</summary>" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo '' >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
||||||
uv run coverage report >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo '' >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "</details>" >> $GITHUB_STEP_SUMMARY
|
|
||||||
48
.github/workflows/pr_checks.yaml
vendored
48
.github/workflows/pr_checks.yaml
vendored
@@ -1,48 +0,0 @@
|
|||||||
name: PR Checks
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
comment_coverage:
|
|
||||||
name: Comment coverage on PR
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: 🔀 checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
submodules: 'recursive'
|
|
||||||
|
|
||||||
- name: 📦 install uv
|
|
||||||
uses: astral-sh/setup-uv@v5
|
|
||||||
|
|
||||||
- name: 🐍 python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version-file: "pyproject.toml"
|
|
||||||
|
|
||||||
- name: 📦 sync depedencies
|
|
||||||
run: |
|
|
||||||
uv sync
|
|
||||||
uv sync --group test
|
|
||||||
|
|
||||||
|
|
||||||
- name: configure git
|
|
||||||
run: |
|
|
||||||
git config --global user.name "github-actions[bot]"
|
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
|
|
||||||
- name: 🧪 run coverage
|
|
||||||
run: |
|
|
||||||
uv run pytest --cov --junitxml=pytest.xml --cov-report=term-missing | tee pytest-coverage.txt
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: 📊 comment coverage
|
|
||||||
uses: MishaKav/pytest-coverage-comment@main
|
|
||||||
with:
|
|
||||||
pytest-coverage-path: pytest-coverage.txt
|
|
||||||
junitxml-path: pytest.xml
|
|
||||||
41
CHANGELOG.md
Normal file
41
CHANGELOG.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.3.0] - 2025-09-23
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [`ffc4ed1`](https://gitea.pufereq.pl/judas/judas_protocol/commit/ffc4ed18974e89c6f1f5554d9e8832065432310a) **message.py**: add `__str__` and `__repr__` methods
|
||||||
|
- [`bc1bf46`](https://gitea.pufereq.pl/judas/judas_protocol/commit/bc1bf46388eb904738893a2f86b5050b4ce2489e) **message.py**: raise ValueError if invalid json in `Message.from_bytes()`
|
||||||
|
|
||||||
|
### Styling
|
||||||
|
|
||||||
|
- [`9b5b104`](https://gitea.pufereq.pl/judas/judas_protocol/commit/9b5b104061859b2dd4ab93258414edd8ce34b4a7) **message.py**: organize imports
|
||||||
|
|
||||||
|
## [0.2.0] - 2025-08-29
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [`fd070b1`](https://gitea.pufereq.pl/judas/judas_protocol/commit/fd070b176347a0f7b81f937b189d8f50736f3514) **message.py**: add `b"\n"` at end of data from `to_bytes()`
|
||||||
|
- [`df55e0c`](https://gitea.pufereq.pl/judas/judas_protocol/commit/df55e0c5cba00c6d08b98cf09f265c130bc11f73) **message.py**: add `Message.from_bytes()`
|
||||||
|
- [`762d09e`](https://gitea.pufereq.pl/judas/judas_protocol/commit/762d09ea9b3e28efdfdd2ac0674bb874154b41a9) **message.py**: add `Message.to_bytes()`
|
||||||
|
- [`b90653b`](https://gitea.pufereq.pl/judas/judas_protocol/commit/b90653b3fd90957a0056dcd803da20a78a589314) **__init__.py**: add public api
|
||||||
|
|
||||||
|
## [0.1.0] - 2025-08-28
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [`dd4b8b0`](https://gitea.pufereq.pl/judas/judas_protocol/commit/dd4b8b0eb2ead66e449c93ae9c5222288774ad2a) **message.py**: add `Message` class
|
||||||
|
- [`5e3ed0f`](https://gitea.pufereq.pl/judas/judas_protocol/commit/5e3ed0fe0f1c7a15bd50b4fb5b563791c00ae0b8) **types.py**: add types.py
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- [`8af71dd`](https://gitea.pufereq.pl/judas/judas_protocol/commit/8af71dd55265a006803d1ea0a58cbd5746f5de5a) remove irrelevant workflows
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
- [`4cf669c`](https://gitea.pufereq.pl/judas/judas_protocol/commit/4cf669c373c973d1ebefbf3a1d22d43e06ee6596) **uv.lock**: add lockfile
|
||||||
|
- [`0fc7994`](https://gitea.pufereq.pl/judas/judas_protocol/commit/0fc7994e9de2bb50b9fa48bdeb1707ba725d0932) **pyproject.toml**: configure basedpyright to ignore Any
|
||||||
|
|
||||||
|
<!-- generated by git-cliff -->
|
||||||
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "judas_protocol"
|
name = "judas_protocol"
|
||||||
version = "0.1.0"
|
version = "0.3.0"
|
||||||
description = "The judas protocol"
|
description = "The judas protocol"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = []
|
authors = []
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
__version__: str = "0.1.0"
|
__version__: str = "0.1.0"
|
||||||
|
|
||||||
|
from .message import Message
|
||||||
|
from .types import Category, ControlAction
|
||||||
|
|
||||||
|
__all__ = ["__version__", "Message", "Category", "ControlAction"]
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
import json
|
import json
|
||||||
from typing import Any
|
from enum import Enum
|
||||||
|
from typing import Any, override
|
||||||
|
|
||||||
from judas_protocol.types import Category, ControlAction
|
from judas_protocol.types import Category, ControlAction
|
||||||
|
|
||||||
@@ -28,6 +28,14 @@ class Message:
|
|||||||
self.action: Enum = action
|
self.action: Enum = action
|
||||||
self.payload: dict[str, Any] = payload or {}
|
self.payload: dict[str, Any] = payload or {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"Message [{self.category.name}] {self.action.name} - {self.payload}"
|
||||||
|
|
||||||
|
@override
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Message(category={self.category}, action={self.action}, payload={self.payload})"
|
||||||
|
|
||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
"""Convert the message to a dictionary.
|
"""Convert the message to a dictionary.
|
||||||
|
|
||||||
@@ -48,6 +56,14 @@ class Message:
|
|||||||
"""
|
"""
|
||||||
return json.dumps(self.to_dict())
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
def to_bytes(self) -> bytes:
|
||||||
|
"""Convert the message to bytes.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bytes: The message as bytes.
|
||||||
|
"""
|
||||||
|
return self.to_json().encode("utf-8") + b"\n"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict[str, Any]) -> Message:
|
def from_dict(cls, data: dict[str, Any]) -> Message:
|
||||||
"""Create a Message from a dictionary.
|
"""Create a Message from a dictionary.
|
||||||
@@ -79,7 +95,23 @@ class Message:
|
|||||||
Returns:
|
Returns:
|
||||||
Message: The created message.
|
Message: The created message.
|
||||||
"""
|
"""
|
||||||
return cls.from_dict(json.loads(data))
|
try:
|
||||||
|
json_data = json.loads(data)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise ValueError("Invalid JSON data") from e
|
||||||
|
|
||||||
|
return cls.from_dict(json_data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_bytes(cls, data: bytes) -> Message:
|
||||||
|
"""Create a Message from bytes.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data (bytes): The bytes to create the message from.
|
||||||
|
Returns:
|
||||||
|
Message: The created message.
|
||||||
|
"""
|
||||||
|
return cls.from_json(data.decode("utf-8"))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ack(cls) -> Message:
|
def ack(cls) -> Message:
|
||||||
|
|||||||
Reference in New Issue
Block a user