diff --git a/integrations/github/pyproject.toml b/integrations/github/pyproject.toml index 264afab59d..2e5fe7c1ff 100644 --- a/integrations/github/pyproject.toml +++ b/integrations/github/pyproject.toml @@ -7,7 +7,7 @@ name = "github-haystack" dynamic = ["version"] description = 'Haystack components for interacting with GitHub repositories' readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.10" license = "Apache-2.0" keywords = [] authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }] @@ -15,7 +15,6 @@ classifiers = [ "License :: OSI Approved :: Apache Software License", "Development Status :: 4 - Beta", "Programming Language :: Python", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", @@ -23,7 +22,7 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] -dependencies = ["haystack-ai>=2.12.0"] +dependencies = ["haystack-ai>=2.22.0"] [project.urls] Source = "https://github.com/deepset-ai/haystack-core-integrations/github" @@ -77,7 +76,6 @@ check_untyped_defs = true disallow_incomplete_defs = true [tool.ruff] -target-version = "py39" line-length = 120 [tool.ruff.lint] @@ -124,10 +122,6 @@ ignore = [ "B008", "S101", ] -unfixable = [ - # Don't touch unused imports - "F401", -] [tool.ruff.lint.isort] known-first-party = ["haystack_integrations"] diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/file_editor.py b/integrations/github/src/haystack_integrations/components/connectors/github/file_editor.py index edbfdad8dd..9b72214dde 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/file_editor.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/file_editor.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 from base64 import b64decode, b64encode from enum import Enum -from typing import Any, Optional, Union +from typing import Any import requests from haystack import component, default_from_dict, default_to_dict, logging @@ -79,7 +79,7 @@ def __init__( self, *, github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"), - repo: Optional[str] = None, + repo: str | None = None, branch: str = "main", raise_on_failure: bool = True, ): @@ -145,7 +145,7 @@ def _update_file(self, owner: str, repo: str, path: str, content: str, message: def _check_last_commit(self, owner: str, repo: str, branch: str) -> bool: """Check if last commit was made by the current token user.""" url = f"https://api.github.com/repos/{owner}/{repo}/commits" - params: dict[str, Union[str, int]] = {"per_page": 1, "sha": branch} + params: dict[str, str | int] = {"per_page": 1, "sha": branch} response = requests.get(url, headers=self._get_request_headers(), params=params, timeout=10) response.raise_for_status() last_commit = response.json()[0] @@ -191,7 +191,7 @@ def _undo_changes(self, owner: str, repo: str, payload: dict[str, Any], branch: commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits" # Get the previous commit SHA - params: dict[str, Union[str, int]] = {"per_page": 2, "sha": branch} + params: dict[str, str | int] = {"per_page": 2, "sha": branch} commits = requests.get(commits_url, headers=self._get_request_headers(), params=params, timeout=10).json() previous_sha = commits[1]["sha"] @@ -244,10 +244,10 @@ def _delete_file(self, owner: str, repo: str, payload: dict[str, str], branch: s @component.output_types(result=str) def run( self, - command: Union[Command, str], + command: Command | str, payload: dict[str, Any], - repo: Optional[str] = None, - branch: Optional[str] = None, + repo: str | None = None, + branch: str | None = None, ) -> dict[str, str]: """ Process GitHub file operations. diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/issue_viewer.py b/integrations/github/src/haystack_integrations/components/connectors/github/issue_viewer.py index 2182400594..83e90c5edd 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/issue_viewer.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/issue_viewer.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 import re -from typing import Any, Optional +from typing import Any import requests from haystack import Document, component, default_from_dict, default_to_dict, logging @@ -37,7 +37,7 @@ class GitHubIssueViewer: def __init__( self, *, - github_token: Optional[Secret] = None, + github_token: Secret | None = None, raise_on_failure: bool = True, retry_attempts: int = 2, ): diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/pr_creator.py b/integrations/github/src/haystack_integrations/components/connectors/github/pr_creator.py index 72193a63dd..2c2e8d8eda 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/pr_creator.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/pr_creator.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 import re -from typing import Any, Optional +from typing import Any import requests from haystack import component, default_from_dict, default_to_dict, logging @@ -102,7 +102,7 @@ def _check_fork_exists(self, repo: str, fork_owner: str) -> bool: except requests.RequestException: return False - def _create_fork(self, owner: str, repo: str) -> Optional[str]: + def _create_fork(self, owner: str, repo: str) -> str | None: """Create a fork of the repository.""" url = f"https://api.github.com/repos/{owner}/{repo}/forks" try: diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py b/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py index 021c60dfeb..725a3e18b8 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import re import time -from typing import Any, Optional +from typing import Any import requests from haystack import component, default_from_dict, default_to_dict, logging @@ -137,7 +137,7 @@ def _get_authenticated_user(self) -> str: response.raise_for_status() return response.json()["login"] - def _get_existing_repository(self, repo_name: str) -> Optional[str]: + def _get_existing_repository(self, repo_name: str) -> str | None: """ Check if a repository with the given name already exists in the authenticated user's account. diff --git a/integrations/github/src/haystack_integrations/components/connectors/github/repo_viewer.py b/integrations/github/src/haystack_integrations/components/connectors/github/repo_viewer.py index 692c823a5a..edf6a8a50e 100644 --- a/integrations/github/src/haystack_integrations/components/connectors/github/repo_viewer.py +++ b/integrations/github/src/haystack_integrations/components/connectors/github/repo_viewer.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import base64 from dataclasses import dataclass -from typing import Any, Optional +from typing import Any import requests from haystack import Document, component, default_from_dict, default_to_dict, logging @@ -21,7 +21,7 @@ class GitHubItem: path: str size: int url: str - content: Optional[str] = None + content: str | None = None @component @@ -71,10 +71,10 @@ class GitHubRepoViewer: def __init__( self, *, - github_token: Optional[Secret] = None, + github_token: Secret | None = None, raise_on_failure: bool = True, max_file_size: int = 1_000_000, # 1MB default limit - repo: Optional[str] = None, + repo: str | None = None, branch: str = "main", ): """ @@ -207,7 +207,7 @@ def _create_error_document(self, error: Exception, path: str) -> Document: ) @component.output_types(documents=list[Document]) - def run(self, path: str, repo: Optional[str] = None, branch: Optional[str] = None) -> dict[str, list[Document]]: + def run(self, path: str, repo: str | None = None, branch: str | None = None) -> dict[str, list[Document]]: """ Process a GitHub repository path and return documents. diff --git a/integrations/github/src/haystack_integrations/tools/github/file_editor_tool.py b/integrations/github/src/haystack_integrations/tools/github/file_editor_tool.py index 59c18530d6..3254c02deb 100644 --- a/integrations/github/src/haystack_integrations/tools/github/file_editor_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/file_editor_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,16 +21,16 @@ class GitHubFileEditorTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "file_editor", - description: Optional[str] = FILE_EDITOR_PROMPT, - parameters: Optional[dict[str, Any]] = FILE_EDITOR_SCHEMA, + name: str | None = "file_editor", + description: str | None = FILE_EDITOR_PROMPT, + parameters: dict[str, Any] | None = FILE_EDITOR_SCHEMA, github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"), - repo: Optional[str] = None, + repo: str | None = None, branch: str = "main", raise_on_failure: bool = True, - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub file editor tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/issue_commenter_tool.py b/integrations/github/src/haystack_integrations/tools/github/issue_commenter_tool.py index 00afc4233c..eb89c67397 100644 --- a/integrations/github/src/haystack_integrations/tools/github/issue_commenter_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/issue_commenter_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,15 +21,15 @@ class GitHubIssueCommenterTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "issue_commenter", - description: Optional[str] = ISSUE_COMMENTER_PROMPT, - parameters: Optional[dict[str, Any]] = ISSUE_COMMENTER_SCHEMA, + name: str | None = "issue_commenter", + description: str | None = ISSUE_COMMENTER_PROMPT, + parameters: dict[str, Any] | None = ISSUE_COMMENTER_SCHEMA, github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"), raise_on_failure: bool = True, retry_attempts: int = 2, - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub issue commenter tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/issue_viewer_tool.py b/integrations/github/src/haystack_integrations/tools/github/issue_viewer_tool.py index 171fdf99ce..47326c7a71 100644 --- a/integrations/github/src/haystack_integrations/tools/github/issue_viewer_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/issue_viewer_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,15 +21,15 @@ class GitHubIssueViewerTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "issue_viewer", - description: Optional[str] = ISSUE_VIEWER_PROMPT, - parameters: Optional[dict[str, Any]] = ISSUE_VIEWER_SCHEMA, - github_token: Optional[Secret] = None, + name: str | None = "issue_viewer", + description: str | None = ISSUE_VIEWER_PROMPT, + parameters: dict[str, Any] | None = ISSUE_VIEWER_SCHEMA, + github_token: Secret | None = None, raise_on_failure: bool = True, retry_attempts: int = 2, - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub issue viewer tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/pr_creator_tool.py b/integrations/github/src/haystack_integrations/tools/github/pr_creator_tool.py index 984a34880d..f076535146 100644 --- a/integrations/github/src/haystack_integrations/tools/github/pr_creator_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/pr_creator_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,14 +21,14 @@ class GitHubPRCreatorTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "pr_creator", - description: Optional[str] = PR_CREATOR_PROMPT, - parameters: Optional[dict[str, Any]] = PR_CREATOR_SCHEMA, + name: str | None = "pr_creator", + description: str | None = PR_CREATOR_PROMPT, + parameters: dict[str, Any] | None = PR_CREATOR_SCHEMA, github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"), raise_on_failure: bool = True, - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub PR creator tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/repo_forker_tool.py b/integrations/github/src/haystack_integrations/tools/github/repo_forker_tool.py index a662eb33c3..aade61ed32 100644 --- a/integrations/github/src/haystack_integrations/tools/github/repo_forker_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/repo_forker_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,14 +21,14 @@ class GitHubRepoForkerTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "repo_forker", - description: Optional[str] = REPO_FORKER_PROMPT, - parameters: Optional[dict[str, Any]] = REPO_FORKER_SCHEMA, + name: str | None = "repo_forker", + description: str | None = REPO_FORKER_PROMPT, + parameters: dict[str, Any] | None = REPO_FORKER_SCHEMA, github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"), raise_on_failure: bool = True, - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub Repo Forker tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/repo_viewer_tool.py b/integrations/github/src/haystack_integrations/tools/github/repo_viewer_tool.py index be6eb153dc..91d40a0ab5 100644 --- a/integrations/github/src/haystack_integrations/tools/github/repo_viewer_tool.py +++ b/integrations/github/src/haystack_integrations/tools/github/repo_viewer_tool.py @@ -1,7 +1,8 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack.core.serialization import generate_qualified_class_name from haystack.tools import ComponentTool @@ -20,17 +21,17 @@ class GitHubRepoViewerTool(ComponentTool): def __init__( self, *, - name: Optional[str] = "repo_viewer", - description: Optional[str] = REPO_VIEWER_PROMPT, - parameters: Optional[dict[str, Any]] = REPO_VIEWER_SCHEMA, - github_token: Optional[Secret] = None, - repo: Optional[str] = None, + name: str | None = "repo_viewer", + description: str | None = REPO_VIEWER_PROMPT, + parameters: dict[str, Any] | None = REPO_VIEWER_SCHEMA, + github_token: Secret | None = None, + repo: str | None = None, branch: str = "main", raise_on_failure: bool = True, max_file_size: int = 1_000_000, # 1MB default limit - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None, - inputs_from_state: Optional[dict[str, str]] = None, - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None, + inputs_from_state: dict[str, str] | None = None, + outputs_to_state: dict[str, dict[str, str | Callable]] | None = None, ): """ Initialize the GitHub repository viewer tool. diff --git a/integrations/github/src/haystack_integrations/tools/github/utils.py b/integrations/github/src/haystack_integrations/tools/github/utils.py index 4321a41347..3b66fb79cf 100644 --- a/integrations/github/src/haystack_integrations/tools/github/utils.py +++ b/integrations/github/src/haystack_integrations/tools/github/utils.py @@ -2,7 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Callable, Optional, Union +from collections.abc import Callable +from typing import Any from haystack import Document from haystack.utils.callable_serialization import deserialize_callable, serialize_callable @@ -33,8 +34,8 @@ def message_handler(documents: list[Document], max_length: int = 150_000) -> str def serialize_handlers( serialized: dict[str, Any], - outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]], - outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]], + outputs_to_state: dict[str, dict[str, str | Callable]] | None, + outputs_to_string: dict[str, str | Callable[[Any], str]] | None, ) -> None: """ Serializes callable handlers in outputs_to_state and outputs_to_string.