From acd661f6290166ae2fa045021d994c50d73fad39 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 28 Aug 2023 18:09:26 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20re?= =?UTF-8?q?move=20unused=20imports=20and=20functions=20to=20improve=20code?= =?UTF-8?q?=20cleanliness=20and=20maintainability=20=F0=9F=94=A7=20chore(m?= =?UTF-8?q?ain.py):=20update=20import=20statement=20to=20use=20get=5Fnumbe?= =?UTF-8?q?r=5Fof=5Fworkers=20from=20=5F=5Fmain=5F=5F=20module=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(util.py):=20remove=20unused=20imports=20an?= =?UTF-8?q?d=20functions=20to=20improve=20code=20cleanliness=20and=20maint?= =?UTF-8?q?ainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 32 +++++++++++++++++++++++++++--- src/backend/langflow/main.py | 2 +- src/backend/langflow/utils/util.py | 30 ---------------------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 5c5582fdd..b5ec034de 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -4,9 +4,8 @@ import httpx from langflow.services.database.utils import session_getter from langflow.services.manager import initialize_services, initialize_settings_manager from langflow.services.utils import get_db_manager, get_settings_manager -from langflow.utils.util import get_number_of_workers -from langflow.utils.util import display_results -from multiprocess import Process # type: ignore + +from multiprocess import Process, cpu_count # type: ignore import platform from pathlib import Path from typing import Optional @@ -14,6 +13,7 @@ import socket from rich.panel import Panel from rich import box from rich import print as rprint +from rich.table import Table import typer from langflow.main import setup_app from langflow.utils.logger import configure, logger @@ -27,6 +27,32 @@ console = Console() app = typer.Typer() +def get_number_of_workers(workers=None): + if workers == -1 or workers is None: + workers = (cpu_count() * 2) + 1 + logger.debug(f"Number of workers: {workers}") + return workers + + +def display_results(results): + """ + Display the results of the migration. + """ + for table_results in results: + table = Table(title=f"Migration {table_results.table_name}") + table.add_column("Name") + table.add_column("Type") + table.add_column("Status") + + for result in table_results.results: + status = "Success" if result.success else "Failure" + color = "green" if result.success else "red" + table.add_row(result.name, result.type, f"[{color}]{status}[/{color}]") + + console.print(table) + console.print() # Print a new line + + def update_settings( config: str, cache: str, diff --git a/src/backend/langflow/main.py b/src/backend/langflow/main.py index d0d62a804..57f3e34dc 100644 --- a/src/backend/langflow/main.py +++ b/src/backend/langflow/main.py @@ -89,7 +89,7 @@ def setup_app( if __name__ == "__main__": import uvicorn - from langflow.utils.util import get_number_of_workers + from langflow.__main__ import get_number_of_workers configure() uvicorn.run( diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 890201294..2c8f92ee1 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -5,13 +5,9 @@ from functools import wraps from typing import Optional, Dict, Any, Union from docstring_parser import parse -from langflow.__main__ import console # type: ignore from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS from langflow.utils import constants -from langflow.utils.logger import logger -from multiprocess import cpu_count # type: ignore -from rich.table import Table # type: ignore def build_template_from_function( @@ -460,29 +456,3 @@ def add_options_to_field( value["options"] = options_map[class_name] value["list"] = True value["value"] = options_map[class_name][0] - - -def get_number_of_workers(workers=None): - if workers == -1 or workers is None: - workers = (cpu_count() * 2) + 1 - logger.debug(f"Number of workers: {workers}") - return workers - - -def display_results(results): - """ - Display the results of the migration. - """ - for table_results in results: - table = Table(title=f"Migration {table_results.table_name}") - table.add_column("Name") - table.add_column("Type") - table.add_column("Status") - - for result in table_results.results: - status = "Success" if result.success else "Failure" - color = "green" if result.success else "red" - table.add_row(result.name, result.type, f"[{color}]{status}[/{color}]") - - console.print(table) - console.print() # Print a new line