From c31aae730a1787ec2185fa44b8c54dd4017dfdc5 Mon Sep 17 00:00:00 2001 From: Michele Dolfi Date: Sun, 10 Jul 2022 20:33:45 +0200 Subject: [PATCH] mypy does not like dicts Signed-off-by: Michele Dolfi --- deepsearch/cps/data_indices/utils.py | 12 +++++----- deepsearch/documents/core/common_routines.py | 17 ++++++++++---- deepsearch/documents/core/convert.py | 24 ++++++++++---------- deepsearch/documents/core/utils.py | 6 ++--- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/deepsearch/cps/data_indices/utils.py b/deepsearch/cps/data_indices/utils.py index 3ce640f0..69afd010 100644 --- a/deepsearch/cps/data_indices/utils.py +++ b/deepsearch/cps/data_indices/utils.py @@ -78,10 +78,10 @@ def process_url_input( count_urls = len(urls) with tqdm( total=count_urls, - desc=f"{'Submitting input:': <{progressbar['padding']}}", + desc=f"{'Submitting input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: for url in urls: payload = {"file_url": url} @@ -138,10 +138,10 @@ def process_local_file( # start loop with tqdm( total=count_total_files, - desc=f"{'Submitting input:': <{progressbar['padding']}}", + desc=f"{'Submitting input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: # loop over all files for single_zip in files_zip: diff --git a/deepsearch/documents/core/common_routines.py b/deepsearch/documents/core/common_routines.py index fe794a30..2e9d182f 100644 --- a/deepsearch/documents/core/common_routines.py +++ b/deepsearch/documents/core/common_routines.py @@ -1,11 +1,18 @@ +from dataclasses import dataclass + dashes = f"{'-'*86}" WELCOME = f"{dashes}\n{'':>26}Welcome to the Deep Search Toolkit\n{dashes}" ERROR_MSG = f"{dashes}\nSuggestion:\n(1) Check your input.\n(2) Contact Deep Search developers if problem persists.\n{dashes}" # setup for progress bars progressbar_length = 30 -progressbar = { - "padding": 22, - "colour": "#0f62fe", - "bar_format": "{l_bar}{bar:%d}{r_bar}{bar:-10b}" % (progressbar_length), -} + + +@dataclass +class ProgressBarParameters: + padding = 22 + colour = "#0f62fe" + bar_format = "{l_bar}{bar:%d}{r_bar}{bar:-10b}" % (progressbar_length) + + +progressbar = ProgressBarParameters() success_message = "Whoa... it is done. Until next time, Ciao!" diff --git a/deepsearch/documents/core/convert.py b/deepsearch/documents/core/convert.py index 72f5cd0e..3df6776f 100644 --- a/deepsearch/documents/core/convert.py +++ b/deepsearch/documents/core/convert.py @@ -129,10 +129,10 @@ def send_files_for_conversion( # start loop with tqdm( total=count_total_files, - desc=f"{'Submitting input:': <{progressbar['padding']}}", + desc=f"{'Submitting input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: # loop over all files for single_zip in files_zip: @@ -168,10 +168,10 @@ def check_status_running_tasks( with tqdm( total=count_total, - desc=f"{'Converting input:': <{progressbar['padding']}}", + desc=f"{'Converting input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: for task_id in task_ids: request_status = check_single_task_status( @@ -232,10 +232,10 @@ def download_converted_documents( with tqdm( total=len(download_urls), - desc=f"{'Downloading result:': <{progressbar['padding']}}", + desc=f"{'Downloading result:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: count = 1 for url in download_urls: @@ -280,10 +280,10 @@ def send_urls_for_conversion( task_ids = [] with tqdm( total=count_urls, - desc=f"{'Submitting input:': <{progressbar['padding']}}", + desc=f"{'Submitting input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: for url in urls: task_id = submit_url_for_conversion( diff --git a/deepsearch/documents/core/utils.py b/deepsearch/documents/core/utils.py index cf116e0e..74dfc43d 100644 --- a/deepsearch/documents/core/utils.py +++ b/deepsearch/documents/core/utils.py @@ -70,10 +70,10 @@ def batch_single_files( if len(files_pdf) != 0: with tqdm( total=len(files_pdf), - desc=f"{'Processing input:': <{progressbar['padding']}}", + desc=f"{'Processing input:': <{progressbar.padding}}", disable=not (progress_bar), - colour=progressbar["colour"], - bar_format=progressbar["bar_format"], + colour=progressbar.colour, + bar_format=progressbar.bar_format, ) as progress: # loop over pdfs for single_doc in files_pdf: