Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial * rename license * add tests * add example * fix actions file * linter fixes * update patio * add coveralls
- Loading branch information
Showing
12 changed files
with
1,470 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{py,yml}] | ||
indent_style = space | ||
|
||
[*.py] | ||
indent_size = 4 | ||
|
||
[docs/**.py] | ||
max_line_length = 80 | ||
|
||
[*.rst] | ||
indent_size = 3 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[*.yml] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
pylama: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup python3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- run: python -m pip install poetry==1.4.0 | ||
- run: poetry install | ||
- run: poetry run pylama | ||
env: | ||
FORCE_COLOR: 1 | ||
mypy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup python3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- run: python -m pip install poetry | ||
- run: poetry install -vvvv | ||
- run: poetry run mypy | ||
env: | ||
FORCE_COLOR: 1 | ||
|
||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
|
||
matrix: | ||
python: | ||
- '3.8' | ||
- '3.9' | ||
- '3.10' | ||
- '3.11' | ||
|
||
services: | ||
rabbitmq: | ||
image: docker://rabbitmq | ||
ports: | ||
- 5672:5672 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup python${{ matrix.python }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "${{ matrix.python }}" | ||
- run: python -m pip install poetry | ||
- run: poetry install -vvvv | ||
- run: >- | ||
poetry run pytest \ | ||
-vv \ | ||
--cov=patio_rabbitmq \ | ||
--cov-report=term-missing \ | ||
--doctest-modules \ | ||
--aiomisc-test-timeout=30 \ | ||
tests | ||
env: | ||
FORCE_COLOR: 1 | ||
- run: poetry run coveralls | ||
env: | ||
COVERALLS_PARALLEL: 'true' | ||
COVERALLS_SERVICE_NAME: github | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
finish: | ||
needs: | ||
- tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Coveralls Finished | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.github_token }} | ||
parallel-finished: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### VirtualEnv template | ||
# Virtualenv | ||
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ | ||
.Python | ||
[Bb]in | ||
[Ii]nclude | ||
[Ll]ib | ||
[Ll]ib64 | ||
[Ll]ocal | ||
[Ss]cripts | ||
pyvenv.cfg | ||
.venv | ||
pip-selfcheck.json | ||
### IPythonNotebook template | ||
# Temporary data | ||
.ipynb_checkpoints/ | ||
### Python template | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
docs/source/apidoc | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# IPython Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pytest | ||
.pytest_cache | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/ | ||
.vscode/ | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
/htmlcov | ||
/temp | ||
.DS_Store | ||
.*cache | ||
.nox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
PATIO Rabbitmq | ||
============== | ||
|
||
PATIO is an acronym for **P**ython **A**synchronous **T**ask for Async**IO**. | ||
|
||
This package provides RabbitMQ broker implementation. | ||
|
||
Example | ||
------- | ||
|
||
### Task executor | ||
|
||
```python | ||
import asyncio | ||
import operator | ||
from functools import reduce | ||
|
||
from patio import Registry, ThreadPoolExecutor | ||
|
||
from patio_rabbitmq import RabbitMQBroker | ||
|
||
|
||
rpc = Registry(project="patio-rabbitmq", auto_naming=False) | ||
|
||
|
||
@rpc("mul") | ||
def mul(*args): | ||
return reduce(operator.mul, args) | ||
|
||
|
||
async def main(): | ||
async with ThreadPoolExecutor(rpc, max_workers=16) as executor: | ||
async with RabbitMQBroker( | ||
executor, amqp_url="amqp://guest:guest@localhost/", | ||
) as broker: | ||
await broker.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
``` | ||
|
||
### Task producer | ||
|
||
```python | ||
import asyncio | ||
|
||
from patio import NullExecutor, Registry | ||
|
||
from patio_rabbitmq import RabbitMQBroker | ||
|
||
|
||
async def main(): | ||
async with NullExecutor(Registry(project="patio-rabbitmq")) as executor: | ||
async with RabbitMQBroker( | ||
executor, amqp_url="amqp://guest:guest@localhost/", | ||
) as broker: | ||
print( | ||
await asyncio.gather( | ||
*[ | ||
broker.call("mul", i, i, timeout=1) for i in range(10) | ||
] | ||
), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import asyncio | ||
|
||
from patio import NullExecutor, Registry | ||
|
||
from patio_rabbitmq import RabbitMQBroker | ||
|
||
|
||
async def main(): | ||
async with NullExecutor(Registry(project="patio-rabbitmq")) as executor: | ||
async with RabbitMQBroker( | ||
executor, amqp_url="amqp://guest:guest@localhost/", | ||
) as broker: | ||
print( | ||
await asyncio.gather( | ||
*[ | ||
broker.call("mul", i, i, timeout=1) for i in range(10) | ||
] | ||
), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import asyncio | ||
import operator | ||
from functools import reduce | ||
|
||
from patio import Registry, ThreadPoolExecutor | ||
|
||
from patio_rabbitmq import RabbitMQBroker | ||
|
||
|
||
rpc = Registry(project="patio-rabbitmq", auto_naming=False) | ||
|
||
|
||
@rpc("mul") | ||
def mul(*args): | ||
return reduce(operator.mul, args) | ||
|
||
|
||
async def main(): | ||
async with ThreadPoolExecutor(rpc, max_workers=16) as executor: | ||
async with RabbitMQBroker( | ||
executor, amqp_url="amqp://guest:guest@localhost/", | ||
) as broker: | ||
await broker.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Oops, something went wrong.