Skip to content

Commit

Permalink
Merge pull request #10 from wlatanowicz/wl/asyncio
Browse files Browse the repository at this point in the history
asyncio
  • Loading branch information
wlatanowicz authored Mar 21, 2023
2 parents c7ea052 + fee191c commit cde5c7e
Show file tree
Hide file tree
Showing 70 changed files with 1,132 additions and 848 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ jobs:
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Cache python packages
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: test-python-packages
with:
Expand All @@ -36,12 +37,21 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements/tests.txt --user
pip install black==22.3.0
pip install -r requirements/types.txt --user
pip install -r requirements/lint.txt --user
- name: Check with black
run: |
python -m black --check indi
- name: Check with isort
run: |
python -m isort --profile black indi
- name: Check with mypy
run: |
python -m mypy indi
- name: Test with pytest
run: |
python -m pytest tests
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog

## 0.4.0

Goodbye threads. Welcome async.

### Features

* Dropped internal threads in favor of async coroutines.
* Event callback functions can be declared as either normal function or coroutine functions


### Breaking changes

* Removed `non_blocking` decorator.
* Both server and client entrypoint are coroutines now. The have to be run in asyncio loop ie. with `asyncio.run()`.

### Fixes

* Fixed a lot of type annotations
* Fixes in logging

## 0.3.0

Enables device cooperation while running in the same INDI server environment.

### Features

* Support for pings.
* Support for device snooping.

### Fixes

* Ignore GetProperties message with unknown device name.
* Fix formatting of xml messages (added declaration and trailing NL).
2 changes: 1 addition & 1 deletion QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Examples above assume that device drivers are located in `devices` module. Let's
```
import logging
from indi.device import Driver, non_blocking, properties
from indi.device import Driver, properties
from indi.device.pool import default_pool
from indi.device.events import on, Change
Expand Down
3 changes: 2 additions & 1 deletion docker-examples/client/simple_events/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.7-slim
ARG PYTHON_VERSION=3.8
FROM python:${PYTHON_VERSION}-slim

RUN apt-get -y update \
&& apt-get -y install git \
Expand Down
69 changes: 53 additions & 16 deletions docker-examples/client/simple_events/client.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
import os
import asyncio
from logging import config

from indi.client import elements
from indi.client.client import Client
from indi.message import const
from indi.transport.client import TCP


host = os.environ.get("INDISERVER_HOST", "indiserver")
port = int(os.environ.get("INDISERVER_PORT", 7624))

control_connection = TCP(host, port)
blob_connection = TCP(host, port)

def client_callback(event):
print(event)


client = Client(control_connection, blob_connection)
client.onevent(callback=client_callback)
client.start()

while True:
pass
def configure_logging():
config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "[%(asctime)s] %(levelname)s:%(name)s: %(message)s"
},
},
"handlers": {
"console": {
"level": os.environ.get("LOG_LEVEL", "INFO"),
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"loggers": {
"": {
"level": "DEBUG",
"handlers": [
"console",
],
},
},
}
)


async def main_loop():
host = os.environ.get("INDISERVER_HOST", "indiserver")
port = int(os.environ.get("INDISERVER_PORT", 7624))

control_connection = TCP(host, port)
blob_connection = TCP(host, port)

def client_callback(event):
print(event)

client = Client(control_connection, blob_connection)
client.onevent(callback=client_callback)

await client.start()

while True:
await asyncio.sleep(100)


if __name__ == "__main__":
configure_logging()
asyncio.run(main_loop())
1 change: 1 addition & 0 deletions docker-examples/client/simple_events/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
context: .
args:
INDIPY_BRANCH: master
PYTHON_VERSION: 3.8
tty: true
stdin_open: true
environment:
Expand Down
3 changes: 2 additions & 1 deletion docker-examples/client/simple_routine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.7-slim
ARG PYTHON_VERSION=3.8
FROM python:${PYTHON_VERSION}-slim

RUN apt-get -y update \
&& apt-get -y install git \
Expand Down
Loading

0 comments on commit cde5c7e

Please sign in to comment.