From 3806458aa7665d63e575d075d4e5561a5822452e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:15:40 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tqdm_publisher/_demo/_client.css | 2 +- .../_demo/_demo_command_line_interface.py | 9 ++++----- src/tqdm_publisher/_demo/_multiple/_server.py | 5 ++--- src/tqdm_publisher/_demo/_single_bar/_server.py | 14 +++++++------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/tqdm_publisher/_demo/_client.css b/src/tqdm_publisher/_demo/_client.css index 35c818c..5134a39 100644 --- a/src/tqdm_publisher/_demo/_client.css +++ b/src/tqdm_publisher/_demo/_client.css @@ -34,4 +34,4 @@ header { height: 100%; background-color: #4caf50; width: 0%; -} \ No newline at end of file +} diff --git a/src/tqdm_publisher/_demo/_demo_command_line_interface.py b/src/tqdm_publisher/_demo/_demo_command_line_interface.py index 2a6c0b7..22b5bdc 100644 --- a/src/tqdm_publisher/_demo/_demo_command_line_interface.py +++ b/src/tqdm_publisher/_demo/_demo_command_line_interface.py @@ -1,9 +1,8 @@ import os import subprocess import sys -from pathlib import Path - import webbrowser +from pathlib import Path DEMOS = { "single": "_single", @@ -44,15 +43,15 @@ def _command_line_interface(): # client_relative_path = Path(subpath) / "_client.py" # subprocess.Popen(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")]) # subprocess.Popen(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_client.py")]) - + # else: client_relative_path = Path(subpath) / "_client.html" - subprocess.Popen(['python', '-m', 'http.server', str(CLIENT_PORT), "-d", DEMO_BASE_FOLDER_PATH]) + subprocess.Popen(["python", "-m", "http.server", str(CLIENT_PORT), "-d", DEMO_BASE_FOLDER_PATH]) webbrowser.open_new_tab(f"http://localhost:{CLIENT_PORT}/{client_relative_path}") - subprocess.run(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")]) + subprocess.run(["python", str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")]) else: print(f"{command} is an invalid command.") diff --git a/src/tqdm_publisher/_demo/_multiple/_server.py b/src/tqdm_publisher/_demo/_multiple/_server.py index 856b679..d56b06f 100644 --- a/src/tqdm_publisher/_demo/_multiple/_server.py +++ b/src/tqdm_publisher/_demo/_multiple/_server.py @@ -33,7 +33,7 @@ def run(self): Defaults are chosen for a deterministic and regular update period of one second for a total time of one minute. """ - all_task_durations_in_seconds = [.1 for _ in range(100)] # Ten seconds of one hundred tasks + all_task_durations_in_seconds = [0.1 for _ in range(100)] # Ten seconds of one hundred tasks progress_bar = self.progress_bar = tqdm_publisher.TQDMPublisher(iterable=all_task_durations_in_seconds) progress_bar.subscribe(callback=self.update) @@ -44,7 +44,6 @@ def run(self): # thread = threading.Thread(target=self.run_progress_bar) # thread.start() - # Wait for messages from the client async for message in websocket: message_from_client = json.loads(message) @@ -66,4 +65,4 @@ def run_demo() -> None: if __name__ == "__main__": - run_demo() \ No newline at end of file + run_demo() diff --git a/src/tqdm_publisher/_demo/_single_bar/_server.py b/src/tqdm_publisher/_demo/_single_bar/_server.py index ff3da61..ca2b02d 100644 --- a/src/tqdm_publisher/_demo/_single_bar/_server.py +++ b/src/tqdm_publisher/_demo/_single_bar/_server.py @@ -14,7 +14,7 @@ def start_progress_bar(*, progress_callback: callable) -> None: Defaults are chosen for a deterministic and regular update period of one second for a total time of one minute. """ - all_task_durations_in_seconds = [.1 for _ in range(100)] # Ten seconds of one hundred tasks + all_task_durations_in_seconds = [0.1 for _ in range(100)] # Ten seconds of one hundred tasks progress_bar = tqdm_publisher.TQDMPublisher(iterable=all_task_durations_in_seconds) def run_function_on_progress_update(format_dict: dict) -> None: @@ -44,9 +44,8 @@ def send_message_to_client(*, websocket: websockets.WebSocketServerProtocol, mes This expects a WebSocket connection and a message (dict) to send. """ - asyncio.run( - websocket.send(message=json.dumps(obj=message)) - ) + asyncio.run(websocket.send(message=json.dumps(obj=message))) + async def handler(websocket: websockets.WebSocketServerProtocol) -> None: """Handle messages from the client and manage the client connections.""" @@ -60,10 +59,11 @@ async def handler(websocket: websockets.WebSocketServerProtocol) -> None: # Start the progress bar in a separate thread thread = threading.Thread( target=start_progress_bar, - # On each update of the progress bar, send this update to the requesting client kwargs=dict( - progress_callback=lambda id, format_dict: send_message_to_client(websocket, dict(id=id, format_dict=format_dict)) + progress_callback=lambda id, format_dict: send_message_to_client( + websocket, dict(id=id, format_dict=format_dict) + ) ), ) thread.start() @@ -81,4 +81,4 @@ def run_demo() -> None: if __name__ == "__main__": - run_demo() \ No newline at end of file + run_demo()