Skip to content

Commit

Permalink
Merge pull request #34 from belek/update_dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
gluk-w authored Jan 30, 2025
2 parents 5cb7385 + 6549edb commit d886807
Show file tree
Hide file tree
Showing 21 changed files with 1,243 additions and 227 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ output/*/index.html

# Sphinx
docs/_build

.qodo
30 changes: 23 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@
language: python

python:
- "3.6"
- "3.7"
- "3.11"
- "3.12"

env:
global:
- POETRY_VIRTUALENVS_CREATE=false # Use the system's Python interpreter

matrix:
fast_finish: true
matrix:
- TOX_ENV=django42
- TOX_ENV=django50

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -r requirements_test.txt
# Cache pip and Poetry dependencies for faster builds
cache:
pip: true
directories:
- $HOME/.cache/pypoetry

# command to run tests using coverage, e.g. python setup.py test
# Install Poetry and dependencies
before_install:
- curl -sSL https://install.python-poetry.org | python3 -
- export PATH="$HOME/.local/bin:$PATH"
- poetry --version

install:
- poetry install --with=dev,qa

# Run the tests
script: tox -e $TOX_ENV

# Upload coverage to Codecov
after_success:
- codecov -e TOX_ENV
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ makes it work faster than any RESTful framework where a lot of time is spent on
Note that you need this project only if you want to use Django functionality in gRPC service.
For pure python implementation [read this](https://grpc.io/docs/languages/python/quickstart/)

* Supported Python: 3.4+
* Supported Django: 2.X, 3.X and 4.X
* Supported Python: 3.10+
* Supported Django: 4.2+

## Installation

Expand Down
27 changes: 16 additions & 11 deletions django_grpc/management/commands/grpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@


class Command(BaseCommand):
help = 'Run gRPC server'
config = getattr(settings, 'GRPCSERVER', dict())
help = "Run gRPC server"
config = getattr(settings, "GRPCSERVER", dict())

def add_arguments(self, parser):
parser.add_argument('--max_workers', type=int, help="Number of workers")
parser.add_argument('--port', type=int, default=50051, help="Port number to listen")
parser.add_argument('--autoreload', action='store_true', default=False)
parser.add_argument('--list-handlers', action='store_true', default=False, help="Print all registered endpoints")
parser.add_argument("--max_workers", type=int, help="Number of workers")
parser.add_argument("--port", type=int, default=50051, help="Port number to listen")
parser.add_argument("--autoreload", action="store_true", default=False)
parser.add_argument(
"--list-handlers",
action="store_true",
default=False,
help="Print all registered endpoints",
)

def handle(self, *args, **options):
is_async = self.config.get('async', False)
is_async = self.config.get("async", False)
if is_async is True:
self._serve_async(**options)
else:
if options['autoreload'] is True:
if options["autoreload"] is True:
self.stdout.write("ATTENTION! Autoreload is enabled!")
if hasattr(autoreload, "run_with_reloader"):
# Django 2.2. and above
Expand All @@ -42,7 +47,7 @@ def _serve(self, max_workers, port, *args, **kwargs):

self.stdout.write("gRPC server is listening port %s" % port)

if kwargs['list_handlers'] is True:
if kwargs["list_handlers"] is True:
self.stdout.write("Registered handlers:")
for handler in extract_handlers(server):
self.stdout.write("* %s" % handler)
Expand All @@ -58,11 +63,11 @@ async def _main_routine():
await server.start()
self.stdout.write("gRPC async server is listening port %s" % port)

if kwargs['list_handlers'] is True:
if kwargs["list_handlers"] is True:
self.stdout.write("Registered handlers:")
for handler in extract_handlers(server):
self.stdout.write("* %s" % handler)

await server.wait_for_termination()

asyncio.get_event_loop().run_until_complete(_main_routine())
asyncio.get_event_loop().run_until_complete(_main_routine())
2 changes: 1 addition & 1 deletion django_grpc/serializers/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from google.protobuf.message import Message

from typing import Iterable
from django.db.models import ForeignKey
from django.db.models import ForeignKey, Model
from django.db.models.fields.reverse_related import ForeignObjectRel


Expand Down
10 changes: 10 additions & 0 deletions django_grpc/signals/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from functools import wraps
from typing import Dict

import grpc
from grpc._utilities import RpcMethodHandler

Expand Down Expand Up @@ -41,6 +43,14 @@ def _replace_method_handler(self, method_handler: 'RpcMethodHandler') -> 'RpcMet

return RpcMethodHandler(**kwargs)

def add_registered_method_handlers(
self,
service_name: str,
method_handlers: Dict[str, grpc.RpcMethodHandler],
):
# do nothing; see https://github.com/grpc/grpc/issues/36683
# and https://github.com/grpc/grpc/pull/36696
pass

def _unary_unary(func):
if func is None:
Expand Down
9 changes: 3 additions & 6 deletions django_grpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from django_grpc.signals.wrapper import SignalWrapper
from django.conf import settings

from django_grpc.signals.wrapper import SignalWrapper


logger = logging.getLogger(__name__)

Expand All @@ -23,7 +21,6 @@ def create_server(max_workers, port, interceptors=None):
credentials = config.get('credentials', None)
is_async = config.get('async', False)


# create a gRPC server
if is_async is True:
server = grpc.aio.server(
Expand All @@ -38,7 +35,7 @@ def create_server(max_workers, port, interceptors=None):
maximum_concurrent_rpcs=maximum_concurrent_rpcs,
options=options
)

add_servicers(server, servicers_list)

if credentials is None:
Expand Down Expand Up @@ -95,14 +92,14 @@ def extract_handlers(server):
if unary is None:
name = "???"
params = "???"
abstract = 'DOES NOT EXIST'
abstract = "DOES NOT EXIST"
else:
code = it.unary_unary.__code__
name = code.co_name
params = ", ".join(code.co_varnames)
abstract = ''
if isinstance(it.__class__, ABCMeta):
abstract = 'NOT IMPLEMENTED'
abstract = "NOT IMPLEMENTED"

yield "{path}: {name}({params}) {abstract}".format(
path=path,
Expand Down
Empty file removed django_grpc_testtools/__init__.py
Empty file.
3 changes: 1 addition & 2 deletions django_grpc_testtools/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mirakuru import TCPExecutor


class TestGRPCServer:
class GRPCServerForTests:
def __init__(self, manage_py, params=None):
if params is None:
params = {}
Expand All @@ -30,4 +30,3 @@ def start(self):

def stop(self):
self.process.stop()

Loading

0 comments on commit d886807

Please sign in to comment.