Skip to content

Commit

Permalink
lazy-import boto3
Browse files Browse the repository at this point in the history
  • Loading branch information
tstadel committed Jul 26, 2024
1 parent f30d4eb commit 82b3a67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions integrations/opensearch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["haystack-ai", "opensearch-py>=2,<3", "boto3"]
dependencies = ["haystack-ai", "opensearch-py>=2,<3"]

[project.urls]
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/opensearch#readme"
Expand All @@ -47,6 +47,7 @@ dependencies = [
"pytest-rerunfailures",
"pytest-xdist",
"haystack-pydoc-tools",
"boto3",
]
[tool.hatch.envs.default.scripts]
test = "pytest --reruns 3 --reruns-delay 30 -x {args:tests}"
Expand All @@ -61,7 +62,7 @@ python = ["3.8", "3.9", "3.10", "3.11"]

[tool.hatch.envs.lint]
detached = true
dependencies = ["black>=23.1.0", "mypy>=1.0.0", "ruff>=0.0.243"]
dependencies = ["black>=23.1.0", "mypy>=1.0.0", "ruff>=0.0.243", "boto3"]
[tool.hatch.envs.lint.scripts]
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
style = ["ruff check {args:.}", "black --check --diff {args:.}"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Optional

import boto3
from botocore.exceptions import BotoCoreError
from haystack.lazy_imports import LazyImport
from haystack_integrations.common.opensearch.errors import AWSConfigurationError

with LazyImport("Run 'pip install \"boto3\"' to install boto3.") as boto3_import:
import boto3
from botocore.exceptions import BotoCoreError

AWS_CONFIGURATION_KEYS = [
"aws_access_key_id",
"aws_secret_access_key",
Expand Down Expand Up @@ -35,6 +38,7 @@ def get_aws_session(
:raises AWSConfigurationError: If the provided AWS credentials are invalid.
:returns: The created AWS session.
"""
boto3_import.check()
try:
return boto3.Session(
aws_access_key_id=aws_access_key_id,
Expand Down

0 comments on commit 82b3a67

Please sign in to comment.