Skip to content

Commit 3117213

Browse files
feat: require passing the logger to the storage provider
1 parent 066664b commit 3117213

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class StorageProviderSettings(StorageProviderSettingsBase):
6868
# This class can be empty as the one below.
6969
# You can however use it to store global information or maintain e.g. a connection
7070
# pool.
71+
# Inside of the provider, you can use self.logger (a normal Python logger of type
72+
# logging.Logger) to log any additional informations or
73+
# warnings.
7174
class StorageProvider(StorageProviderBase):
7275
# For compatibility with future changes, you should not overwrite the __init__
7376
# method. Instead, use __post_init__ to set additional attributes and initialize
@@ -129,6 +132,8 @@ class StorageProvider(StorageProviderBase):
129132
# storage (e.g. because it is read-only see
130133
# snakemake-storage-http for comparison), remove the corresponding base classes
131134
# from the list of inherited items.
135+
# Inside of the object, you can use self.provider to access the provider (e.g. for )
136+
# self.provider.logger, see above, or self.provider.settings).
132137
class StorageObject(
133138
StorageObjectRead,
134139
StorageObjectWrite,

snakemake_interface_storage_plugins/storage_provider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from dataclasses import dataclass
99
from enum import Enum
1010
from fractions import Fraction
11+
from logging import Logger
1112
from pathlib import Path
1213
import sys
1314
from abc import ABC, abstractmethod
@@ -57,11 +58,13 @@ class StorageProviderBase(ABC):
5758
def __init__(
5859
self,
5960
local_prefix: Path,
61+
logger: Logger,
6062
settings: Optional[StorageProviderSettingsBase] = None,
6163
keep_local=False,
6264
retrieve=True,
6365
is_default=False,
6466
):
67+
self.logger: Logger = logger
6568
try:
6669
local_prefix.mkdir(parents=True, exist_ok=True)
6770
except OSError as e:

snakemake_interface_storage_plugins/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from abc import ABC, abstractmethod
77
import asyncio
8+
import logging
89
from pathlib import Path
910
import shutil
1011
import sys
@@ -20,6 +21,9 @@
2021
from snakemake.io import IOCache
2122

2223

24+
logger = logging.getLogger(__name__)
25+
26+
2327
class TestStorageBase(ABC):
2428
__test__ = False
2529
retrieve_only = False
@@ -129,6 +133,7 @@ def test_query_validation(self, tmp_path):
129133

130134
def _get_provider(self, tmp_path):
131135
return self.get_storage_provider_cls()(
136+
logger=logger,
132137
local_prefix=Path(tmp_path) / "local_prefix",
133138
settings=self.get_storage_provider_settings(),
134139
)

0 commit comments

Comments
 (0)