Compare commits

..
13 Commits
Author SHA1 Message Date
Brian Bjarke Jensen 1dd604dc2a Merge pull request 'moved import of optional packages into classes' (#6) from make-optional-parts-independent into main
Test Python Package / test (push) Successful in 34s
Publish Python Package / build-and-publish (push) Successful in 15s
Code Quality Pipeline / code-quality (push) Successful in 27s
Reviewed-on: brian/python-repositories#6
2025-09-17 12:38:58 +02:00
Brian Bjarke Jensen e5c4025aeb added graceful handling of missing optional packages
Code Quality Pipeline / code-quality (pull_request) Successful in 26s
Test Python Package / test (pull_request) Successful in 34s
2025-09-17 12:36:22 +02:00
Brian Bjarke Jensen 396cf83a05 code quality fixes
Code Quality Pipeline / code-quality (pull_request) Successful in 30s
Test Python Package / test (pull_request) Successful in 1m12s
2025-09-17 12:14:37 +02:00
Brian Bjarke Jensen 538b26b62f mypy fixed 2025-09-17 12:04:45 +02:00
Brian Bjarke Jensen ee6acc6791 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
2025-09-17 11:44:47 +02:00
Brian Bjarke Jensen 0ca07c02ac Merge pull request 'exposed minio adapter' (#5) from expose-minio-adapter into main
Code Quality Pipeline / code-quality (push) Successful in 36s
Test Python Package / test (push) Successful in 35s
Publish Python Package / build-and-publish (push) Successful in 15s
Reviewed-on: brian/python-repositories#5
2025-09-15 14:44:00 +02:00
Brian Bjarke Jensen 7446e88850 added py.typed mypy config file
Code Quality Pipeline / code-quality (pull_request) Successful in 34s
Test Python Package / test (pull_request) Successful in 40s
2025-09-15 14:15:39 +02:00
Brian Bjarke Jensen d5f437f77c ruff format fix
Code Quality Pipeline / code-quality (pull_request) Successful in 1m21s
Test Python Package / test (pull_request) Successful in 1m30s
2025-09-15 13:59:03 +02:00
Brian Bjarke Jensen 7beca7c398 exposed minio adapter
Code Quality Pipeline / code-quality (pull_request) Failing after 1m9s
Test Python Package / test (pull_request) Successful in 1m29s
2025-09-15 13:38:06 +02:00
Brian Bjarke Jensen 65d8051c57 Merge pull request 'add-minio-adapter' (#4) from add-minio-adapter into main
Test Python Package / test (push) Successful in 25s
Publish Python Package / build-and-publish (push) Successful in 11s
Dependency Update Bot / update-check (push) Failing after 58s
Code Quality Pipeline / code-quality (push) Successful in 17s
Reviewed-on: brian/python-repositories#4
2025-09-15 01:05:17 +02:00
Brian Bjarke Jensen f5af30328d auto install all extra packages
Code Quality Pipeline / code-quality (pull_request) Successful in 18s
Test Python Package / test (pull_request) Successful in 59s
2025-09-15 01:03:34 +02:00
Brian Bjarke Jensen 3260a3ffb1 added new optional package to ci
Code Quality Pipeline / code-quality (pull_request) Failing after 6s
Test Python Package / test (pull_request) Failing after 6s
2025-09-15 00:59:40 +02:00
Brian Bjarke Jensen c7bced4254 ruff lint fixes
Code Quality Pipeline / code-quality (pull_request) Successful in 17s
Test Python Package / test (pull_request) Failing after 12s
2025-09-15 00:56:21 +02:00
7 changed files with 30 additions and 17 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
env: env:
UV_LINK_MODE: copy UV_LINK_MODE: copy
run: uv sync --extra redis run: uv sync --all-extras
- name: Type check with mypy - name: Type check with mypy
run: uv run mypy . run: uv run mypy .
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
env: env:
UV_LINK_MODE: copy UV_LINK_MODE: copy
run: uv sync --extra redis run: uv sync --all-extras
- name: Run pytest - name: Run pytest
env: env:
+9 -1
View File
@@ -1,5 +1,13 @@
from .redis_adapter import RedisAdapter as RedisAdapter """
Adapters for various backend repositories (e.g., Redis, Minio).
This module exposes concrete implementations for repository interfaces.
"""
from .redis_adapter import RedisAdapter
from .minio_adapter import MinioAdapter
__all__ = [ __all__ = [
"RedisAdapter", "RedisAdapter",
"MinioAdapter",
] ]
@@ -3,10 +3,8 @@
from __future__ import annotations from __future__ import annotations
import os import os
from io import BytesIO from io import BytesIO
from importlib.util import find_spec
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 (
@@ -14,6 +12,10 @@ from python_repositories.interfaces import (
ConnectionAwareInterface, ConnectionAwareInterface,
) )
# Handle optional dependencies
if find_spec("minio") is not None:
import minio
class MinioAdapter( class MinioAdapter(
ContextAwareInterface, ContextAwareInterface,
@@ -42,7 +44,7 @@ class MinioAdapter(
}, },
) )
# Prepare internal variables # Prepare internal variables
self._client: Minio | None = None self._client: minio.Minio | None = None
self._bucket_name: str | None = None self._bucket_name: str | None = None
def __enter__(self) -> MinioAdapter: def __enter__(self) -> MinioAdapter:
@@ -77,7 +79,7 @@ class MinioAdapter(
secret_key = str(os.getenv(self.secret_key_env_var_name)) secret_key = str(os.getenv(self.secret_key_env_var_name))
bucket = str(os.getenv(self.bucket_env_var_name)) bucket = str(os.getenv(self.bucket_env_var_name))
# Connect client # Connect client
client = Minio( client = minio.Minio(
endpoint=endpoint, endpoint=endpoint,
access_key=access_key, access_key=access_key,
secret_key=secret_key, secret_key=secret_key,
@@ -107,7 +109,7 @@ class MinioAdapter(
@property @property
def is_connected(self) -> bool: def is_connected(self) -> bool:
"""Check if connected to Minio server.""" """Check if connected to Minio server."""
res = bool(isinstance(self._client, Minio)) res = bool(isinstance(self._client, minio.Minio))
self.logger.debug(res) self.logger.debug(res)
return res return res
@@ -161,7 +163,7 @@ class MinioAdapter(
f"Got object '{object_name}' from bucket '{self._bucket_name}'" f"Got object '{object_name}' from bucket '{self._bucket_name}'"
) )
return buffer return buffer
except S3Error as exc: except minio.S3Error as exc:
if exc.code == "NoSuchKey": if exc.code == "NoSuchKey":
self.logger.warning( self.logger.warning(
f"Object '{object_name}' not found in bucket '{self._bucket_name}'" f"Object '{object_name}' not found in bucket '{self._bucket_name}'"
@@ -2,13 +2,10 @@
from __future__ import annotations from __future__ import annotations
from typing import cast from typing import cast
from importlib.util import find_spec
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 (
@@ -16,6 +13,11 @@ from python_repositories.interfaces import (
ConnectionAwareInterface, ConnectionAwareInterface,
) )
# Handle optional dependencies
if find_spec("redis") is not None:
import redis
from redis.commands.json.path import Path as RedisPath
class RedisAdapter( class RedisAdapter(
ContextAwareInterface, ContextAwareInterface,
@@ -24,7 +26,7 @@ class RedisAdapter(
"""Redis adapter exposing basic CRUD functionality.""" """Redis adapter exposing basic CRUD functionality."""
uri_env_var_name: str = "REDIS_URI" uri_env_var_name: str = "REDIS_URI"
path: str = RedisPath.root_path() path: str = "." # JSON root path, updated in __init__
encoding: str = "UTF-8" encoding: str = "UTF-8"
def __init__(self) -> None: def __init__(self) -> None:
@@ -36,6 +38,7 @@ class RedisAdapter(
check_env(self.uri_env_var_name) check_env(self.uri_env_var_name)
# Prepare internal variables # Prepare internal variables
self._client: redis.Redis | None = None self._client: redis.Redis | None = None
self.path: str = RedisPath.root_path()
def __enter__(self) -> RedisAdapter: def __enter__(self) -> RedisAdapter:
"""Enter the context.""" """Enter the context."""
View File
+2 -2
View File
@@ -4,14 +4,14 @@
"""Integration tests for the MinioAdapter.""" """Integration tests for the MinioAdapter."""
from collections.abc import Generator from collections.abc import Generator
from minio import S3Error
import pytest import pytest
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock
from minio import Minio from minio import Minio
from io import BytesIO from io import BytesIO
import random import random
import os import os
import logging import logging
from minio import S3Error
from python_repositories.adapters.minio_adapter import MinioAdapter from python_repositories.adapters.minio_adapter import MinioAdapter