From 5ee995e89d5f8a46bc21435c8b9c8c8038f39aff Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Wed, 11 Dec 2024 14:37:29 +0100 Subject: [PATCH] ref: Fix some ruff preview rules (#5156) Fix some ruff preview rules --- src/backend/base/langflow/api/utils.py | 3 +-- src/backend/base/langflow/api/v1/endpoints.py | 3 +-- src/backend/base/langflow/base/curl/parse.py | 2 +- src/backend/base/langflow/base/data/base_file.py | 6 +----- .../base/langflow/components/composio/composio_api.py | 2 +- .../base/langflow/components/deactivated/merge_data.py | 2 +- .../base/langflow/components/helpers/structured_output.py | 2 +- .../base/langflow/components/processing/merge_data.py | 2 +- .../base/langflow/components/processing/update_data.py | 4 ++-- src/backend/base/langflow/components/tools/astradb_cql.py | 4 ++-- .../base/langflow/components/tools/youtube_transcripts.py | 8 +++----- .../base/langflow/components/unstructured/unstructured.py | 3 +-- .../base/langflow/custom/custom_component/component.py | 5 +---- .../langflow/custom/directory_reader/directory_reader.py | 2 +- src/backend/base/langflow/logging/logger.py | 2 +- .../base/langflow/services/tracing/arize_phoenix.py | 4 ++-- .../helpers/test_structured_output_component.py | 4 ++-- .../starter_projects/test_vector_store_rag.py | 7 +++---- 18 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index e331d93ea..7f3d98a01 100644 --- a/src/backend/base/langflow/api/utils.py +++ b/src/backend/base/langflow/api/utils.py @@ -261,8 +261,7 @@ def get_suggestion_message(outdated_components: list[str]) -> str: ) components = ", ".join(outdated_components) return ( - f"The flow contains {count} outdated components. " - f"We recommend updating the following components: {components}." + f"The flow contains {count} outdated components. We recommend updating the following components: {components}." ) diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 4bf4787d0..34504564c 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -511,8 +511,7 @@ async def process() -> None: ) raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail="The /process endpoint is deprecated and will be removed in a future version. " - "Please use /run instead.", + detail="The /process endpoint is deprecated and will be removed in a future version. Please use /run instead.", ) diff --git a/src/backend/base/langflow/base/curl/parse.py b/src/backend/base/langflow/base/curl/parse.py index 93af7abe4..4a5ccaf94 100644 --- a/src/backend/base/langflow/base/curl/parse.py +++ b/src/backend/base/langflow/base/curl/parse.py @@ -141,7 +141,7 @@ def parse_context(curl_command): for curl_header in parsed_args.headers: if curl_header.startswith(":"): - occurrence = [m.start() for m in re.finditer(":", curl_header)] + occurrence = [m.start() for m in re.finditer(r":", curl_header)] header_key, header_value = curl_header[: occurrence[1]], curl_header[occurrence[1] + 1 :] else: header_key, header_value = curl_header.split(":", 1) diff --git a/src/backend/base/langflow/base/data/base_file.py b/src/backend/base/langflow/base/data/base_file.py index 46f4ab415..21d6b33df 100644 --- a/src/backend/base/langflow/base/data/base_file.py +++ b/src/backend/base/langflow/base/data/base_file.py @@ -88,11 +88,7 @@ class BaseFileComponent(Component, ABC): text_preview = f"text_preview='{text_preview}'" else: text_preview = f"{len(self.data)} data objects" - return ( - f"BaseFile(path={self.path}" - f", delete_after_processing={self.delete_after_processing}" - f", {text_preview}" - ) + return f"BaseFile(path={self.path}, delete_after_processing={self.delete_after_processing}, {text_preview}" # Subclasses can override these class variables VALID_EXTENSIONS: list[str] = [] # To be overridden by child classes diff --git a/src/backend/base/langflow/components/composio/composio_api.py b/src/backend/base/langflow/components/composio/composio_api.py index e94af95cb..cd9a26a5b 100644 --- a/src/backend/base/langflow/components/composio/composio_api.py +++ b/src/backend/base/langflow/components/composio/composio_api.py @@ -233,7 +233,7 @@ class ComposioAPIComponent(LCToolComponent): build_config[field]["show"] = True build_config[field]["advanced"] = False - if field_name in {"app_names"} and hasattr(self, "api_key") and self.api_key != "": + if field_name == "app_names" and hasattr(self, "api_key") and self.api_key != "": # app_name = self._get_normalized_app_name() app_name = self.app_names try: diff --git a/src/backend/base/langflow/components/deactivated/merge_data.py b/src/backend/base/langflow/components/deactivated/merge_data.py index 853801317..8c57a7888 100644 --- a/src/backend/base/langflow/components/deactivated/merge_data.py +++ b/src/backend/base/langflow/components/deactivated/merge_data.py @@ -76,7 +76,7 @@ class MergeDataComponent(Component): # Use the existing value if the key exists, otherwise use an empty string value = data_input.data.get(key, "") if key not in data_input.data: - log_message = f"Key '{key}' missing in data input at index {idx}. " "Assigning empty string." + log_message = f"Key '{key}' missing in data input at index {idx}. Assigning empty string." logger.debug(log_message) merged_data_dict[key] = value diff --git a/src/backend/base/langflow/components/helpers/structured_output.py b/src/backend/base/langflow/components/helpers/structured_output.py index 26615691a..61cca1260 100644 --- a/src/backend/base/langflow/components/helpers/structured_output.py +++ b/src/backend/base/langflow/components/helpers/structured_output.py @@ -55,7 +55,7 @@ class StructuredOutputComponent(Component): "display_name": "Type", "type": "str", "description": ( - "Indicate the data type of the output field " "(e.g., str, int, float, bool, list, dict)." + "Indicate the data type of the output field (e.g., str, int, float, bool, list, dict)." ), "default": "text", }, diff --git a/src/backend/base/langflow/components/processing/merge_data.py b/src/backend/base/langflow/components/processing/merge_data.py index b82d8160a..819895ff0 100644 --- a/src/backend/base/langflow/components/processing/merge_data.py +++ b/src/backend/base/langflow/components/processing/merge_data.py @@ -76,7 +76,7 @@ class MergeDataComponent(Component): # Use the existing value if the key exists, otherwise use an empty string value = data_input.data.get(key, "") if key not in data_input.data: - log_message = f"Key '{key}' missing in data input at index {idx}. " "Assigning empty string." + log_message = f"Key '{key}' missing in data input at index {idx}. Assigning empty string." logger.debug(log_message) merged_data_dict[key] = value diff --git a/src/backend/base/langflow/components/processing/update_data.py b/src/backend/base/langflow/components/processing/update_data.py index 206c9924f..a79ad3691 100644 --- a/src/backend/base/langflow/components/processing/update_data.py +++ b/src/backend/base/langflow/components/processing/update_data.py @@ -78,7 +78,7 @@ class UpdateDataComponent(Component): if field_value_int > self.MAX_FIELDS: build_config["number_of_fields"]["value"] = self.MAX_FIELDS - msg = f"Number of fields cannot exceed {self.MAX_FIELDS}. " "Try using a Component to combine two Data." + msg = f"Number of fields cannot exceed {self.MAX_FIELDS}. Try using a Component to combine two Data." raise ValueError(msg) existing_fields = {} @@ -154,5 +154,5 @@ class UpdateDataComponent(Component): """This function validates that the Text Key is one of the keys in the Data.""" data_keys = data.data.keys() if self.text_key and self.text_key not in data_keys: - msg = f"Text Key: '{self.text_key}' not found in the Data keys: " f"{', '.join(data_keys)}" + msg = f"Text Key: '{self.text_key}' not found in the Data keys: {', '.join(data_keys)}" raise ValueError(msg) diff --git a/src/backend/base/langflow/components/tools/astradb_cql.py b/src/backend/base/langflow/components/tools/astradb_cql.py index 79c3904c8..5c2fa7dd0 100644 --- a/src/backend/base/langflow/components/tools/astradb_cql.py +++ b/src/backend/base/langflow/components/tools/astradb_cql.py @@ -111,10 +111,10 @@ class AstraDBCQLToolComponent(LCToolComponent): elif self.static_filters[k] is not None: key.append(self.static_filters[k]) - url = f'{astra_url}{"/".join(key)}?page-size={self.number_of_results}' + url = f"{astra_url}{'/'.join(key)}?page-size={self.number_of_results}" if self.projection_fields != "*": - url += f'&fields={urllib.parse.quote(self.projection_fields.replace(" ", ""))}' + url += f"&fields={urllib.parse.quote(self.projection_fields.replace(' ', ''))}" res = requests.request("GET", url=url, headers=headers, timeout=10) diff --git a/src/backend/base/langflow/components/tools/youtube_transcripts.py b/src/backend/base/langflow/components/tools/youtube_transcripts.py index 04b671bc1..cc4561d69 100644 --- a/src/backend/base/langflow/components/tools/youtube_transcripts.py +++ b/src/backend/base/langflow/components/tools/youtube_transcripts.py @@ -27,8 +27,7 @@ class YouTubeTranscriptsComponent(Component): display_name="Transcript Format", options=["text", "chunks"], value="text", - info="The format of the transcripts. Either 'text' for a single output " - "or 'chunks' for timestamped chunks.", + info="The format of the transcripts. Either 'text' for a single output or 'chunks' for timestamped chunks.", advanced=True, ), IntInput( @@ -179,8 +178,7 @@ class YouTubeTranscriptsComponent(Component): ], value="en", info=( - "Specify to make sure the transcripts are retrieved in your desired language. " - "Defaults to English: 'en'" + "Specify to make sure the transcripts are retrieved in your desired language. Defaults to English: 'en'" ), ), DropdownInput( @@ -188,7 +186,7 @@ class YouTubeTranscriptsComponent(Component): display_name="Translation Language", advanced=True, options=["", "en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "hi", "ar", "id"], - info="Translate the transcripts to the specified language. " "Leave empty for no translation.", + info="Translate the transcripts to the specified language. Leave empty for no translation.", ), ] diff --git a/src/backend/base/langflow/components/unstructured/unstructured.py b/src/backend/base/langflow/components/unstructured/unstructured.py index 0e8de67fc..f4946fc2e 100644 --- a/src/backend/base/langflow/components/unstructured/unstructured.py +++ b/src/backend/base/langflow/components/unstructured/unstructured.py @@ -8,8 +8,7 @@ from langflow.schema import Data class UnstructuredComponent(BaseFileComponent): display_name = "Unstructured API" description = ( - "Uses Unstructured.io API to extract clean text from raw source documents. " - "Supports a wide range of file types." + "Uses Unstructured.io API to extract clean text from raw source documents. Supports a wide range of file types." ) documentation = ( "https://python.langchain.com/api_reference/unstructured/document_loaders/" diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 3185fce6c..08a1e8f4a 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -625,10 +625,7 @@ class Component(CustomComponent): def _set_parameter_or_attribute(self, key, value) -> None: if isinstance(value, Component): methods = ", ".join([f"'{output.method}'" for output in value.outputs]) - msg = ( - f"You set {value.display_name} as value for `{key}`. " - f"You should pass one of the following: {methods}" - ) + msg = f"You set {value.display_name} as value for `{key}`. You should pass one of the following: {methods}" raise TypeError(msg) self._set_input_value(key, value) self._parameters[key] = value diff --git a/src/backend/base/langflow/custom/directory_reader/directory_reader.py b/src/backend/base/langflow/custom/directory_reader/directory_reader.py index 840652418..81ac913f5 100644 --- a/src/backend/base/langflow/custom/directory_reader/directory_reader.py +++ b/src/backend/base/langflow/custom/directory_reader/directory_reader.py @@ -75,7 +75,7 @@ class DirectoryReader: continue items.append({"name": menu["name"], "path": menu["path"], "components": components}) filtered = [menu for menu in items if menu["components"]] - logger.debug(f'Filtered components {"with errors" if with_errors else ""}: {len(filtered)}') + logger.debug(f"Filtered components {'with errors' if with_errors else ''}: {len(filtered)}") return {"menu": filtered} def validate_code(self, file_content) -> bool: diff --git a/src/backend/base/langflow/logging/logger.py b/src/backend/base/langflow/logging/logger.py index b4cc10435..4db331d58 100644 --- a/src/backend/base/langflow/logging/logger.py +++ b/src/backend/base/langflow/logging/logger.py @@ -22,7 +22,7 @@ from langflow.settings import DEV VALID_LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] # Human-readable DEFAULT_LOG_FORMAT = ( - "{time:YYYY-MM-DD HH:mm:ss} - " "{level: <8} - {module} - {message}" + "{time:YYYY-MM-DD HH:mm:ss} - {level: <8} - {module} - {message}" ) diff --git a/src/backend/base/langflow/services/tracing/arize_phoenix.py b/src/backend/base/langflow/services/tracing/arize_phoenix.py index 94bc24df2..475da19c2 100644 --- a/src/backend/base/langflow/services/tracing/arize_phoenix.py +++ b/src/backend/base/langflow/services/tracing/arize_phoenix.py @@ -74,13 +74,13 @@ class ArizePhoenixTracer(BaseTracer): def setup_arize_phoenix(self) -> bool: """Configures Arize/Phoenix specific environment variables and registers the tracer provider.""" - arize_phoenix_batch = os.getenv("ARIZE_PHOENIX_BATCH", "False").lower() in ( + arize_phoenix_batch = os.getenv("ARIZE_PHOENIX_BATCH", "False").lower() in { "true", "t", "yes", "y", "1", - ) + } # Arize Config arize_api_key = os.getenv("ARIZE_API_KEY", None) diff --git a/src/backend/tests/unit/components/helpers/test_structured_output_component.py b/src/backend/tests/unit/components/helpers/test_structured_output_component.py index bce79b4b5..adebc6a43 100644 --- a/src/backend/tests/unit/components/helpers/test_structured_output_component.py +++ b/src/backend/tests/unit/components/helpers/test_structured_output_component.py @@ -116,7 +116,7 @@ class TestStructuredOutputComponent: "display_name": "Type", "type": "str", "description": ( - "Indicate the data type of the output field " "(e.g., str, int, float, bool, list, dict)." + "Indicate the data type of the output field (e.g., str, int, float, bool, list, dict)." ), }, { @@ -158,7 +158,7 @@ class TestStructuredOutputComponent: "display_name": "Type", "type": "str", "description": ( - "Indicate the data type of the output field " "(e.g., str, int, float, bool, list, dict)." + "Indicate the data type of the output field (e.g., str, int, float, bool, list, dict)." ), }, { diff --git a/src/backend/tests/unit/initial_setup/starter_projects/test_vector_store_rag.py b/src/backend/tests/unit/initial_setup/starter_projects/test_vector_store_rag.py index 183f1740b..87515a0f2 100644 --- a/src/backend/tests/unit/initial_setup/starter_projects/test_vector_store_rag.py +++ b/src/backend/tests/unit/initial_setup/starter_projects/test_vector_store_rag.py @@ -215,10 +215,9 @@ def test_vector_store_rag_add(ingestion_graph: Graph, rag_graph: Graph): f"Vertices mismatch: {len(ingestion_graph_copy.vertices)} " f"!= {len(ingestion_graph.vertices)} + {len(rag_graph.vertices)}" ) - assert len(ingestion_graph_copy.edges) == len(ingestion_graph.edges) + len(rag_graph.edges), ( - f"Edges mismatch: {len(ingestion_graph_copy.edges)} " - f"!= {len(ingestion_graph.edges)} + {len(rag_graph.edges)}" - ) + assert len(ingestion_graph_copy.edges) == len(ingestion_graph.edges) + len( + rag_graph.edges + ), f"Edges mismatch: {len(ingestion_graph_copy.edges)} != {len(ingestion_graph.edges)} + {len(rag_graph.edges)}" combined_graph_dump = ingestion_graph_copy.dump( name="Combined Graph", description="Graph for data ingestion and RAG", endpoint_name="combined"