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

chore: blackify #6146

Merged
merged 5 commits into from
Feb 29, 2024
Merged
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 jina/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _ignore_google_warnings():
'ignore',
category=DeprecationWarning,
message='Deprecated call to `pkg_resources.declare_namespace(\'google\')`.',
append=True
append=True,
)


Expand Down
1 change: 1 addition & 0 deletions jina/clients/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module wrapping the Client of Jina."""

import argparse
from typing import TYPE_CHECKING, List, Optional, Union, overload

Expand Down
12 changes: 7 additions & 5 deletions jina/clients/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing the Base Client for Jina."""

import abc
import argparse
import inspect
Expand Down Expand Up @@ -48,9 +49,11 @@ def __init__(
os.unsetenv('https_proxy')
self._inputs = None
self._setup_instrumentation(
name=self.args.name
if hasattr(self.args, 'name')
else self.__class__.__name__,
name=(
self.args.name
if hasattr(self.args, 'name')
else self.__class__.__name__
),
tracing=self.args.tracing,
traces_exporter_host=self.args.traces_exporter_host,
traces_exporter_port=self.args.traces_exporter_port,
Expand Down Expand Up @@ -180,8 +183,7 @@ async def _get_results(
on_error: Optional['CallbackFnType'] = None,
on_always: Optional['CallbackFnType'] = None,
**kwargs,
):
...
): ...

@abc.abstractmethod
def _is_flow_ready(self, **kwargs) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions jina/clients/base/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ async def _get_results(
compression=self.compression,
**kwargs,
)
async for response in stream_rpc.stream_rpc_with_retry():
async for (
response
) in stream_rpc.stream_rpc_with_retry():
yield response
else:
unary_rpc = UnaryRpc(
Expand Down Expand Up @@ -257,9 +259,7 @@ async def _get_streaming_results(
req.header.exec_endpoint = on
req.document_cls = inputs.__class__
req.data.doc = inputs
async for response in self.stream_doc_endpoint(
request=req, timeout=timeout
):
async for response in self.stream_doc_endpoint(request=req, timeout=timeout):
yield return_type.from_protobuf(response.document)


Expand Down
35 changes: 20 additions & 15 deletions jina/clients/base/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
raise err


def sync_wait_or_raise_err(attempt: int,
err: Exception,
max_attempts: float,
backoff_multiplier: float,
initial_backoff: float,
max_backoff: float,
):
def sync_wait_or_raise_err(
attempt: int,
err: Exception,
max_attempts: float,
backoff_multiplier: float,
initial_backoff: float,
max_backoff: float,
):
"""
Accepts retry parameters and the underlying. The error is raised if the max_attempts has been reached otherwise the
method waits based on the backoff calculations.
Expand All @@ -53,16 +54,18 @@
if attempt == max_attempts:
_raise_last_attempt(err, attempt)
else:
time.sleep(_wait_time(attempt, backoff_multiplier, initial_backoff, max_backoff))
time.sleep(

Check warning on line 57 in jina/clients/base/retry.py

View check run for this annotation

Codecov / codecov/patch

jina/clients/base/retry.py#L57

Added line #L57 was not covered by tests
_wait_time(attempt, backoff_multiplier, initial_backoff, max_backoff)
)


async def wait_or_raise_err(
attempt: int,
err: Exception,
max_attempts: float,
backoff_multiplier: float,
initial_backoff: float,
max_backoff: float,
attempt: int,
err: Exception,
max_attempts: float,
backoff_multiplier: float,
initial_backoff: float,
max_backoff: float,
):
"""
Accepts retry parameters and the underlying. The error is raised if the max_attempts has been reached otherwise the
Expand All @@ -78,7 +81,9 @@
if attempt == max_attempts:
_raise_last_attempt(err, attempt)
else:
await asyncio.sleep(_wait_time(attempt, backoff_multiplier, initial_backoff, max_backoff))
await asyncio.sleep(
_wait_time(attempt, backoff_multiplier, initial_backoff, max_backoff)
)


def _wait_time(attempt, backoff_multiplier, initial_backoff, max_backoff):
Expand Down
7 changes: 4 additions & 3 deletions jina/clients/base/websocket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A module for the websockets-based Client for Jina."""

import asyncio
from contextlib import AsyncExitStack
from typing import TYPE_CHECKING, Dict, Optional, Tuple
Expand Down Expand Up @@ -131,9 +132,9 @@ async def _get_results(
)
)

request_buffer: Dict[
str, asyncio.Future
] = dict() # maps request_ids to futures (tasks)
request_buffer: Dict[str, asyncio.Future] = (
dict()
) # maps request_ids to futures (tasks)

def _result_handler(result):
return result
Expand Down
2 changes: 2 additions & 0 deletions jina/clients/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ async def _get_results(*args, **kwargs):
inferred_return_type = return_type
if docarray_v2:
from docarray import DocList

if not issubclass(return_type, DocList):
is_singleton = True
inferred_return_type = DocList[return_type]
Expand Down Expand Up @@ -530,6 +531,7 @@ async def post(
is_singleton = False
if docarray_v2:
from docarray import DocList

if issubclass(return_type, DocList):
result.document_array_cls = return_type
else:
Expand Down
1 change: 1 addition & 0 deletions jina/clients/request/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for helper functions for clients."""

from typing import Optional, Tuple

from jina._docarray import Document, DocumentArray, docarray_v2
Expand Down
1 change: 1 addition & 0 deletions jina/excepts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This modules defines all kinds of exceptions raised in Jina."""

from typing import List, Optional, Set, Union

import grpc.aio
Expand Down
9 changes: 7 additions & 2 deletions jina/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
output_base_path=args.outpath, k8s_namespace=args.k8s_namespace
)
else:
raise NotImplementedError(f'Object of class {obj.__class__.__name__} cannot be exported to Kubernetes')
raise NotImplementedError(

Check warning on line 25 in jina/exporter.py

View check run for this annotation

Codecov / codecov/patch

jina/exporter.py#L25

Added line #L25 was not covered by tests
f'Object of class {obj.__class__.__name__} cannot be exported to Kubernetes'
)


def export_docker_compose(args):
Expand All @@ -40,7 +42,9 @@
output_path=args.outpath, network_name=args.network_name
)
else:
raise NotImplementedError(f'Object of class {obj.__class__.__name__} cannot be exported to Docker Compose')
raise NotImplementedError(

Check warning on line 45 in jina/exporter.py

View check run for this annotation

Codecov / codecov/patch

jina/exporter.py#L45

Added line #L45 was not covered by tests
f'Object of class {obj.__class__.__name__} cannot be exported to Docker Compose'
)


def export_flowchart(args):
Expand All @@ -59,6 +63,7 @@
:param args: args from CLI
"""
from jina import __version__

if args.yaml_path:
dump_api = api_to_dict()
for yp in args.yaml_path:
Expand Down
1 change: 1 addition & 0 deletions jina/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,4 +1666,5 @@ def _telemetry():

def is_generator(func):
import inspect

return inspect.isgeneratorfunction(func) or inspect.isasyncgenfunction(func)
23 changes: 11 additions & 12 deletions jina/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@

def __enter__(self):
return self

def _check_v(self, v, missing_module):
if (
v.strip()
and not v.startswith('#')
and v.startswith(missing_module)
and ':' in v
):
v.strip()
and not v.startswith('#')
and v.startswith(missing_module)
and ':' in v
):
return True

def _find_missing_module_in_extra_req(self, missing_module):
with open(os.path.join(__resources_path__, 'extra-requirements.txt'), encoding='utf-8') as fp:
with open(
os.path.join(__resources_path__, 'extra-requirements.txt'), encoding='utf-8'
) as fp:
for v in fp:
if self._check_v(v, missing_module):
missing_module, install_tags = v.split(':')
Expand All @@ -63,7 +65,6 @@
missing_module = self._find_missing_module_in_extra_req(missing_module)
return missing_module


def _err_msg(self, exc_val, missing_module):
if self._tags:
from jina.helper import colored
Expand All @@ -84,7 +85,7 @@
else:
err_msg = f'{exc_val.msg}'
return err_msg

def _log_critical(self, err_msg):
if self._verbose and self._logger:
self._logger.critical(err_msg)
Expand All @@ -95,7 +96,7 @@
if self._verbose and self._logger:
self._logger.warning(err_msg)
if self._help_text:
self._logger.info(self._help_text)
self._logger.info(self._help_text)

Check warning on line 99 in jina/importer.py

View check run for this annotation

Codecov / codecov/patch

jina/importer.py#L99

Added line #L99 was not covered by tests

def _raise_or_supress(self, err_msg, exc_val):
if self._verbose and not self._logger:
Expand All @@ -107,14 +108,12 @@
self._log_warning(err_msg)
return True # suppress the error


def __exit__(self, exc_type, exc_val, traceback):
if exc_type != ModuleNotFoundError:
return
missing_module = self._find_missing_module(exc_val)
err_msg = self._err_msg(exc_val, missing_module)
return self._raise_or_supress(err_msg, exc_val)



def _path_import(absolute_path: str):
Expand Down
12 changes: 6 additions & 6 deletions jina/jaml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,7 @@ def load_config(
:return: :class:`JAMLCompatible` object
"""
if runtime_args:
kwargs[
'runtimes_args'
] = (
kwargs['runtimes_args'] = (
dict()
) # when we have runtime args it is needed to have an empty runtime args session in the yam config

Expand Down Expand Up @@ -741,9 +739,11 @@ def _delitem(
_extra_search_paths = extra_search_paths or []
load_py_modules(
no_tag_yml,
extra_search_paths=(_extra_search_paths + [os.path.dirname(s_path)])
if s_path
else _extra_search_paths,
extra_search_paths=(
(_extra_search_paths + [os.path.dirname(s_path)])
if s_path
else _extra_search_paths
),
)

from jina.enums import DeploymentRoleType
Expand Down
16 changes: 10 additions & 6 deletions jina/orchestrate/deployments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ def _get_connection_list_for_flow(self) -> List[str]:
# there is no head, add the worker connection information instead
ports = self.ports
hosts = [
__docker_host__
if host_is_local(host) and in_docker() and self._is_docker
else host
(
__docker_host__
if host_is_local(host) and in_docker() and self._is_docker
else host
)
for host in self.hosts
]
return [
Expand Down Expand Up @@ -1133,9 +1135,11 @@ def start(self) -> 'Deployment':
deployment_args=self.args,
args=self.pod_args['pods'][shard_id],
head_pod=self.head_pod,
name=f'{self.name}-replica-set-{shard_id}'
if num_shards > 1
else f'{self.name}-replica-set',
name=(
f'{self.name}-replica-set-{shard_id}'
if num_shards > 1
else f'{self.name}-replica-set'
),
)
self.enter_context(self.shards[shard_id])

Expand Down
20 changes: 8 additions & 12 deletions jina/orchestrate/deployments/config/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ def __init__(
shard_id=i,
common_args=self.args,
service_args=args,
pod_type=PodRoleType.WORKER
if name != 'gateway'
else PodRoleType.GATEWAY,
pod_type=(
PodRoleType.WORKER if name != 'gateway' else PodRoleType.GATEWAY
),
jina_deployment_name=self.name,
deployments_addresses=self.deployments_addresses
if name == 'gateway'
else None,
deployments_addresses=(
self.deployments_addresses if name == 'gateway' else None
),
)
)

Expand Down Expand Up @@ -342,9 +342,7 @@ def _get_services_args(self, args):
uses_before_cargs.pod_role = PodRoleType.WORKER
uses_before_cargs.polling = None
parsed_args['uses_before_service'] = uses_before_cargs
parsed_args[
'head_service'
].uses_before_address = (
parsed_args['head_service'].uses_before_address = (
f'{to_compatible_name(uses_before_cargs.name)}:{uses_before_cargs.port}'
)
if uses_after and shards > 1:
Expand All @@ -366,9 +364,7 @@ def _get_services_args(self, args):
uses_after_cargs.pod_role = PodRoleType.WORKER
uses_after_cargs.polling = None
parsed_args['uses_after_service'] = uses_after_cargs
parsed_args[
'head_service'
].uses_after_address = (
parsed_args['head_service'].uses_after_address = (
f'{to_compatible_name(uses_after_cargs.name)}:{uses_after_cargs.port}'
)

Expand Down
Loading
Loading