Skip to content

Commit

Permalink
Merge pull request #25 from dapper91/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dapper91 authored Jul 28, 2021
2 parents 6fd3da3 + 879cc01 commit 048938d
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 55 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: release

on:
release:
types:
- released

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist
twine upload dist/*
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: test

on:
pull_request:
branches:
- dev
- master
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv --upgrade
pipenv install --python ${{ matrix.python-version }} --dev
- name: Run linter
run: pipenv run flake8 .
- name: Run tests
run: PYTHONPATH="$(pwd):$PYTHONPATH" pipenv run py.test --cov=pjrpc --cov-report=xml tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
fail_ci_if_error: true
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.0.1
hooks:
- id: check-docstring-first
stages:
Expand All @@ -27,7 +27,7 @@ repos:
stages:
- commit
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5
rev: v1.5.7
hooks:
- id: autopep8
stages:
Expand All @@ -37,14 +37,14 @@ repos:
- --max-line-length=120
- --diff
- repo: https://github.com/asottile/add-trailing-comma
rev: v1.5.0
rev: v2.1.0
hooks:
- id: add-trailing-comma
stages:
- commit
- push
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.9.2
hooks:
- id: flake8
stages:
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.2.2 (2021-07-28)
------------------

- pydantic validation schema bug fixed
- method registry merge bug fixed
- method view validation bug fixed
- method metadata format changed


1.2.1 (2021-03-02)
------------------
Expand Down
4 changes: 1 addition & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ httpx = "~=0.0"
aioresponses = "~=0.0"
asynctest = "~=0.12"
codecov = "~=2.0"
flake8 = "~=3.0"
pre-commit = "~=2.0"
pytest = "~=6.0"
pytest-mock = "~=3.0"
pytest-aiohttp = "~=0.0"
pytest-cov = "~=2.0"
responses = "~=0.0"
respx = "~=0.0"

[requires]
python_version = "3.8"
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Features:
- intuitive api
- extendability
- synchronous and asynchronous client backed
- synchronous and asynchronous server support
- popular frameworks integration
- builtin parameter validation
- pytest integration
Expand Down Expand Up @@ -66,7 +67,7 @@ Quickstart
Client requests
_______________

The way of using ``pjrpc`` clients is very simple and intuitive. Methods may be called by name, using proxy object
``pjrpc`` client interface is very simple and intuitive. Methods may be called by name, using proxy object
or by sending handmade ``pjrpc.common.Request`` class object. Notification requests can be made using
``pjrpc.client.AbstractClient.notify`` method or by sending a ``pjrpc.common.Request`` object without id.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/pjrpc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Quick start
Client requests
_______________

The way of using ``pjrpc`` clients is very simple and intuitive. Methods may be called by name, using proxy object
``pjrpc`` client interface is very simple and intuitive. Methods may be called by name, using proxy object
or by sending handmade :py:class:`pjrpc.common.Request` class object. Notification requests can be made using
:py:meth:`pjrpc.client.AbstractClient.notify` method or by sending a :py:class:`pjrpc.common.Request` object without id.

Expand Down
6 changes: 5 additions & 1 deletion docs/source/pjrpc/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ registry and run the server:
Class-based view
----------------

``pjrpc`` has a support of class-based method handlers:
``pjrpc`` has a support of class-based method handlers.

Class-based method view can be added to the registry using :py:meth:`pjrpc.server.MethodRegistry.view` decorator.
Class should implement `__method__` method returning a list of methods to be exposed or inherit
it from :py:class:`pjrpc.server.ViewMixin` which exposes all public ones.


.. code-block:: python
Expand Down
4 changes: 2 additions & 2 deletions examples/server_prometheus_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ async def active_count_metric_middleware(request: pjrpc.Request, context: web.Re


async def any_error_handler(
request: pjrpc.Request, context: web.Request, error: pjrpc.exceptions.JsonRpcError
request: pjrpc.Request, context: web.Request, error: pjrpc.exceptions.JsonRpcError,
) -> pjrpc.exceptions.JsonRpcError:
method_error_count.labels(method=request.method, code=error.code).inc()

return error


async def validation_error_handler(
request: pjrpc.Request, context: web.Request, error: pjrpc.exceptions.JsonRpcError
request: pjrpc.Request, context: web.Request, error: pjrpc.exceptions.JsonRpcError,
) -> pjrpc.exceptions.JsonRpcError:
print("validation error occurred")

Expand Down
2 changes: 1 addition & 1 deletion pjrpc/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Extensible JSON-RPC library'
__url__ = 'https://github.com/dapper91/pjrpc'

__version__ = '1.2.1'
__version__ = '1.2.2'

__author__ = 'Dmitry Pershin'
__email__ = '[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion pjrpc/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def default(self, o: Any) -> Any:
return super().default(o)


Json = Union['Json', str, int, float, dict, bool, list, tuple, set, None]
Json = Union[str, int, float, dict, bool, list, tuple, set, None]
16 changes: 8 additions & 8 deletions pjrpc/common/v20.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def from_json(cls, json_data: Json, error_cls: Type[JsonRpcError] = JsonRpcError

try:
if not isinstance(json_data, dict):
raise DeserializationError(f"data must be of type dict")
raise DeserializationError("data must be of type dict")

jsonrpc = json_data['jsonrpc']
if jsonrpc != cls.version:
Expand Down Expand Up @@ -192,23 +192,23 @@ def from_json(cls, json_data: Json) -> 'Request':

try:
if not isinstance(json_data, dict):
raise DeserializationError(f"data must be of type dict")
raise DeserializationError("data must be of type dict")

jsonrpc = json_data['jsonrpc']
if jsonrpc != cls.version:
raise DeserializationError(f"jsonrpc version '{json_data['jsonrpc']}' is not supported")

id = json_data.get('id')
if id is not None and not isinstance(id, (int, str)):
raise DeserializationError(f"field 'id' must be of type integer or string")
raise DeserializationError("field 'id' must be of type integer or string")

method = json_data['method']
if not isinstance(method, str):
raise DeserializationError(f"field 'method' must be of type string")
raise DeserializationError("field 'method' must be of type string")

params = json_data.get('params', [])
if not isinstance(params, (list, dict)):
raise DeserializationError(f"field 'params' must be of type list or dict")
raise DeserializationError("field 'params' must be of type list or dict")

return cls(method, params, id)
except KeyError as e:
Expand Down Expand Up @@ -322,7 +322,7 @@ def from_json(cls, json_data: Json, error_cls: Type[JsonRpcError] = JsonRpcError
return cls(error=error_cls.from_json(json_data['error']))

if not isinstance(json_data, (list, tuple)):
raise DeserializationError(f"data must be of type list")
raise DeserializationError("data must be of type list")

except KeyError as e:
raise DeserializationError(f"required field {e} not found") from e
Expand Down Expand Up @@ -501,10 +501,10 @@ def from_json(cls, data: Json) -> 'BatchRequest':
"""

if not isinstance(data, (list, tuple)):
raise DeserializationError(f"data must be of type list")
raise DeserializationError("data must be of type list")

if len(data) == 0:
raise DeserializationError(f"request list is empty")
raise DeserializationError("request list is empty")

return cls(*(Request.from_json(request) for request in data))

Expand Down
Loading

0 comments on commit 048938d

Please sign in to comment.