Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Dec 26, 2024
1 parent 0eb3cb8 commit f2d65d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/git/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .git import GitLoaderComponent
from .gitextractor import GitExtractorComponent

__all__ = ["GitLoaderComponent", "GitExtractorComponent"]
__all__ = ["GitExtractorComponent", "GitLoaderComponent"]
67 changes: 35 additions & 32 deletions src/backend/base/langflow/components/git/gitextractor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import shutil
import tempfile

import git

from langflow.custom import Component
from langflow.io import MessageTextInput, Output
from langflow.schema import Data
from langflow.schema.message import Message
from langflow.io import MessageTextInput, Output
import git
import os
import tempfile
import shutil


class GitExtractorComponent(Component):
display_name = "GitExtractor"
Expand All @@ -23,12 +25,15 @@ class GitExtractorComponent(Component):
]

outputs = [
Output(display_name="Text-Based File Contents", name="text_based_file_contents", method="get_text_based_file_contents"),
Output(
display_name="Text-Based File Contents",
name="text_based_file_contents",
method="get_text_based_file_contents",
),
Output(display_name="Directory Structure", name="directory_structure", method="get_directory_structure"),
Output(display_name="Repository Info", name="repository_info", method="get_repository_info"),
Output(display_name="Statistics", name="statistics", method="get_statistics"),
Output(display_name="Files Content", name="files_content", method="get_files_content"),

]

def get_repository_info(self) -> list[Data]:
Expand All @@ -37,25 +42,25 @@ def get_repository_info(self) -> list[Data]:
try:
repo = git.Repo.clone_from(self.repository_url, temp_dir)
repo_info = {
"name": self.repository_url.split('/')[-1],
"name": self.repository_url.split("/")[-1],
"url": self.repository_url,
"default_branch": repo.active_branch.name,
"remote_urls": [remote.url for remote in repo.remotes],
"last_commit": {
"hash": repo.head.commit.hexsha,
"author": str(repo.head.commit.author),
"message": repo.head.commit.message.strip(),
"date": str(repo.head.commit.committed_datetime)
"date": str(repo.head.commit.committed_datetime),
},
"branches": [str(branch) for branch in repo.branches]
"branches": [str(branch) for branch in repo.branches],
}
result = [Data(data=repo_info)]
self.status = result
return result
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception as e:

Check failure on line 62 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (BLE001)

src/backend/base/langflow/components/git/gitextractor.py:62:16: BLE001 Do not catch blind exception: `Exception`
error_result = [Data(data={"error": f"Error getting repository info: {str(e)}"})]
error_result = [Data(data={"error": f"Error getting repository info: {e!s}"})]
self.status = error_result
return error_result

Expand All @@ -76,7 +81,7 @@ def get_statistics(self) -> list[Data]:
file_path = os.path.join(root, file)

Check failure on line 81 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PTH118)

src/backend/base/langflow/components/git/gitextractor.py:81:37: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
total_size += os.path.getsize(file_path)

Check failure on line 82 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PTH202)

src/backend/base/langflow/components/git/gitextractor.py:82:39: PTH202 `os.path.getsize` should be replaced by `Path.stat().st_size`
try:
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, encoding="utf-8") as f:

Check failure on line 84 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PTH123)

src/backend/base/langflow/components/git/gitextractor.py:84:34: PTH123 `open()` should be replaced by `Path.open()`
total_lines += sum(1 for _ in f)
except UnicodeDecodeError:
binary_files += 1
Expand All @@ -87,15 +92,15 @@ def get_statistics(self) -> list[Data]:
"total_size_mb": round(total_size / (1024 * 1024), 2),
"total_lines": total_lines,
"binary_files": binary_files,
"directories": directories
"directories": directories,
}
result = [Data(data=statistics)]
self.status = result
return result
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception as e:

Check failure on line 102 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (BLE001)

src/backend/base/langflow/components/git/gitextractor.py:102:16: BLE001 Do not catch blind exception: `Exception`
error_result = [Data(data={"error": f"Error calculating statistics: {str(e)}"})]
error_result = [Data(data={"error": f"Error calculating statistics: {e!s}"})]
self.status = error_result
return error_result

Expand All @@ -106,22 +111,22 @@ def get_directory_structure(self) -> Message:
git.Repo.clone_from(self.repository_url, temp_dir)
tree = ["Directory structure:"]
for root, dirs, files in os.walk(temp_dir):

Check failure on line 113 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (B007)

src/backend/base/langflow/components/git/gitextractor.py:113:27: B007 Loop control variable `dirs` not used within loop body
level = root.replace(temp_dir, '').count(os.sep)
indent = ' ' * level
level = root.replace(temp_dir, "").count(os.sep)
indent = " " * level
if level == 0:
tree.append(f"└── {os.path.basename(root)}")

Check failure on line 117 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PTH119)

src/backend/base/langflow/components/git/gitextractor.py:117:44: PTH119 `os.path.basename()` should be replaced by `Path.name`
else:
tree.append(f"{indent}├── {os.path.basename(root)}")

Check failure on line 119 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PTH119)

src/backend/base/langflow/components/git/gitextractor.py:119:52: PTH119 `os.path.basename()` should be replaced by `Path.name`
subindent = ' ' * (level + 1)
subindent = " " * (level + 1)
for f in files:
tree.append(f"{subindent}├── {f}")

Check failure on line 122 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PERF401)

src/backend/base/langflow/components/git/gitextractor.py:122:25: PERF401 Use `list.extend` to create a transformed list
directory_structure = '\n'.join(tree)
directory_structure = "\n".join(tree)
self.status = directory_structure
return Message(text=directory_structure)
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception as e:

Check failure on line 128 in src/backend/base/langflow/components/git/gitextractor.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (BLE001)

src/backend/base/langflow/components/git/gitextractor.py:128:16: BLE001 Do not catch blind exception: `Exception`
error_message = f"Error getting directory structure: {str(e)}"
error_message = f"Error getting directory structure: {e!s}"
self.status = error_message
return Message(text=error_message)

Expand All @@ -137,21 +142,19 @@ def get_files_content(self) -> list[Data]:
relative_path = os.path.relpath(file_path, temp_dir)
file_size = os.path.getsize(file_path)
try:
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, encoding="utf-8") as f:
file_content = f.read()
except UnicodeDecodeError:
file_content = "[BINARY FILE]"
content_list.append(Data(data={
"path": relative_path,
"size": file_size,
"content": file_content
}))
content_list.append(
Data(data={"path": relative_path, "size": file_size, "content": file_content})
)
self.status = content_list
return content_list
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception as e:
error_result = [Data(data={"error": f"Error getting files content: {str(e)}"})]
error_result = [Data(data={"error": f"Error getting files content: {e!s}"})]
self.status = error_result
return error_result

Expand All @@ -171,9 +174,9 @@ def get_text_based_file_contents(self) -> Message:
content_list.append("=" * 50)
content_list.append(f"File: /{relative_path}")
content_list.append("=" * 50)

try:
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, encoding="utf-8") as f:
file_content = f.read()
if total_chars + len(file_content) > char_limit:
remaining_chars = char_limit - total_chars
Expand All @@ -182,12 +185,12 @@ def get_text_based_file_contents(self) -> Message:
total_chars += len(file_content)
except UnicodeDecodeError:
content_list.append("[BINARY FILE]")

content_list.append("") # Add an empty line between files

if total_chars >= char_limit:
break

if total_chars >= char_limit:
break

Expand All @@ -197,6 +200,6 @@ def get_text_based_file_contents(self) -> Message:
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
except Exception as e:
error_message = f"Error getting text-based file contents: {str(e)}"
error_message = f"Error getting text-based file contents: {e!s}"
self.status = error_message
return Message(text=error_message)

0 comments on commit f2d65d0

Please # to comment.