moved import of optional packages into classes
This commit is contained in:
@@ -3,10 +3,7 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import structlog
|
||||
from minio import Minio, S3Error
|
||||
|
||||
from python_utils import check_env
|
||||
|
||||
from python_repositories.interfaces import (
|
||||
@@ -28,6 +25,11 @@ class MinioAdapter(
|
||||
chunk_size: int = 5 * 2**20 # 5 MiB
|
||||
|
||||
def __init__(self) -> None:
|
||||
# Import here to avoid hard dependency if MinioAdapter is not used
|
||||
try:
|
||||
from minio import Minio, S3Error # type: ignore[import]
|
||||
except ImportError as e:
|
||||
raise RuntimeError("MinioAdapter dependencies missing") from e
|
||||
# Setup logger
|
||||
self.logger = structlog.get_logger(
|
||||
self.__class__.__name__,
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import cast
|
||||
|
||||
import os
|
||||
import structlog
|
||||
|
||||
import redis
|
||||
from redis.commands.json.path import Path as RedisPath
|
||||
|
||||
from python_utils import check_env
|
||||
|
||||
from python_repositories.interfaces import (
|
||||
@@ -28,6 +24,12 @@ class RedisAdapter(
|
||||
encoding: str = "UTF-8"
|
||||
|
||||
def __init__(self) -> None:
|
||||
# Import here to avoid hard dependency to optional package
|
||||
try:
|
||||
import redis # type: ignore[import]
|
||||
from redis.commands.json.path import Path as RedisPath # type: ignore[import]
|
||||
except ImportError as e:
|
||||
raise RuntimeError("RedisAdapter dependencies missing") from e
|
||||
# Setup logger
|
||||
self.logger = structlog.get_logger(
|
||||
self.__class__.__name__,
|
||||
|
||||
Reference in New Issue
Block a user