moved import of optional packages into classes #6

Merged
brian merged 4 commits from make-optional-parts-independent into main 2025-09-17 12:39:00 +02:00
2 changed files with 11 additions and 7 deletions
Showing only changes of commit ee6acc6791 - Show all commits
@@ -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__,