Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #94

Merged
merged 19 commits into from
Aug 10, 2023
Merged

Dev #94

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_stages:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -25,25 +25,25 @@ repos:
args:
- --fix=no
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.2.1
rev: v3.0.0
hooks:
- id: add-trailing-comma
stages:
- commit
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.6.0
rev: v2.0.2
hooks:
- id: autopep8
stages:
- commit
args:
- --diff
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: fix import order
Expand All @@ -63,7 +63,7 @@ repos:
- --multi-line=9
- --project=pjrpc
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
rev: v1.4.1
hooks:
- id: mypy
stages:
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ python:
- method: pip
path: .
extra_requirements:
- docgen
- docs
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.7.0 (2023-08-10)
------------------

- refactoring done
- dependencies updated
- python 3.11 support added


1.6.0 (2022-07-05)
------------------

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pjrpc
.. image:: https://static.pepy.tech/personalized-badge/pjrpc?period=month&units=international_system&left_color=grey&right_color=orange&left_text=Downloads/month
:target: https://pepy.tech/project/pjrpc
:alt: Downloads/month
.. image:: https://travis-ci.org/dapper91/pjrpc.svg?branch=master
:target: https://travis-ci.org/dapper91/pjrpc
.. image:: https://github.com/dapper91/pjrpc/actions/workflows/test.yml/badge.svg?branch=master
:target: https://github.com/dapper91/pjrpc/actions/workflows/test.yml
:alt: Build status
.. image:: https://img.shields.io/pypi/l/pjrpc.svg
:target: https://pypi.org/project/pjrpc
Expand Down Expand Up @@ -67,7 +67,7 @@ Extra requirements
Documentation
-------------

Documentation is available at `Read the Docs <https://pjrpc.readthedocs.io/en/latest/>`_.
Documentation is available at `Read the Docs <https://pjrpc.readthedocs.io>`_.


Quickstart
Expand Down
8 changes: 4 additions & 4 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.py.class {
padding: 1.5em 0em 1.5em;
.content {
width: 55em;
}

.py.data, .py.method, .py.property, .py.exception, .py.function {
padding: 0.5em 0em 0.5em;
.sidebar-drawer {
width: 15em;
}
85 changes: 25 additions & 60 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import enum
import sys
from pathlib import Path

THIS_PATH = Path(__file__).parent
sys.path.insert(0, str(THIS_PATH.parent.parent))

import pjrpc.common.typedefs # noqa
import pjrpc.server.typedefs # noqa
import toml

# -- Project information -----------------------------------------------------

project = pjrpc.__title__
author = pjrpc.__author__
copyright = '2019, {}'.format(author)
THIS_PATH = Path(__file__).parent
ROOT_PATH = THIS_PATH.parent.parent
sys.path.insert(0, str(ROOT_PATH))

# The full version, including alpha/beta/rc tags
release = pjrpc.__version__
version = pjrpc.__version__
PYPROJECT = toml.load(ROOT_PATH / 'pyproject.toml')
PROJECT_INFO = PYPROJECT['tool']['poetry']

project = PROJECT_INFO['name']
copyright = f"2023, {PROJECT_INFO['name']}"
author = PROJECT_INFO['authors'][0]
release = PROJECT_INFO['version']

# -- General configuration ---------------------------------------------------

Expand All @@ -40,68 +36,37 @@
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.autosectionlabel',
'sphinx.ext.viewcode',
'sphinx_copybutton',
'sphinx_design',
]

html_theme_options = {
'github_user': 'dapper91',
'github_repo': 'pjrpc',
'github_banner': True,
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = ['css/custom.css']

# The master toctree document.
master_doc = 'index'

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'aiohttp': ('https://aiohttp.readthedocs.io/en/stable/', None),
'requests': ('https://requests.kennethreitz.org/en/master/', None),
}

autodoc_mock_imports = ['attrs']
autodoc_typehints = 'description'
autodoc_typehints_format = 'short'
autodoc_member_order = 'bysource'
autodoc_default_options = {
'show-inheritance': True,
}
autodoc_type_aliases = {
type_name: f'{pjrpc.common.typedefs.__name__}.{type_name}'
for type_name in pjrpc.common.typedefs.__all__
} | {
type_name: f'{pjrpc.server.typedefs.__name__}.{type_name}'
for type_name in pjrpc.server.typedefs.__all__
}


def maybe_skip_member(app, what, name, obj, skip, options):
if isinstance(obj, enum.Enum):
return False
autosectionlabel_prefix_document = True

return None
html_theme_options = {}
html_title = PROJECT_INFO['name']

templates_path = ['_templates']
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

def setup(app):
app.connect('autodoc-skip-member', maybe_skip_member)
html_theme = 'furo'
html_static_path = ['_static']
html_css_files = ['css/custom.css']
14 changes: 10 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to pjrpc's documentation!
=================================
Python JSON-RPC without boilerplate
===================================


.. image:: https://static.pepy.tech/personalized-badge/pjrpc?period=month&units=international_system&left_color=grey&right_color=orange&left_text=Downloads/month
:target: https://pepy.tech/project/pjrpc
:alt: Downloads/month
.. image:: https://travis-ci.org/dapper91/pjrpc.svg?branch=master
:target: https://travis-ci.org/dapper91/pjrpc
.. image:: https://github.com/dapper91/pjrpc/actions/workflows/test.yml/badge.svg?branch=master
:target: https://github.com/dapper91/pjrpc/actions/workflows/test.yml
:alt: Build status
.. image:: https://img.shields.io/pypi/l/pjrpc.svg
:target: https://pypi.org/project/pjrpc
Expand Down Expand Up @@ -99,6 +99,12 @@ Development
pjrpc/development


Links
-----

- `Source code <https://github.com/dapper91/pjrpc>`_


Indices and tables
==================

Expand Down
3 changes: 3 additions & 0 deletions docs/source/pjrpc/api/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
Client
------

Misc
~~~~

.. automodule:: pjrpc.client
:members:


Backends
~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions docs/source/pjrpc/api/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Common
------

Misc
~~~~

.. automodule:: pjrpc.common
:members:
Expand Down
4 changes: 4 additions & 0 deletions docs/source/pjrpc/api/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
Server
------

Misc
~~~~

.. automodule:: pjrpc.server
:members:


Types
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion docs/source/pjrpc/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@ Id generators
--------------

The library request id generator can also be customized. There are four generator types implemented in the library
see :py:mod:`pjrpc.common.generators`. You can implement your own one and pass it to a client by `id_gen`
see :py:mod:`pjrpc.common.generators`. You can implement your own one and pass it to a client by ``id_gen``
parameter.
11 changes: 6 additions & 5 deletions docs/source/pjrpc/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ an JSON-RPC server implementation based on :py:mod:`http.server` standard python

.. code-block:: python

import uuid
import http.server
import socketserver
import uuid

import pjrpc
import pjrpc.server
Expand All @@ -19,20 +19,21 @@ an JSON-RPC server implementation based on :py:mod:`http.server` standard python
class JsonRpcHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
content_type = self.headers.get('Content-Type')
if content_type not in pjrpc.common.JSONRPC_REQUEST_CONTENT_TYPES:
self.send_response(http.HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
if content_type not in pjrpc.common.REQUEST_CONTENT_TYPES:
self.send_error(http.HTTPStatus.UNSUPPORTED_MEDIA_TYPE)
return

try:
content_length = int(self.headers.get('Content-Length', -1))
request_text = self.rfile.read(content_length).decode()
except UnicodeDecodeError:
self.send_response(http.HTTPStatus.BAD_REQUEST)
self.send_error(http.HTTPStatus.BAD_REQUEST)
return

response_text = self.server.dispatcher.dispatch(request_text, context=self)
if response_text is None:
self.send_response(http.HTTPStatus.OK)
self.send_response_only(http.HTTPStatus.OK)
self.end_headers()
else:
self.send_response(http.HTTPStatus.OK)
self.send_header("Content-type", pjrpc.common.DEFAULT_CONTENT_TYPE)
Expand Down
4 changes: 2 additions & 2 deletions docs/source/pjrpc/specification.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _specification:

Specification:
==============
Specification
=============


``pjrpc`` has built-in `OpenAPI <https://swagger.io/specification/>`_ and `OpenRPC <https://spec.open-rpc.org/#introduction>`_
Expand Down
9 changes: 9 additions & 0 deletions docs/source/pjrpc/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ pytest
------

``pjrpc`` implements pytest plugin that simplifies JSON-RPC requests mocking.
To install the plugin add the following line to your pytest configuration:

.. code-block:: python

pytest_plugins = ("pjrpc.client.integrations.pytest ", )

or export the environment variable ``PYTEST_PLUGINS=pjrpc.client.integrations.pytest``.
For more information `see <https://docs.pytest.org/en/latest/how-to/plugins.html#requiring-loading-plugins-in-a-test-module-or-conftest-file>`_.

Look at the following test example:

.. code-block:: python
Expand Down
Loading
Loading