From a3a950c290074385bfc38c9459ce838658b1ad92 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Thu, 3 Oct 2024 10:55:49 +0200 Subject: [PATCH] ref: Add more ruff rules (#3994) Add more ruff rules --- src/backend/base/langflow/__init__.py | 0 src/backend/base/langflow/api/v1/endpoints.py | 2 +- src/backend/base/langflow/base/curl/parse.py | 49 +++++++++++-------- .../components/assemblyai/__init__.py | 0 .../deactivated/ChatLiteLLMModel.py | 2 +- .../langchain_utilities/FirecrawlCrawlApi.py | 4 +- .../langchain_utilities/FirecrawlScrapeApi.py | 4 +- .../memories/CassandraChatMemory.py | 2 +- .../components/memories/ZepChatMemory.py | 2 +- .../components/prototypes/JSONCleaner.py | 2 +- .../components/vectorstores/Cassandra.py | 2 +- .../components/vectorstores/CassandraGraph.py | 2 +- .../components/vectorstores/Chroma.py | 4 +- .../langflow/components/vectorstores/HCD.py | 2 +- .../components/vectorstores/Milvus.py | 4 +- .../custom/custom_component/component.py | 4 +- src/backend/base/langflow/graph/edge/base.py | 8 +-- src/backend/base/pyproject.toml | 6 +++ 18 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 src/backend/base/langflow/__init__.py create mode 100644 src/backend/base/langflow/components/assemblyai/__init__.py diff --git a/src/backend/base/langflow/__init__.py b/src/backend/base/langflow/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 70c8ce798..7f5e06a48 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -521,7 +521,7 @@ async def process( """ # Raise a depreciation warning logger.warning( - "The /process endpoint is deprecated and will be removed in a future version. " "Please use /run instead." + "The /process endpoint is deprecated and will be removed in a future version. Please use /run instead." ) raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, diff --git a/src/backend/base/langflow/base/curl/parse.py b/src/backend/base/langflow/base/curl/parse.py index 055f92499..e5e2de87a 100644 --- a/src/backend/base/langflow/base/curl/parse.py +++ b/src/backend/base/langflow/base/curl/parse.py @@ -15,30 +15,37 @@ followed by a newline with a space. import re import shlex -from collections import OrderedDict, namedtuple +from collections import OrderedDict from http.cookies import SimpleCookie +from typing import NamedTuple -ParsedArgs = namedtuple( - "ParsedArgs", - [ - "command", - "url", - "data", - "data_binary", - "method", - "headers", - "compressed", - "insecure", - "user", - "include", - "silent", - "proxy", - "proxy_user", - "cookies", - ], -) -ParsedContext = namedtuple("ParsedContext", ["method", "url", "data", "headers", "cookies", "verify", "auth", "proxy"]) +class ParsedArgs(NamedTuple): + command: str | None + url: str | None + data: str | None + data_binary: str | None + method: str + headers: list[str] + compressed: bool + insecure: bool + user: tuple[str, str] + include: bool + silent: bool + proxy: str | None + proxy_user: str | None + cookies: dict[str, str] + + +class ParsedContext(NamedTuple): + method: str + url: str + data: str | None + headers: dict[str, str] + cookies: dict[str, str] + verify: bool + auth: tuple[str, str] | None + proxy: dict[str, str] | None def normalize_newlines(multiline_text): diff --git a/src/backend/base/langflow/components/assemblyai/__init__.py b/src/backend/base/langflow/components/assemblyai/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/backend/base/langflow/components/deactivated/ChatLiteLLMModel.py b/src/backend/base/langflow/components/deactivated/ChatLiteLLMModel.py index 0af61d39e..7e521abb8 100644 --- a/src/backend/base/langflow/components/deactivated/ChatLiteLLMModel.py +++ b/src/backend/base/langflow/components/deactivated/ChatLiteLLMModel.py @@ -125,7 +125,7 @@ class ChatLiteLLMModelComponent(LCModelComponent): litellm.drop_params = True litellm.set_verbose = self.verbose except ImportError as e: - msg = "Could not import litellm python package. " "Please install it with `pip install litellm`" + msg = "Could not import litellm python package. Please install it with `pip install litellm`" raise ChatLiteLLMException(msg) from e # Remove empty keys if "" in self.kwargs: diff --git a/src/backend/base/langflow/components/langchain_utilities/FirecrawlCrawlApi.py b/src/backend/base/langflow/components/langchain_utilities/FirecrawlCrawlApi.py index f9edeb5ac..25e910186 100644 --- a/src/backend/base/langflow/components/langchain_utilities/FirecrawlCrawlApi.py +++ b/src/backend/base/langflow/components/langchain_utilities/FirecrawlCrawlApi.py @@ -57,9 +57,7 @@ class FirecrawlCrawlApi(CustomComponent): try: from firecrawl.firecrawl import FirecrawlApp # type: ignore except ImportError as e: - msg = ( - "Could not import firecrawl integration package. " "Please install it with `pip install firecrawl-py`." - ) + msg = "Could not import firecrawl integration package. Please install it with `pip install firecrawl-py`." raise ImportError(msg) from e crawler_options_dict = crawlerOptions.__dict__["data"]["text"] if crawlerOptions else {} diff --git a/src/backend/base/langflow/components/langchain_utilities/FirecrawlScrapeApi.py b/src/backend/base/langflow/components/langchain_utilities/FirecrawlScrapeApi.py index 81c3145df..440ca46b2 100644 --- a/src/backend/base/langflow/components/langchain_utilities/FirecrawlScrapeApi.py +++ b/src/backend/base/langflow/components/langchain_utilities/FirecrawlScrapeApi.py @@ -50,9 +50,7 @@ class FirecrawlScrapeApi(CustomComponent): try: from firecrawl.firecrawl import FirecrawlApp # type: ignore except ImportError as e: - msg = ( - "Could not import firecrawl integration package. " "Please install it with `pip install firecrawl-py`." - ) + msg = "Could not import firecrawl integration package. Please install it with `pip install firecrawl-py`." raise ImportError(msg) from e extractor_options_dict = extractorOptions.__dict__["data"]["text"] if extractorOptions else {} diff --git a/src/backend/base/langflow/components/memories/CassandraChatMemory.py b/src/backend/base/langflow/components/memories/CassandraChatMemory.py index 69812c00e..8bb1b6bb4 100644 --- a/src/backend/base/langflow/components/memories/CassandraChatMemory.py +++ b/src/backend/base/langflow/components/memories/CassandraChatMemory.py @@ -55,7 +55,7 @@ class CassandraChatMemory(LCChatMemoryComponent): try: import cassio except ImportError as e: - msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." + msg = "Could not import cassio integration package. Please install it with `pip install cassio`." raise ImportError(msg) from e from uuid import UUID diff --git a/src/backend/base/langflow/components/memories/ZepChatMemory.py b/src/backend/base/langflow/components/memories/ZepChatMemory.py index 2edb9a6c0..90060e694 100644 --- a/src/backend/base/langflow/components/memories/ZepChatMemory.py +++ b/src/backend/base/langflow/components/memories/ZepChatMemory.py @@ -35,7 +35,7 @@ class ZepChatMemory(LCChatMemoryComponent): zep_python.zep_client.API_BASE_PATH = self.api_base_path except ImportError as e: - msg = "Could not import zep-python package. " "Please install it with `pip install zep-python`." + msg = "Could not import zep-python package. Please install it with `pip install zep-python`." raise ImportError(msg) from e zep_client = ZepClient(api_url=self.url, api_key=self.api_key) diff --git a/src/backend/base/langflow/components/prototypes/JSONCleaner.py b/src/backend/base/langflow/components/prototypes/JSONCleaner.py index 3e4fd49e1..6f98b44c5 100644 --- a/src/backend/base/langflow/components/prototypes/JSONCleaner.py +++ b/src/backend/base/langflow/components/prototypes/JSONCleaner.py @@ -48,7 +48,7 @@ class JSONCleaner(Component): try: from json_repair import repair_json # type: ignore except ImportError as e: - msg = "Could not import the json_repair package." "Please install it with `pip install json_repair`." + msg = "Could not import the json_repair package. Please install it with `pip install json_repair`." raise ImportError(msg) from e """Clean the input JSON string based on provided options and return the cleaned JSON string.""" diff --git a/src/backend/base/langflow/components/vectorstores/Cassandra.py b/src/backend/base/langflow/components/vectorstores/Cassandra.py index e4293b9ec..19ab2eb18 100644 --- a/src/backend/base/langflow/components/vectorstores/Cassandra.py +++ b/src/backend/base/langflow/components/vectorstores/Cassandra.py @@ -137,7 +137,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent): import cassio from langchain_community.utilities.cassandra import SetupMode except ImportError as e: - msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." + msg = "Could not import cassio integration package. Please install it with `pip install cassio`." raise ImportError(msg) from e from uuid import UUID diff --git a/src/backend/base/langflow/components/vectorstores/CassandraGraph.py b/src/backend/base/langflow/components/vectorstores/CassandraGraph.py index 6d0ed872e..557da2c24 100644 --- a/src/backend/base/langflow/components/vectorstores/CassandraGraph.py +++ b/src/backend/base/langflow/components/vectorstores/CassandraGraph.py @@ -126,7 +126,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent): import cassio from langchain_community.utilities.cassandra import SetupMode except ImportError as e: - msg = "Could not import cassio integration package. " "Please install it with `pip install cassio`." + msg = "Could not import cassio integration package. Please install it with `pip install cassio`." raise ImportError(msg) from e database_ref = self.database_ref diff --git a/src/backend/base/langflow/components/vectorstores/Chroma.py b/src/backend/base/langflow/components/vectorstores/Chroma.py index affdfb0ea..92a2ef83a 100644 --- a/src/backend/base/langflow/components/vectorstores/Chroma.py +++ b/src/backend/base/langflow/components/vectorstores/Chroma.py @@ -107,9 +107,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent): from chromadb import Client from langchain_chroma import Chroma except ImportError as e: - msg = ( - "Could not import Chroma integration package. " "Please install it with `pip install langchain-chroma`." - ) + msg = "Could not import Chroma integration package. Please install it with `pip install langchain-chroma`." raise ImportError(msg) from e # Chroma settings chroma_settings = None diff --git a/src/backend/base/langflow/components/vectorstores/HCD.py b/src/backend/base/langflow/components/vectorstores/HCD.py index 3ead01b18..78580d877 100644 --- a/src/backend/base/langflow/components/vectorstores/HCD.py +++ b/src/backend/base/langflow/components/vectorstores/HCD.py @@ -191,7 +191,7 @@ class HCDVectorStoreComponent(LCVectorStoreComponent): from astrapy.authentication import UsernamePasswordTokenProvider from astrapy.constants import Environment except ImportError as e: - msg = "Could not import astrapy integration package. " "Please install it with `pip install astrapy`." + msg = "Could not import astrapy integration package. Please install it with `pip install astrapy`." raise ImportError(msg) from e try: diff --git a/src/backend/base/langflow/components/vectorstores/Milvus.py b/src/backend/base/langflow/components/vectorstores/Milvus.py index f2ca43bb3..0ebefdf45 100644 --- a/src/backend/base/langflow/components/vectorstores/Milvus.py +++ b/src/backend/base/langflow/components/vectorstores/Milvus.py @@ -74,9 +74,7 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent): try: from langchain_milvus.vectorstores import Milvus as LangchainMilvus except ImportError as e: - msg = ( - "Could not import Milvus integration package. " "Please install it with `pip install langchain-milvus`." - ) + msg = "Could not import Milvus integration package. Please install it with `pip install langchain-milvus`." raise ImportError(msg) from e self.connection_args.update(uri=self.uri, token=self.password) milvus_store = LangchainMilvus( diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index f06e96301..cbf71377a 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -572,9 +572,7 @@ class Component(CustomComponent): except KeyError as e: close_match = find_closest_match(name, list(template.keys())) if close_match: - msg = ( - f"Parameter '{name}' not found in {self.__class__.__name__}. " f"Did you mean '{close_match}'?" - ) + msg = f"Parameter '{name}' not found in {self.__class__.__name__}. Did you mean '{close_match}'?" raise ValueError(msg) from e msg = f"Parameter {name} not found in {self.__class__.__name__}. " raise ValueError(msg) from e diff --git a/src/backend/base/langflow/graph/edge/base.py b/src/backend/base/langflow/graph/edge/base.py index 7e0284041..7454bb964 100644 --- a/src/backend/base/langflow/graph/edge/base.py +++ b/src/backend/base/langflow/graph/edge/base.py @@ -89,7 +89,7 @@ class Edge: if not self.valid_handles: logger.debug(self.source_handle) logger.debug(self.target_handle) - msg = f"Edge between {source.display_name} and {target.display_name} " f"has invalid handles" + msg = f"Edge between {source.display_name} and {target.display_name} has invalid handles" raise ValueError(msg) def _legacy_validate_handles(self, source, target) -> None: @@ -103,7 +103,7 @@ class Edge: if not self.valid_handles: logger.debug(self.source_handle) logger.debug(self.target_handle) - msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has invalid handles" + msg = f"Edge between {source.vertex_type} and {target.vertex_type} has invalid handles" raise ValueError(msg) def __setstate__(self, state): @@ -160,7 +160,7 @@ class Edge: if no_matched_type: logger.debug(self.source_types) logger.debug(self.target_reqs) - msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has no matched type. " + msg = f"Edge between {source.vertex_type} and {target.vertex_type} has no matched type." raise ValueError(msg) def _legacy_validate_edge(self, source, target) -> None: @@ -182,7 +182,7 @@ class Edge: if no_matched_type: logger.debug(self.source_types) logger.debug(self.target_reqs) - msg = f"Edge between {source.vertex_type} and {target.vertex_type} " f"has no matched type" + msg = f"Edge between {source.vertex_type} and {target.vertex_type} has no matched type" raise ValueError(msg) def __repr__(self) -> str: diff --git a/src/backend/base/pyproject.toml b/src/backend/base/pyproject.toml index 54a0fa525..1a15ea8d3 100644 --- a/src/backend/base/pyproject.toml +++ b/src/backend/base/pyproject.toml @@ -168,13 +168,18 @@ select = [ "FA", "FLY", "FURB", + "G", "I", "ICN", "INT", + "INP", + "ISC", "LOG", "NPY", "PD", "PIE", + "PT", + "PYI", "Q", "RET", "RSE", @@ -188,6 +193,7 @@ select = [ ] ignore = [ "COM812", # Messes with the formatter + "ISC001", # Messes with the formatter ] [tool.uv]