Skip to content

Commit

Permalink
Format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Jul 14, 2024
1 parent e25e316 commit 10cea66
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
4 changes: 3 additions & 1 deletion python/imjoy_rpc/hypha/sse_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shortuuid

from .rpc import RPC
from .websocket_client import WebsocketRPCConnection

try:
import js # noqa: F401
Expand Down Expand Up @@ -95,7 +96,8 @@ async def open(self):
self._retry_count += 1
self._opening.set_exception(
Exception(
f"Failed to connect to {server_url.split('?')[0]} (retry {self._retry_count}/{MAX_RETRY}): {exp}"
f"Failed to connect to {server_url.split('?')[0]} "
f"(retry {self._retry_count}/{MAX_RETRY}): {exp}"
)
)
finally:
Expand Down
2 changes: 2 additions & 0 deletions python/imjoy_rpc/hypha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class SyncHyphaServer:
"""A class to interact with the Hypha server synchronously."""

def __init__(self, sync_max_workers=2):
"""Initialize the SyncHyphaServer."""
self.loop = None
self.thread = None
self.server = None
Expand Down Expand Up @@ -212,6 +213,7 @@ def get_rtc_service(server, service_id, config=None):
print("Public services: #", len(services))

def hello(name):
"""Say hello."""
print("Hello " + name)
print("Current thread id: ", threading.get_ident(), threading.current_thread())
time.sleep(2)
Expand Down
1 change: 0 additions & 1 deletion python/imjoy_rpc/hypha/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ def make_signature(func, name=None, sig=None, doc=None):
sig can be a Signature object or a string without 'def' such as
"foo(a, b=0)"
"""

if isinstance(sig, str):
# Parse signature string
func_name, sig = _str_to_signature(sig)
Expand Down
5 changes: 3 additions & 2 deletions python/imjoy_rpc/hypha/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ async def get_service(query, webrtc=None, webrtc_config=None):
if ":" in svc.id and "/" in svc.id and AIORTC_AVAILABLE:
client = svc.id.split(":")[0]
try:
# Assuming that the client registered a webrtc service with the client_id + "-rtc"
# Assuming that the client registered
# a webrtc service with the client_id + "-rtc"
peer = await get_rtc_service(
wm,
client + ":" + client.split("/")[1] + "-rtc",
Expand All @@ -326,8 +327,8 @@ async def get_service(query, webrtc=None, webrtc_config=None):
wm["getService"] = get_service
return wm


def setup_local_client(enable_execution=False, on_ready=None):
"""Set up a local client."""
fut = asyncio.Future()

async def message_handler(event):
Expand Down
7 changes: 7 additions & 0 deletions python/imjoy_rpc/qr.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""QR code generator and display functions."""
# Code adopted from https://github.com/Khalil-Youssefi/qrcodeT/tree/master
# Released under MIT license

import numpy as np


def qrcode2text(img):
"""Convert a QR code image to text."""
bindata = np.array(img)[::10, ::10] + 0
if bindata.shape[0] % 2 != 0:
bindata.resize((bindata.shape[0] + 1, bindata.shape[1]), refcheck=False)
Expand All @@ -19,6 +21,7 @@ def qrcode2text(img):


def generate_qrcode(txt, fill_color="black", back_color="white"):
"""Generate a QR code image."""
import qrcode

qr = qrcode.QRCode(
Expand All @@ -34,6 +37,7 @@ def generate_qrcode(txt, fill_color="black", back_color="white"):


def print_qrcode(txt):
"""Print a QR code to the console."""
chars = qrcode2text(generate_qrcode(txt))
for i in range(chars.shape[0]):
for j in range(chars.shape[1]):
Expand All @@ -42,6 +46,7 @@ def print_qrcode(txt):


def qrcode2html(txt):
"""Convert a QR code to HTML."""
chars = qrcode2text(generate_qrcode(txt))
qrcode_str = ""
for i in range(chars.shape[0]):
Expand All @@ -52,6 +57,7 @@ def qrcode2html(txt):


def in_ipynb():
"""Check if running in a Jupyter notebook."""
try:
cfg = get_ipython().config
if isinstance(cfg, dict):
Expand All @@ -63,6 +69,7 @@ def in_ipynb():


def display_qrcode(text):
"""Display a QR code in the console or Jupyter notebook."""
if in_ipynb():
from IPython.display import display, HTML

Expand Down
14 changes: 6 additions & 8 deletions python/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from types import BuiltinFunctionType
"""Tests for the utils module."""
from functools import partial
from imjoy_rpc.hypha.utils import callable_sig, callable_doc, make_signature

from inspect import signature

# Import necessary modules
from inspect import signature
from typing import Union, Optional

Expand Down Expand Up @@ -98,7 +95,8 @@ def func(a, b, context=None):
assert callable_sig(func, skip_context=True) == "func(a, b)"

# Lambda function
lambda_func = lambda a, b, context=None: a + b
def lambda_func(a, b, context=None):
return a + b
assert callable_sig(lambda_func) == "lambda(a, b, context=None)"
assert callable_sig(lambda_func, skip_context=True) == "lambda(a, b)"

Expand Down Expand Up @@ -129,7 +127,7 @@ def test_callable_doc():
"""Test callable_doc."""
# Function with docstring
def func_with_doc(a, b):
"This is a function with a docstring"
"""This is a function with a docstring."""
return a + b

assert callable_doc(func_with_doc) == "This is a function with a docstring"
Expand All @@ -138,11 +136,11 @@ def func_with_doc(a, b):
def func_without_doc(a, b):
return a + b

assert callable_doc(func_without_doc) == None
assert callable_doc(func_without_doc) is None

# Partial function with docstring
def partial_func_with_doc(a, b=3):
"This is a partial function with a docstring"
"""This is a partial function with a docstring"""
return a + b

partial_func = partial(partial_func_with_doc, b=3)
Expand Down

0 comments on commit 10cea66

Please sign in to comment.