Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add various ruff rules #3974

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/base/langflow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def migration(
if not typer.confirm(
"This will delete all data necessary to fix migrations. Are you sure you want to continue?"
):
raise typer.Abort()
raise typer.Abort

initialize_services(fix_migration=fix)
db_service = get_db_service()
Expand Down
2 changes: 0 additions & 2 deletions src/backend/base/langflow/base/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class LCAgentComponent(Component):
@abstractmethod
def build_agent(self) -> AgentExecutor:
"""Create the agent."""
pass

async def message_response(self) -> Message:
"""Run the agent and return the response."""
Expand Down Expand Up @@ -156,4 +155,3 @@ async def run_agent(
@abstractmethod
def create_agent_runnable(self) -> Runnable:
"""Create the agent."""
pass
2 changes: 1 addition & 1 deletion src/backend/base/langflow/base/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def parse_text_file_to_data(file_path: str, silent_errors: bool) -> Data | None:
text = [normalize_text(item) if isinstance(item, str) else item for item in text]
text = orjson.dumps(text).decode("utf-8")

elif file_path.endswith(".yaml") or file_path.endswith(".yml"):
elif file_path.endswith((".yaml", ".yml")):
text = yaml.safe_load(text)
elif file_path.endswith(".xml"):
xml_element = ET.fromstring(text)
Expand Down
2 changes: 0 additions & 2 deletions src/backend/base/langflow/base/document_transformers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ def get_data_input(self) -> Any:
"""
Get the data input.
"""
pass

@abstractmethod
def build_document_transformer(self) -> BaseDocumentTransformer:
"""
Build the text splitter.
"""
pass
2 changes: 0 additions & 2 deletions src/backend/base/langflow/base/langchain_utilities/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ def run_model(self) -> Data | list[Data]:
"""
Run model and return the output.
"""
pass

@abstractmethod
def build_tool(self) -> Tool | Sequence[Tool]:
"""
Build the tool.
"""
pass
1 change: 0 additions & 1 deletion src/backend/base/langflow/base/textsplitters/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ def build_text_splitter(self) -> TextSplitter:
"""
Build the text splitter.
"""
pass
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/chains/RetrievalQA.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def invoke_chain(self) -> Message:
result_str = str(result.get("result", ""))
if self.return_source_documents and len(source_docs):
references_str = self.create_references_from_data(source_docs)
result_str = "\n".join([result_str, references_str])
result_str = f"{result_str}\n{references_str}"
# put the entire result to debug history, query and content
self.status = {**result, "source_documents": source_docs, "output": result_str}
return result_str
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ def parse_classes(self, node: ast.ClassDef) -> None:
nodes.append(class_node)
except Exception as exc:
logger.error(f"Error finding base class node: {exc}")
pass
nodes.insert(0, node)
class_details = ClassCodeDetails(
name=node.name,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/custom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_field_properties(extra_field):


def process_type(field_type: str):
if field_type.startswith("list") or field_type.startswith("List"):
if field_type.startswith(("list", "List")):
return extract_inner_type(field_type)

# field_type is a string can be Prompt or Code too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def hierarchical_tasks_agent_graph():
template="""User's query:
{query}

Respond to the user with as much as information as you can about the topic. Delete if needed.
Respond to the user with as much as information as you can about the topic. Delete if needed.
If it is just a general query (e.g a greeting) you can respond them directly.""",
query=chat_input.message_response,
)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/inputs/input_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class FieldTypes(str, Enum):
TEXT = "str"
INTEGER = "int"
PASSWORD = "str"
PASSWORD = "str" # noqa: PIE796
FLOAT = "float"
BOOLEAN = "bool"
DICT = "dict"
Expand Down
18 changes: 13 additions & 5 deletions src/backend/base/langflow/services/storage/local.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from pathlib import Path

from loguru import logger
Expand Down Expand Up @@ -33,9 +34,12 @@ async def save_file(self, flow_id: str, file_name: str, data: bytes):
folder_path.mkdir(parents=True, exist_ok=True)
file_path = folder_path / file_name

try:
def write_file(file_path: Path, data: bytes) -> None:
with open(file_path, "wb") as f:
f.write(data)

try:
await asyncio.get_event_loop().run_in_executor(None, write_file, file_path, data)
logger.info(f"File {file_name} saved successfully in flow {flow_id}.")
except Exception as e:
logger.error(f"Error saving file {file_name} in flow {flow_id}: {e}")
Expand All @@ -55,9 +59,13 @@ async def get_file(self, flow_id: str, file_name: str) -> bytes:
logger.warning(f"File {file_name} not found in flow {flow_id}.")
raise FileNotFoundError(f"File {file_name} not found in flow {flow_id}")

with open(file_path, "rb") as f:
logger.debug(f"File {file_name} retrieved successfully from flow {flow_id}.")
return f.read()
def read_file(file_path: Path) -> bytes:
with open(file_path, "rb") as f:
return f.read()

content = await asyncio.get_event_loop().run_in_executor(None, read_file, file_path)
logger.debug(f"File {file_name} retrieved successfully from flow {flow_id}.")
return content

async def list_files(self, flow_id: str):
"""
Expand Down Expand Up @@ -92,4 +100,4 @@ async def delete_file(self, flow_id: str, file_name: str):

async def teardown(self):
"""Perform any cleanup operations when the service is being torn down."""
pass # No specific teardown actions required for local
# No specific teardown actions required for local
1 change: 0 additions & 1 deletion src/backend/base/langflow/services/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ async def delete_file(self, folder: str, file_name: str):
async def teardown(self):
"""Perform any cleanup operations when the service is being torn down."""
# No specific teardown actions required for S3 storage at the moment.
pass
8 changes: 4 additions & 4 deletions src/backend/base/langflow/services/store/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def get_components_in_users_collection(self, component_ids: list[str], api

async def download(self, api_key: str, component_id: UUID) -> DownloadComponentResponse:
url = f"{self.components_url}/{component_id}"
params = {"fields": ",".join(["id", "name", "description", "data", "is_component", "metadata"])}
params = {"fields": "id,name,description,data,is_component,metadata"}
if not self.download_webhook_url:
raise ValueError("DOWNLOAD_WEBHOOK_URL is not set")
component, _ = await self._get(url, api_key, params)
Expand Down Expand Up @@ -420,14 +420,14 @@ async def update(

async def get_tags(self) -> list[dict[str, Any]]:
url = f"{self.base_url}/items/tags"
params = {"fields": ",".join(["id", "name"])}
params = {"fields": "id,name"}
tags, _ = await self._get(url, api_key=None, params=params)
return tags

async def get_user_likes(self, api_key: str) -> list[dict[str, Any]]:
url = f"{self.base_url}/users/me"
params = {
"fields": ",".join(["id", "likes"]),
"fields": "id,likes",
}
likes, _ = await self._get(url, api_key, params)
return likes
Expand All @@ -436,7 +436,7 @@ async def get_component_likes_count(self, component_id: str, api_key: str | None
url = f"{self.components_url}/{component_id}"

params = {
"fields": ",".join(["id", "count(liked_by)"]),
"fields": "id,count(liked_by)",
}
result, _ = await self._get(url, api_key=api_key, params=params)
if len(result) == 0:
Expand Down
29 changes: 28 additions & 1 deletion src/backend/base/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,34 @@ exclude = ["langflow/alembic"]
line-length = 120

[tool.ruff.lint]
select = ["C4", "E", "F", "I", "UP"]
select = [
"ASYNC",
"C4",
"COM",
"DJ",
"E",
"F",
"FLY",
"FURB",
"I",
"ICN",
"INT",
"LOG",
"NPY",
"PD",
"PIE",
"Q",
"RSE",
"SLOT",
"T10",
"TID",
"UP",
"W",
"YTT"
]
ignore = [
"COM812", # Messes with the formatter
]

[build-system]
requires = ["hatchling"]
Expand Down
Loading