Skip to content

Commit

Permalink
fix: ruff lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed May 6, 2024
1 parent 6c64bcc commit 6464f51
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ build-backend = "poetry.core.masonry.api"

[tool.ruff]
line-length = 90
extend-exclude = ["locust"]

[tool.ruff.lint]
select = ["E", "F", "C", "D"]
Expand Down
3 changes: 3 additions & 0 deletions socket_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Simple test client."""

import asyncio
import websockets


async def hello():
"""Connect and say hello."""
async with websockets.connect("ws://localhost:8765/ws") as websocket:
for i in range(5):
print(f"> Hello world! ({i})", flush=True)
Expand Down
1 change: 1 addition & 0 deletions socketdock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""SocketDock."""
2 changes: 0 additions & 2 deletions socketdock/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

def config() -> argparse.Namespace:
"""Parse command line arguments."""

parser = argparse.ArgumentParser(
prog="SocketDock", description="Socket Gateway for configurable backends"
)
Expand All @@ -31,7 +30,6 @@ def config() -> argparse.Namespace:

def main():
"""Run the SocketDock server."""

args = config()
if args.backend == "loopback":
from .testbackend import TestBackend
Expand Down
11 changes: 7 additions & 4 deletions socketdock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ async def socket_handler(request: Request, websocket: Websocket):
global lifetime_connections
backend = backend_var.get()
socket_id = None
endpoint = endpoint_var.get()
send = f"{endpoint}/socket/{socket_id}/send"
disconnect = f"{endpoint_var.get()}/socket/{socket_id}/disconnect"
try:
# register user
LOGGER.info("new client connected")
Expand All @@ -92,8 +95,8 @@ async def socket_handler(request: Request, websocket: Websocket):
{
"connection_id": socket_id,
"headers": dict(request.headers.items()),
"send": f"{endpoint_var.get()}/socket/{socket_id}/send",
"disconnect": f"{endpoint_var.get()}/socket/{socket_id}/disconnect",
"send": send,
"disconnect": disconnect,
},
)

Expand All @@ -102,8 +105,8 @@ async def socket_handler(request: Request, websocket: Websocket):
await backend.inbound_socket_message(
{
"connection_id": socket_id,
"send": f"{endpoint_var.get()}/socket/{socket_id}/send",
"disconnect": f"{endpoint_var.get()}/socket/{socket_id}/disconnect",
"send": send,
"disconnect": disconnect,
},
message,
)
Expand Down
13 changes: 9 additions & 4 deletions socketdock/testbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ class TestBackend(Backend):
"""Test backend for SocketDock."""

async def socket_connected(self, callback_uris: dict):
# This test method doesn't care, but can be useful to clean up state.
pass
"""Socket connected.
This test backend doesn't care, but can be useful to clean up state.
"""

async def inbound_socket_message(
self, callback_uris: dict, message: Union[str, bytes]
):
"""Receive socket message."""
# send three backend messages in response
# TODO: send response message via callback URI for sending a message
send_uri = callback_uris["send"]
Expand All @@ -27,5 +30,7 @@ async def inbound_socket_message(
# response = requests.post(send_uri, data="Hello yourself!")

async def socket_disconnected(self, bundle: dict):
# This test method doesn't care, but can be useful to clean up state.
pass
"""Socket disconnected.
This test backend doesn't care, but can be useful to clean up state.
"""

0 comments on commit 6464f51

Please sign in to comment.