Skip to content

Commit

Permalink
Initial (#1)
Browse files Browse the repository at this point in the history
* Initial
* rename license
* add tests
* add example
* fix actions file
* linter fixes
* update patio
* add coveralls
  • Loading branch information
mosquito committed Jun 8, 2023
1 parent cde81cc commit 624e48c
Show file tree
Hide file tree
Showing 12 changed files with 1,470 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .editorconfig
@@ -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
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
@@ -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
144 changes: 144 additions & 0 deletions .gitignore
@@ -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
2 changes: 1 addition & 1 deletion LICENSE → COPYING
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 patio-python
Copyright (c) 2023 Dmitry Orlov <twig-curfews-0e@icloud.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
70 changes: 70 additions & 0 deletions README.md
@@ -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())

```
23 changes: 23 additions & 0 deletions examples/multiplication-producer.py
@@ -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())
27 changes: 27 additions & 0 deletions examples/multiplication-worker.py
@@ -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())

0 comments on commit 624e48c

Please sign in to comment.