Skip to content

Commit

Permalink
chore: adopt ruff
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <kemingy94@gmail.com>
  • Loading branch information
kemingy committed Feb 16, 2024
1 parent 17e16e5 commit 5ab7504
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 44 deletions.
2 changes: 0 additions & 2 deletions mosec/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def set_mosec_timeout(duration: int):
"""Context manager to set a timeout for a code block.
Args:
----
duration (float): the duration in seconds before timing out
"""
Expand Down Expand Up @@ -114,7 +113,6 @@ def __init__(
"""Initialize the mosec coordinator.
Args:
----
worker: subclass of `mosec.Worker` implemented by users.
max_batch_size: maximum batch size for this worker.
shutdown: `multiprocessing.synchronize.Event` object for shutdown IPC.
Expand Down
8 changes: 2 additions & 6 deletions mosec/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def __init__(self, process_context: SpawnContext, shutdown_notify: Event):
"""Initialize a process pool.
Args:
----
process_context: server context of spawn process
shutdown_notify: event of server will shutdown
Expand All @@ -94,7 +93,6 @@ def start_worker(self, worker_runtime: Runtime, init: bool):
"""Start the worker process for dry run.
Args:
----
worker_runtime: worker runtime to start
init: whether the worker is tried to start at the first time
Expand All @@ -121,8 +119,7 @@ def start_worker(self, worker_runtime: Runtime, init: bool):
def probe_worker_liveness(self) -> Tuple[Union[int, None], Union[int, None]]:
"""Check every worker is running/alive.
Returns
-------
Returns:
index: index of the first failed worker
exitcode: exitcode of the first failed worker
Expand All @@ -135,8 +132,7 @@ def probe_worker_liveness(self) -> Tuple[Union[int, None], Union[int, None]]:
def wait_all(self) -> Tuple[Union[int, None], Union[int, None]]:
"""Blocking until all worker to end or one failed.
Returns
-------
Returns:
index: index of the first failed worker
exitcode: exitcode of the first failed worker
Expand Down
2 changes: 0 additions & 2 deletions mosec/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def __init__(
"""Init with `%` style format.
Args:
----
fmt (str): logging message format (% style)
datefmt (str): datatime format
prefix (str): prefix of target
Expand Down Expand Up @@ -108,7 +107,6 @@ def __init__(
"""Init with `%` style format.
Args:
----
fmt (str): logging message format (% style)
datefmt (str): datatime format
prefix (str): prefix of target
Expand Down
6 changes: 0 additions & 6 deletions mosec/mixin/msgpack_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ def serialize(self, data: Any) -> bytes:
"""Serialize with msgpack for the last stage (egress).
Arguments:
---------
data: the **same type** as returned by
:py:meth:`Worker.forward <mosec.worker.Worker.forward>`
Returns:
-------
the bytes you want to put into the response body
Raises:
------
EncodingError: if the data cannot be serialized with msgpack
"""
Expand All @@ -63,16 +60,13 @@ def deserialize(self, data: bytes) -> Any:
"""Deserialize method for the first stage (ingress).
Arguments:
---------
data: the raw bytes extracted from the request body
Returns:
-------
the **same type** as the input of
:py:meth:`Worker.forward <mosec.worker.Worker.forward>`
Raises:
------
DecodingError: if the data cannot be deserialized with msgpack
"""
Expand Down
1 change: 0 additions & 1 deletion mosec/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def __init__(
"""Initialize the protocol client.
Args:
----
name (str): name of its belonging coordinator.
addr (str): Unix domain socket address in file system's namespace.
timeout (float, optional): socket timeout. Defaults to 2.0 seconds.
Expand Down
7 changes: 0 additions & 7 deletions mosec/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def __init__(
"""Initialize the mosec coordinator.
Args:
----
worker (Worker): subclass of `mosec.Worker` implemented by users.
num (int): number of workers
max_batch_size: the maximum batch size allowed (>=1), will enable the
Expand Down Expand Up @@ -140,14 +139,12 @@ def _check(
"""Check and start the worker process if it has not started yet.
Args:
----
work_path: path of working directory
shutdown: Event of server shutdown
shutdown_notify: Event of server will shutdown
init: whether the worker is tried to start at the first time
Returns:
-------
Whether the worker is started successfully
"""
Expand Down Expand Up @@ -190,7 +187,6 @@ def __init__(self, work_path: str, shutdown: Event, shutdown_notify: Event):
"""Initialize a coordinator manager.
Args:
----
work_path: path of working directory
shutdown: Event of server shutdown
shutdown_notify: Event of server will shutdown
Expand Down Expand Up @@ -220,7 +216,6 @@ def check_and_start(self, init: bool) -> Union[Runtime, None]:
"""Check all worker processes and try to start failed ones.
Args:
----
init: whether the worker is tried to start at the first time
"""
Expand All @@ -239,7 +234,6 @@ def __init__(self, timeout: int):
"""Initialize a Mosec manager.
Args:
----
timeout: service timeout in milliseconds
"""
Expand Down Expand Up @@ -277,7 +271,6 @@ def start(self, config_path: Path) -> subprocess.Popen:
"""Start the Mosec process.
Args:
----
config_path: configuration path of mosec
"""
Expand Down
4 changes: 0 additions & 4 deletions mosec/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
model serving.
Dynamic Batching
----------------
The user may enable the dynamic batching feature for any stage when the
corresponding worker is appended, by setting the
:py:meth:`append_worker(max_batch_size) <Server.append_worker>`.
Multiprocessing
---------------
The user may spawn multiple processes for any stage when the
corresponding worker is appended, by setting the
Expand Down Expand Up @@ -176,7 +174,6 @@ def register_daemon(self, name: str, proc: subprocess.Popen):
"""Register a daemon to be monitored.
Args:
----
name: the name of this daemon
proc: the process handle of the daemon
Expand All @@ -202,7 +199,6 @@ def append_worker(
"""Sequentially appends workers to the workflow pipeline.
Args:
----
worker: the class you inherit from :class:`Worker<mosec.worker.Worker>`
which implements the :py:meth:`forward<mosec.worker.Worker.forward>`
num: the number of processes for parallel computing (>=1)
Expand Down
12 changes: 0 additions & 12 deletions mosec/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def serialize_ipc(self, data: Any) -> bytes:
"""Define IPC serialization method.
Args:
----
data: returned data from :py:meth:`forward`
"""
Expand All @@ -90,7 +89,6 @@ def deserialize_ipc(self, data: bytes) -> Any:
"""Define IPC deserialization method.
Args:
----
data: input data for :py:meth:`forward`
"""
Expand Down Expand Up @@ -137,15 +135,12 @@ def serialize(self, data: Any) -> bytes:
Check :py:mod:`mosec.mixin` for more information.
Arguments:
---------
data: the same type as the output of the :py:meth:`forward`
Returns:
-------
the bytes you want to put into the response body
Raises:
------
EncodingError: if the data cannot be serialized with JSON
"""
Expand All @@ -163,15 +158,12 @@ def deserialize(self, data: bytes) -> Any:
Check :py:mod:`mosec.mixin` for more information.
Arguments:
---------
data: the raw bytes extracted from the request body
Returns:
-------
the same type as the input of the :py:meth:`forward`
Raises:
------
DecodingError: if the data cannot be deserialized with JSON
"""
Expand All @@ -186,7 +178,6 @@ def forward(self, data: Any) -> Any:
"""Model inference, data processing or computation logic.
Args:
----
data: input data to be processed
**Must be overridden** by the subclass.
Expand Down Expand Up @@ -220,13 +211,11 @@ def get_forward_json_schema(
"""Retrieve the JSON schema for the `forward` method of the class.
Args:
----
cls : The class object.
target : The target variable to parse the schema for.
ref_template : A template to use when generating ``"$ref"`` fields.
Returns:
-------
A tuple containing the schema and the component schemas.
The :py:meth:`get_forward_json_schema` method is a class method that returns the
Expand Down Expand Up @@ -260,7 +249,6 @@ def send_stream_event(self, text: str, index: int = 0):
"""Send a stream event to the client.
Args:
----
text: the text to be sent, needs to be UTF-8 compatible
index: the index of the stream event. For the single request, this will
always be 0. For dynamic batch request, this should be the index of
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,11 @@ module = [
ignore_missing_imports = true

[tool.pyright]
pythonPlatform = ["Linux", "Darwin"]
pythonPlatform = "Linux"
pythonVersion = "3.8"
include = ["mosec", "tests", "examples"]
reportMissingImports = "warning"

[pydocstyle]
convention = "google"

[tool.pytest.ini_options]
markers = [
"shm: mark a test is related to shared memory",
Expand All @@ -93,3 +90,5 @@ max-args = 10
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D"]
"examples/*" = ["D"]
[tool.ruff.lint.pydocstyle]
convention = "google"

0 comments on commit 5ab7504

Please sign in to comment.