moved import of optional packages into classes
Code Quality Pipeline / code-quality (pull_request) Failing after 1m53s
Test Python Package / test (pull_request) Failing after 22s

This commit is contained in:
Brian Bjarke Jensen
2025-09-17 11:44:47 +02:00
parent 0ca07c02ac
commit ee6acc6791
2 changed files with 11 additions and 7 deletions
@@ -3,10 +3,7 @@
from __future__ import annotations from __future__ import annotations
import os import os
from io import BytesIO from io import BytesIO
import structlog import structlog
from minio import Minio, S3Error
from python_utils import check_env from python_utils import check_env
from python_repositories.interfaces import ( from python_repositories.interfaces import (
@@ -28,6 +25,11 @@ class MinioAdapter(
chunk_size: int = 5 * 2**20 # 5 MiB chunk_size: int = 5 * 2**20 # 5 MiB
def __init__(self) -> None: 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 # Setup logger
self.logger = structlog.get_logger( self.logger = structlog.get_logger(
self.__class__.__name__, self.__class__.__name__,
@@ -2,13 +2,9 @@
from __future__ import annotations from __future__ import annotations
from typing import cast from typing import cast
import os import os
import structlog import structlog
import redis
from redis.commands.json.path import Path as RedisPath
from python_utils import check_env from python_utils import check_env
from python_repositories.interfaces import ( from python_repositories.interfaces import (
@@ -28,6 +24,12 @@ class RedisAdapter(
encoding: str = "UTF-8" encoding: str = "UTF-8"
def __init__(self) -> None: 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 # Setup logger
self.logger = structlog.get_logger( self.logger = structlog.get_logger(
self.__class__.__name__, self.__class__.__name__,