Compare commits

..
15 Commits
Author SHA1 Message Date
brian f4280f15c1 Merge pull request 'Remove non-existent Mongo adapter from README.' (#10) from cleanup/remove-mongo-adapter-mentions into main
Test Python Package / test (push) Successful in 1m12s
Code Quality Pipeline / code-quality (push) Successful in 24s
Reviewed-on: https://gitea.lille-vemmelund.dk/brian/python-repositories/pulls/10
2026-06-21 23:05:47 +02:00
Brian Bjarke Jensen d9b9fa49a2 updated package settings
Code Quality Pipeline / code-quality (pull_request) Successful in 41s
Test Python Package / test (pull_request) Successful in 1m18s
2026-06-21 22:45:29 +02:00
Brian Bjarke Jensen 9d25f7c722 updated package settings
Code Quality Pipeline / code-quality (pull_request) Failing after 39s
Test Python Package / test (pull_request) Successful in 1m23s
2026-06-21 22:43:14 +02:00
Brian Bjarke Jensen 163581526d updated package settings
Code Quality Pipeline / code-quality (pull_request) Failing after 21s
Test Python Package / test (pull_request) Failing after 12s
2026-06-21 22:39:50 +02:00
Brian Bjarke Jensen 933c4ee7c5 updated package settings
Test Python Package / test (pull_request) Successful in 1m27s
Code Quality Pipeline / code-quality (pull_request) Successful in 41s
2026-06-21 22:34:50 +02:00
Brian Bjarke Jensen 2b0d98f84c updated package settings
Code Quality Pipeline / code-quality (pull_request) Failing after 51s
Test Python Package / test (pull_request) Failing after 2m1s
2026-06-21 22:26:41 +02:00
Brian Bjarke JensenandCursor 729fa48505 Remove non-existent Mongo adapter from README.
Code Quality Pipeline / code-quality (pull_request) Failing after 2m9s
Test Python Package / test (pull_request) Failing after 2m10s
The package only ships Redis and MinIO adapters, so the docs should not reference a mongo extra.

Co-authored-by: Cursor <[email protected]>
2026-06-21 22:17:44 +02:00
Brian Bjarke Jensen fa011be862 Merge pull request 'added support for content type when putting object in minio' (#9) from add-support-for-content-type-in-minio into main
Code Quality Pipeline / code-quality (push) Successful in 26s
Test Python Package / test (push) Successful in 33s
Publish Python Package / build-and-publish (push) Successful in 15s
Dependency Update Bot / update-check (push) Failing after 10s
Security Audit / safety (push) Failing after 2m9s
Reviewed-on: brian/python-repositories#9
2025-09-18 19:40:27 +02:00
Brian Bjarke Jensen 2e9330949c ruff format fix
Code Quality Pipeline / code-quality (pull_request) Successful in 29s
Test Python Package / test (pull_request) Successful in 35s
2025-09-18 19:38:22 +02:00
Brian Bjarke Jensen 3ab8da92fb added support for content type when putting object in minio
Code Quality Pipeline / code-quality (pull_request) Failing after 24s
Test Python Package / test (pull_request) Successful in 1m9s
2025-09-18 19:34:05 +02:00
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
6 changed files with 690 additions and 664 deletions
+1 -2
View File
@@ -7,11 +7,10 @@ Various python repository interfaces exposed as a python package.
This package supports interacting with multiple different backends:
- Redis
- Mongo
- MinIO
To add support for a specific backend install this package with one or more of these optional packages:
```bash
uv add python-repositories[redis, mongo, minio]
uv add python-repositories[redis, minio]
```
+2 -2
View File
@@ -31,12 +31,12 @@ python-utils = { index = "gitea" }
[[tool.uv.index]]
name = "threadripper-proxpi-cache"
url = "http://10.0.0.2:5001/index/"
url = "https://proxpi.lille-vemmelund.dk/index/"
default = true
[[tool.uv.index]]
name = "gitea"
url = "https://gitea.gt-proj.com/api/packages/brian/pypi/simple/"
url = "https://gitea.lille-vemmelund.dk/api/packages/brian/pypi/simple/"
explicit = true
[tool.mypy]
+18 -8
View File
@@ -3,10 +3,8 @@
from __future__ import annotations
import os
from io import BytesIO
from importlib.util import find_spec
import structlog
from minio import Minio, S3Error
from python_utils import check_env
from python_repositories.interfaces import (
@@ -14,6 +12,10 @@ from python_repositories.interfaces import (
ConnectionAwareInterface,
)
# Handle optional dependencies
if find_spec("minio") is not None:
import minio
class MinioAdapter(
ContextAwareInterface,
@@ -42,7 +44,7 @@ class MinioAdapter(
},
)
# Prepare internal variables
self._client: Minio | None = None
self._client: minio.Minio | None = None
self._bucket_name: str | None = None
def __enter__(self) -> MinioAdapter:
@@ -77,7 +79,7 @@ class MinioAdapter(
secret_key = str(os.getenv(self.secret_key_env_var_name))
bucket = str(os.getenv(self.bucket_env_var_name))
# Connect client
client = Minio(
client = minio.Minio(
endpoint=endpoint,
access_key=access_key,
secret_key=secret_key,
@@ -107,17 +109,24 @@ class MinioAdapter(
@property
def is_connected(self) -> bool:
"""Check if connected to Minio server."""
res = bool(isinstance(self._client, Minio))
res = bool(isinstance(self._client, minio.Minio))
self.logger.debug(res)
return res
def _put(self, object_name: str, data: BytesIO) -> None:
def _put(
self,
object_name: str,
data: BytesIO,
content_type: str = "application/octet-stream",
) -> None:
"""Put an object into the Minio bucket."""
# Check input
if not isinstance(object_name, str) or len(object_name) == 0:
raise ValueError("object_name must be a non-empty string")
if not isinstance(data, BytesIO) or data.getbuffer().nbytes == 0:
raise ValueError("data must be a non-empty BytesIO object")
if not isinstance(content_type, str) or len(content_type) == 0:
raise ValueError("content_type must be a non-empty string")
# Check connection
if self._client is None or not self.is_connected:
raise ConnectionError("Not connected to Minio")
@@ -132,6 +141,7 @@ class MinioAdapter(
data=data,
length=num_bytes,
part_size=self.chunk_size,
content_type=content_type,
)
self.logger.debug(
f"Put object '{object_name}' into bucket '{self._bucket_name}'"
@@ -161,7 +171,7 @@ class MinioAdapter(
f"Got object '{object_name}' from bucket '{self._bucket_name}'"
)
return buffer
except S3Error as exc:
except minio.S3Error as exc:
if exc.code == "NoSuchKey":
self.logger.warning(
f"Object '{object_name}' not found in bucket '{self._bucket_name}'"
@@ -2,13 +2,10 @@
from __future__ import annotations
from typing import cast
from importlib.util import find_spec
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 (
@@ -16,6 +13,11 @@ from python_repositories.interfaces import (
ConnectionAwareInterface,
)
# Handle optional dependencies
if find_spec("redis") is not None:
import redis
from redis.commands.json.path import Path as RedisPath
class RedisAdapter(
ContextAwareInterface,
@@ -24,7 +26,7 @@ class RedisAdapter(
"""Redis adapter exposing basic CRUD functionality."""
uri_env_var_name: str = "REDIS_URI"
path: str = RedisPath.root_path()
path: str = "." # JSON root path, updated in __init__
encoding: str = "UTF-8"
def __init__(self) -> None:
@@ -36,6 +38,7 @@ class RedisAdapter(
check_env(self.uri_env_var_name)
# Prepare internal variables
self._client: redis.Redis | None = None
self.path: str = RedisPath.root_path()
def __enter__(self) -> RedisAdapter:
"""Enter the context."""
+14
View File
@@ -370,6 +370,20 @@ def test_should_raise_value_error_on_invalid_put_data(
minio_adapter._put(object_name, data) # type: ignore
def test_should_raise_value_error_on_invalid_put_content_type(
data: BytesIO,
minio_adapter: MinioAdapter,
) -> None:
"""Test that the MinioAdapter raises ValueError when putting with an invalid content type."""
# Arrange
object_name = "valid_object_name"
invalid_content_types = ["", 123, None]
# Act & Assert
for content_type in invalid_content_types:
with pytest.raises(ValueError):
minio_adapter._put(object_name, data, content_type) # type: ignore
def test_should_raise_connection_error_on_put_when_not_connected(
data: BytesIO,
minio_adapter: MinioAdapter,
Generated
+647 -647
View File
File diff suppressed because it is too large Load Diff