Skip to content

Commit 1c4865d

Browse files
committed
fix: remove redundant imports and errors
1 parent abe2ca4 commit 1c4865d

5 files changed

Lines changed: 10 additions & 18 deletions

File tree

integrations/amazon_textract/pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ classifiers = [
2828
"Programming Language :: Python :: 3.13",
2929
"Programming Language :: Python :: 3.14",
3030
"Programming Language :: Python :: Implementation :: CPython",
31-
"Programming Language :: Python :: Implementation :: PyPy",
3231
]
3332
dependencies = [
3433
"haystack-ai>=2.24.1",
@@ -63,7 +62,6 @@ fmt-check = "ruff check {args} && ruff format --check {args}"
6362
[tool.hatch.envs.test]
6463
dependencies = [
6564
"pytest",
66-
"pytest-asyncio",
6765
"pytest-cov",
6866
"pytest-rerunfailures",
6967
"mypy",
@@ -173,7 +171,7 @@ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
173171
[tool.pytest.ini_options]
174172
addopts = "--strict-markers"
175173
markers = [
174+
"unit: unit tests",
176175
"integration: integration tests",
177176
]
178177
log_cli = true
179-
asyncio_default_fixture_loop_scope = "function"

integrations/amazon_textract/src/haystack_integrations/components/converters/amazon_textract/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
from haystack_integrations.components.converters.amazon_textract.converter import AmazonTextractConverter
5+
from .converter import AmazonTextractConverter
6+
from .errors import AmazonTextractConfigurationError
67

7-
__all__ = ["AmazonTextractConverter"]
8+
__all__ = ["AmazonTextractConfigurationError", "AmazonTextractConverter"]

integrations/amazon_textract/src/haystack_integrations/components/converters/amazon_textract/converter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import os
65
from pathlib import Path
76
from typing import Any
87

@@ -14,9 +13,7 @@
1413
from haystack.dataclasses import ByteStream
1514
from haystack.utils import Secret, deserialize_secrets_inplace
1615

17-
from haystack_integrations.components.converters.amazon_textract.errors import (
18-
AmazonTextractConfigurationError,
19-
)
16+
from .errors import AmazonTextractConfigurationError
2017

2118
logger = logging.getLogger(__name__)
2219

@@ -125,7 +122,7 @@ def resolve_secret(secret: Secret | None) -> str | None:
125122
**(self.boto3_config if self.boto3_config else {}),
126123
)
127124
self._client = session.client("textract", config=config)
128-
except Exception as e:
125+
except BotoCoreError as e:
129126
msg = (
130127
"Could not connect to AWS Textract. Make sure the AWS environment is configured correctly. "
131128
"See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration"
@@ -180,7 +177,7 @@ def run(
180177

181178
merged_metadata = {**bytestream.meta, **metadata}
182179
if not self.store_full_path and (file_path := bytestream.meta.get("file_path")):
183-
merged_metadata["file_path"] = os.path.basename(file_path)
180+
merged_metadata["file_path"] = Path(file_path).name
184181

185182
doc = self._create_document(response, merged_metadata)
186183
documents.append(doc)

integrations/amazon_textract/src/haystack_integrations/components/converters/amazon_textract/errors.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55

6-
class AmazonTextractError(Exception):
7-
"""Any error generated by the Amazon Textract integration."""
8-
9-
10-
class AmazonTextractConfigurationError(AmazonTextractError):
6+
class AmazonTextractConfigurationError(Exception):
117
"""Exception raised when AWS is not configured correctly for Textract."""

integrations/amazon_textract/tests/test_amazon_textract_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from unittest.mock import MagicMock, patch
77

88
import pytest
9-
from botocore.exceptions import ClientError
9+
from botocore.exceptions import BotoCoreError, ClientError
1010
from haystack.dataclasses import ByteStream
1111
from haystack.utils import Secret
1212

@@ -190,7 +190,7 @@ def test_warm_up_idempotent(self, mock_session_cls):
190190

191191
@patch(
192192
"haystack_integrations.components.converters.amazon_textract.converter.boto3.Session",
193-
side_effect=Exception("bad config"),
193+
side_effect=BotoCoreError(),
194194
)
195195
def test_warm_up_configuration_error(self, _mock_session_cls):
196196
converter = AmazonTextractConverter(

0 commit comments

Comments
 (0)