Skip to content

Commit

Permalink
style: fix overload and cli autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jina-bot committed Jul 3, 2023
1 parent b277311 commit 732149c
Show file tree
Hide file tree
Showing 4 changed files with 487 additions and 517 deletions.
53 changes: 22 additions & 31 deletions jina/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,24 @@

# overload_inject_start_client
@overload
def Client(
*,
asyncio: Optional[bool] = False,
grpc_channel_options: Optional[dict] = None,
host: Optional[str] = '0.0.0.0',
log_config: Optional[str] = None,
metrics: Optional[bool] = False,
metrics_exporter_host: Optional[str] = None,
metrics_exporter_port: Optional[int] = None,
port: Optional[int] = None,
prefetch: Optional[int] = 1000,
protocol: Optional[Union[str, List[str]]] = 'GRPC',
proxy: Optional[bool] = False,
suppress_root_logging: Optional[bool] = False,
tls: Optional[bool] = False,
traces_exporter_host: Optional[str] = None,
traces_exporter_port: Optional[int] = None,
tracing: Optional[bool] = False,
**kwargs
) -> Union[
'AsyncWebSocketClient',
'WebSocketClient',
'AsyncGRPCClient',
'GRPCClient',
'HTTPClient',
'AsyncHTTPClient',
]:
def Client(*,
asyncio: Optional[bool] = False,
grpc_channel_options: Optional[dict] = None,
host: Optional[str] = '0.0.0.0',
log_config: Optional[str] = None,
metrics: Optional[bool] = False,
metrics_exporter_host: Optional[str] = None,
metrics_exporter_port: Optional[int] = None,
port: Optional[int] = None,
prefetch: Optional[int] = 1000,
protocol: Optional[Union[str, List[str]]] = 'GRPC',
proxy: Optional[bool] = False,
suppress_root_logging: Optional[bool] = False,
tls: Optional[bool] = False,
traces_exporter_host: Optional[str] = None,
traces_exporter_port: Optional[int] = None,
tracing: Optional[bool] = False,
**kwargs) -> Union['AsyncWebSocketClient', 'WebSocketClient', 'AsyncGRPCClient', 'GRPCClient', 'HTTPClient', 'AsyncHTTPClient']:
"""Create a Client. Client is how user interact with Flow
:param asyncio: If set, then the input and output of this Client work in an asynchronous manner.
Expand All @@ -53,8 +44,8 @@ def Client(
:param metrics_exporter_host: If tracing is enabled, this hostname will be used to configure the metrics exporter agent.
:param metrics_exporter_port: If tracing is enabled, this port will be used to configure the metrics exporter agent.
:param port: The port of the Gateway, which the client should connect to.
:param prefetch: Number of requests fetched from the client before feeding into the first Executor.
:param prefetch: Number of requests fetched from the client before feeding into the first Executor.
Used to control the speed of data input into a Flow. 0 disables prefetch (1000 requests is the default)
:param protocol: Communication protocol between server and client.
:param proxy: If set, respect the http_proxy and https_proxy environment variables. otherwise, it will unset these proxy variables before start. gRPC seems to prefer no proxy
Expand Down Expand Up @@ -109,8 +100,8 @@ def Client(
:param metrics_exporter_host: If tracing is enabled, this hostname will be used to configure the metrics exporter agent.
:param metrics_exporter_port: If tracing is enabled, this port will be used to configure the metrics exporter agent.
:param port: The port of the Gateway, which the client should connect to.
:param prefetch: Number of requests fetched from the client before feeding into the first Executor.
:param prefetch: Number of requests fetched from the client before feeding into the first Executor.
Used to control the speed of data input into a Flow. 0 disables prefetch (1000 requests is the default)
:param protocol: Communication protocol between server and client.
:param proxy: If set, respect the http_proxy and https_proxy environment variables. otherwise, it will unset these proxy variables before start. gRPC seems to prefer no proxy
Expand Down
173 changes: 85 additions & 88 deletions jina/orchestrate/deployments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,77 +256,75 @@ def __exit__(self, exc_type, exc_val, exc_tb):
# overload_inject_start_deployment
@overload
def __init__(
self,
*,
allow_concurrent: Optional[bool] = False,
compression: Optional[str] = None,
connection_list: Optional[str] = None,
cors: Optional[bool] = False,
description: Optional[str] = None,
disable_auto_volume: Optional[bool] = False,
docker_kwargs: Optional[dict] = None,
entrypoint: Optional[str] = None,
env: Optional[dict] = None,
env_from_secret: Optional[dict] = None,
exit_on_exceptions: Optional[List[str]] = [],
external: Optional[bool] = False,
floating: Optional[bool] = False,
force_update: Optional[bool] = False,
gpus: Optional[str] = None,
grpc_channel_options: Optional[dict] = None,
grpc_metadata: Optional[dict] = None,
grpc_server_options: Optional[dict] = None,
host: Optional[List[str]] = ['0.0.0.0'],
install_requirements: Optional[bool] = False,
log_config: Optional[str] = None,
metrics: Optional[bool] = False,
metrics_exporter_host: Optional[str] = None,
metrics_exporter_port: Optional[int] = None,
monitoring: Optional[bool] = False,
name: Optional[str] = 'executor',
native: Optional[bool] = False,
no_reduce: Optional[bool] = False,
output_array_type: Optional[str] = None,
polling: Optional[str] = 'ANY',
port: Optional[int] = None,
port_monitoring: Optional[int] = None,
prefer_platform: Optional[str] = None,
protocol: Optional[Union[str, List[str]]] = ['GRPC'],
py_modules: Optional[List[str]] = None,
quiet: Optional[bool] = False,
quiet_error: Optional[bool] = False,
raft_configuration: Optional[dict] = None,
reload: Optional[bool] = False,
replicas: Optional[int] = 1,
retries: Optional[int] = -1,
runtime_cls: Optional[str] = 'WorkerRuntime',
shards: Optional[int] = 1,
ssl_certfile: Optional[str] = None,
ssl_keyfile: Optional[str] = None,
stateful: Optional[bool] = False,
timeout_ctrl: Optional[int] = 60,
timeout_ready: Optional[int] = 600000,
timeout_send: Optional[int] = None,
title: Optional[str] = None,
tls: Optional[bool] = False,
traces_exporter_host: Optional[str] = None,
traces_exporter_port: Optional[int] = None,
tracing: Optional[bool] = False,
uses: Optional[Union[str, Type['BaseExecutor'], dict]] = 'BaseExecutor',
uses_after: Optional[Union[str, Type['BaseExecutor'], dict]] = None,
uses_after_address: Optional[str] = None,
uses_before: Optional[Union[str, Type['BaseExecutor'], dict]] = None,
uses_before_address: Optional[str] = None,
uses_dynamic_batching: Optional[dict] = None,
uses_metas: Optional[dict] = None,
uses_requests: Optional[dict] = None,
uses_with: Optional[dict] = None,
uvicorn_kwargs: Optional[dict] = None,
volumes: Optional[List[str]] = None,
when: Optional[dict] = None,
workspace: Optional[str] = None,
**kwargs,
):
self,*,
allow_concurrent: Optional[bool] = False,
compression: Optional[str] = None,
connection_list: Optional[str] = None,
cors: Optional[bool] = False,
description: Optional[str] = None,
disable_auto_volume: Optional[bool] = False,
docker_kwargs: Optional[dict] = None,
entrypoint: Optional[str] = None,
env: Optional[dict] = None,
env_from_secret: Optional[dict] = None,
exit_on_exceptions: Optional[List[str]] = [],
external: Optional[bool] = False,
floating: Optional[bool] = False,
force_update: Optional[bool] = False,
gpus: Optional[str] = None,
grpc_channel_options: Optional[dict] = None,
grpc_metadata: Optional[dict] = None,
grpc_server_options: Optional[dict] = None,
host: Optional[List[str]] = ['0.0.0.0'],
install_requirements: Optional[bool] = False,
log_config: Optional[str] = None,
metrics: Optional[bool] = False,
metrics_exporter_host: Optional[str] = None,
metrics_exporter_port: Optional[int] = None,
monitoring: Optional[bool] = False,
name: Optional[str] = 'executor',
native: Optional[bool] = False,
no_reduce: Optional[bool] = False,
output_array_type: Optional[str] = None,
polling: Optional[str] = 'ANY',
port: Optional[int] = None,
port_monitoring: Optional[int] = None,
prefer_platform: Optional[str] = None,
protocol: Optional[Union[str, List[str]]] = ['GRPC'],
py_modules: Optional[List[str]] = None,
quiet: Optional[bool] = False,
quiet_error: Optional[bool] = False,
raft_configuration: Optional[dict] = None,
reload: Optional[bool] = False,
replicas: Optional[int] = 1,
retries: Optional[int] = -1,
runtime_cls: Optional[str] = 'WorkerRuntime',
shards: Optional[int] = 1,
ssl_certfile: Optional[str] = None,
ssl_keyfile: Optional[str] = None,
stateful: Optional[bool] = False,
timeout_ctrl: Optional[int] = 60,
timeout_ready: Optional[int] = 600000,
timeout_send: Optional[int] = None,
title: Optional[str] = None,
tls: Optional[bool] = False,
traces_exporter_host: Optional[str] = None,
traces_exporter_port: Optional[int] = None,
tracing: Optional[bool] = False,
uses: Optional[Union[str, Type['BaseExecutor'], dict]] = 'BaseExecutor',
uses_after: Optional[Union[str, Type['BaseExecutor'], dict]] = None,
uses_after_address: Optional[str] = None,
uses_before: Optional[Union[str, Type['BaseExecutor'], dict]] = None,
uses_before_address: Optional[str] = None,
uses_dynamic_batching: Optional[dict] = None,
uses_metas: Optional[dict] = None,
uses_requests: Optional[dict] = None,
uses_with: Optional[dict] = None,
uvicorn_kwargs: Optional[dict] = None,
volumes: Optional[List[str]] = None,
when: Optional[dict] = None,
workspace: Optional[str] = None,
**kwargs):
"""Create a Deployment to serve or deploy and Executor or Gateway
:param allow_concurrent: Allow concurrent requests to be processed by the Executor. This is only recommended if the Executor is thread-safe.
Expand All @@ -336,8 +334,8 @@ def __init__(
:param description: The description of this HTTP server. It will be used in automatics docs such as Swagger UI.
:param disable_auto_volume: Do not automatically mount a volume for dockerized Executors.
:param docker_kwargs: Dictionary of kwargs arguments that will be passed to Docker SDK when starting the docker '
container.
container.
More details can be found in the Docker SDK docs: https://docker-py.readthedocs.io/en/stable/
:param entrypoint: The entrypoint command overrides the ENTRYPOINT in Docker image. when not set then the Docker image ENTRYPOINT takes effective.
:param env: The map of environment variables that are available inside runtime
Expand All @@ -347,8 +345,8 @@ def __init__(
:param floating: If set, the current Pod/Deployment can not be further chained, and the next `.add()` will chain after the last Pod/Deployment not this current one.
:param force_update: If set, always pull the latest Hub Executor bundle even it exists on local
:param gpus: This argument allows dockerized Jina Executors to discover local gpu devices.
Note,
Note,
- To access all gpus, use `--gpus all`.
- To access multiple gpus, e.g. make use of 2 gpus, use `--gpus 2`.
- To access specified gpus based on device id, use `--gpus device=[YOUR-GPU-DEVICE-ID]`
Expand All @@ -365,19 +363,19 @@ def __init__(
:param metrics_exporter_port: If tracing is enabled, this port will be used to configure the metrics exporter agent.
:param monitoring: If set, spawn an http server with a prometheus endpoint to expose metrics
:param name: The name of this object.
This will be used in the following places:
- how you refer to this object in Python/YAML/CLI
- visualization
- log message header
- ...
When not given, then the default naming strategy will apply.
:param native: If set, only native Executors is allowed, and the Executor is always run inside WorkerRuntime.
:param no_reduce: Disable the built-in reduction mechanism. Set this if the reduction is to be handled by the Executor itself by operating on a `docs_matrix` or `docs_map`
:param output_array_type: The type of array `tensor` and `embedding` will be serialized to.
Supports the same types as `docarray.to_protobuf(.., ndarray_type=...)`, which can be found
Supports the same types as `docarray.to_protobuf(.., ndarray_type=...)`, which can be found
`here <https://docarray.jina.ai/fundamentals/document/serialization/#from-to-protobuf>`.
Defaults to retaining whatever type is returned by the Executor.
:param polling: The polling strategy of the Deployment and its endpoints (when `shards>1`).
Expand All @@ -393,7 +391,7 @@ def __init__(
:param prefer_platform: The preferred target Docker platform. (e.g. "linux/amd64", "linux/arm64")
:param protocol: Communication protocol of the server exposed by the Executor. This can be a single value or a list of protocols, depending on your chosen Gateway. Choose the convenient protocols from: ['GRPC', 'HTTP', 'WEBSOCKET'].
:param py_modules: The customized python modules need to be imported before loading the executor
Note that the recommended way is to only import a single module - a simple python file, if your
executor can be defined in a single file, or an ``__init__.py`` file if you have multiple files,
which should be structured as a python package. For more details, please see the
Expand Down Expand Up @@ -424,7 +422,7 @@ def __init__(
* a docker image (must start with `docker://`)
* the string literal of a YAML config (must start with `!` or `jtype: `)
* the string literal of a JSON config
When use it under Python, one can use the following values additionally:
- a Python dict that represents the config
- a text file stream has `.read()` interface
Expand All @@ -437,13 +435,13 @@ def __init__(
:param uses_requests: Dictionary of keyword arguments that will override the `requests` configuration in `uses`
:param uses_with: Dictionary of keyword arguments that will override the `with` configuration in `uses`
:param uvicorn_kwargs: Dictionary of kwargs arguments that will be passed to Uvicorn server when starting the server
More details can be found in Uvicorn docs: https://www.uvicorn.org/settings/
:param volumes: The path on the host to be mounted inside the container.
Note,
- If separated by `:`, then the first part will be considered as the local host path and the second part is the path in the container system.
- If no split provided, then the basename of that directory will be mounted into container's root path, e.g. `--volumes="/user/test/my-workspace"` will be mounted into `/my-workspace` inside the container.
:param volumes: The path on the host to be mounted inside the container.
Note,
- If separated by `:`, then the first part will be considered as the local host path and the second part is the path in the container system.
- If no split provided, then the basename of that directory will be mounted into container's root path, e.g. `--volumes="/user/test/my-workspace"` will be mounted into `/my-workspace` inside the container.
- All volumes are mounted with read-write mode.
:param when: The condition that the documents need to fulfill before reaching the Executor.The condition can be defined in the form of a `DocArray query condition <https://docarray.jina.ai/fundamentals/documentarray/find/#query-by-conditions>`
:param workspace: The working directory for any IO operations in this object. If not set, then derive from its parent `workspace`.
Expand All @@ -452,7 +450,6 @@ def __init__(
.. # noqa: DAR101
.. # noqa: DAR003
"""

# overload_inject_end_deployment

def __init__(
Expand Down
Loading

0 comments on commit 732149c

Please sign in to comment.