Skip to content

Commit a0cac63

Browse files
authored
Merge pull request #19 from taskiq-python/feature/releases
Package updated to be ready to be published on pypi.
2 parents 3f069ef + 1241545 commit a0cac63

File tree

8 files changed

+97
-54
lines changed

8 files changed

+97
-54
lines changed

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release python package
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: "3.9"
17+
- name: Install deps
18+
uses: knowsuchagency/poetry-install@v1
19+
env:
20+
POETRY_VIRTUALENVS_CREATE: false
21+
- name: Release package
22+
env:
23+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
24+
run: poetry publish --build

.github/workflows/test.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,23 @@ jobs:
4646
- name: Run mypy check
4747
run: poetry run mypy .
4848
pytest:
49-
runs-on: ubuntu-latest
49+
strategy:
50+
matrix:
51+
py_version: ["3.7", "3.8", "3.9", "3.10"]
52+
os: [ubuntu-latest, windows-latest]
53+
runs-on: "${{ matrix.os }}"
5054
steps:
5155
- uses: actions/checkout@v2
5256
- name: Set up Python
5357
uses: actions/setup-python@v2
5458
with:
55-
python-version: "3.9"
59+
python-version: "${{ matrix.py_version }}"
60+
- name: Update pip
61+
run: python -m pip install -U pip
62+
- name: Install poetry
63+
run: python -m pip install poetry
5664
- name: Install deps
57-
uses: knowsuchagency/poetry-install@v1
65+
run: poetry install
5866
env:
5967
POETRY_VIRTUALENVS_CREATE: false
6068
- name: Run pytest check

poetry.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq"
3-
version = "0.1.1"
3+
version = "0.0.1"
44
description = "Asynchronous task queue with async support"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
maintainers = ["Pavel Kirilin <[email protected]>"]

taskiq/brokers/inmemory_broker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ def __init__(
9898
self.executor = ThreadPoolExecutor(max_workers=sync_tasks_pool_size)
9999
self.cast_types = cast_types
100100
if logs_format is None:
101-
logs_format = "%(levelname)s %(message)s"
101+
logs_format = (
102+
"[%(asctime)s]"
103+
"[%(levelname)-7s]"
104+
"[%(module)s:%(funcName)s:%(lineno)d] "
105+
"%(message)s"
106+
)
102107
self.logs_format = logs_format
103108

104109
async def kick(self, message: BrokerMessage) -> None:

taskiq/cli/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TaskiqArgs:
2020

2121
broker: str
2222
tasks_pattern: str
23-
modules: list[str]
23+
modules: List[str]
2424
fs_discover: bool
2525
log_level: str
2626
workers: int

taskiq/cli/async_task_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from taskiq.abc.broker import AsyncBroker
1414
from taskiq.cli.args import TaskiqArgs
15-
from taskiq.cli.log_collector import LogsCollector
15+
from taskiq.cli.log_collector import log_collector
1616
from taskiq.message import TaskiqMessage
1717
from taskiq.result import TaskiqResult
1818

@@ -131,7 +131,7 @@ async def run_task( # noqa: WPS210
131131
returned = None
132132
# Captures function's logs.
133133
parse_params(signature, message)
134-
with LogsCollector(logs, log_collector_format):
134+
with log_collector(logs, log_collector_format):
135135
start_time = time()
136136
try:
137137
if asyncio.iscoroutinefunction(target):
@@ -162,7 +162,7 @@ async def run_task( # noqa: WPS210
162162
)
163163

164164

165-
def exit_process(task: asyncio.Task[Any]) -> NoReturn:
165+
def exit_process(task: "asyncio.Task[Any]") -> NoReturn:
166166
"""
167167
This function exits from the current process.
168168

taskiq/cli/log_collector.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import logging
22
import sys
3-
from contextlib import AbstractContextManager
4-
from typing import Any, List, TextIO
3+
from contextlib import contextmanager
4+
from typing import Generator, List, TextIO
55

66

7-
class LogsCollector(AbstractContextManager[TextIO]):
7+
@contextmanager
8+
def log_collector(
9+
new_target: TextIO,
10+
custom_format: str,
11+
) -> "Generator[TextIO, None, None]":
812
"""
913
Context manager to collect logs.
1014
@@ -15,27 +19,29 @@ class LogsCollector(AbstractContextManager[TextIO]):
1519
It can be used like this:
1620
1721
>>> logs = io.StringIO()
18-
>>> with LogsCollector(logs):
22+
>>> with log_collector(logs, "%(levelname)s %(message)s"):
1923
>>> print("A")
2024
>>>
2125
>>> print(f"Collected logs: {logs.get_value()}")
22-
"""
2326
24-
def __init__(self, new_target: TextIO, custom_format: str):
25-
self._new_target = new_target
26-
self._old_targets: List[TextIO] = []
27-
self._log_handler = logging.StreamHandler(new_target)
28-
self._log_handler.setFormatter(logging.Formatter(custom_format))
29-
30-
def __enter__(self) -> TextIO:
31-
self._old_targets.append(sys.stdout)
32-
self._old_targets.append(sys.stderr)
33-
logging.root.addHandler(self._log_handler)
34-
sys.stdout = self._new_target
35-
sys.stderr = self._new_target
36-
return self._new_target
37-
38-
def __exit__(self, *_args: Any, **_kwargs: Any) -> None:
39-
sys.stderr = self._old_targets.pop()
40-
sys.stdout = self._old_targets.pop()
41-
logging.root.removeHandler(self._log_handler)
27+
:param new_target: new target for logs. All
28+
logs are written in new_target.
29+
:param custom_format: custom format for
30+
collected logging calls.
31+
:yields: new target.
32+
"""
33+
old_targets: "List[TextIO]" = []
34+
log_handler = logging.StreamHandler(new_target)
35+
log_handler.setFormatter(logging.Formatter(custom_format))
36+
37+
old_targets.extend([sys.stdout, sys.stderr])
38+
logging.root.addHandler(log_handler)
39+
sys.stdout = new_target
40+
sys.stderr = new_target
41+
42+
try:
43+
yield new_target
44+
finally:
45+
sys.stderr = old_targets.pop()
46+
sys.stdout = old_targets.pop()
47+
logging.root.removeHandler(log_handler)

0 commit comments

Comments
 (0)