8
8
import abc
9
9
import os
10
10
import uuid
11
- from typing import TYPE_CHECKING , Generic , Iterable , Type , TypeVar , Union
11
+ from typing import TYPE_CHECKING , Any , Generic , Iterable , Mapping , Type , TypeVar , Union
12
12
13
13
import structlog
14
14
from pydantic import BaseModel , ConfigDict , Field
22
22
23
23
if TYPE_CHECKING :
24
24
from kiara .context import Kiara
25
+ from kiara .context .config import KiaraArchiveConfig
25
26
26
27
27
28
class ArchiveConfig (BaseModel , abc .ABC ):
28
29
@classmethod
29
30
@abc .abstractmethod
30
- def create_new_store_config (cls , store_id : str , stores_base_path : str ) -> Self :
31
+ def create_new_store_config (
32
+ cls , store_id : uuid .UUID , stores_base_path : str
33
+ ) -> Self :
31
34
raise NotImplementedError (
32
35
f"Store config type '{ cls } ' does not implement 'create_new_config'."
33
36
)
@@ -55,16 +58,42 @@ class KiaraArchive(abc.ABC):
55
58
56
59
_config_cls = ArchiveConfig # type: ignore
57
60
61
+ @classmethod
62
+ def create_config (
63
+ cls , config : Union ["KiaraArchiveConfig" , BaseModel , Mapping [str , Any ]]
64
+ ) -> "BaseArchive" :
65
+
66
+ from kiara .context .config import KiaraArchiveConfig
67
+
68
+ if isinstance (config , cls ._config_cls ):
69
+ config = config
70
+ elif isinstance (config , KiaraArchiveConfig ):
71
+ config = cls ._config_cls (** config .config )
72
+ elif isinstance (config , BaseModel ):
73
+ config = cls ._config_cls (** config .model_dump ())
74
+ elif isinstance (config , Mapping ):
75
+ config = cls ._config_cls (** config )
76
+
77
+ return config
78
+
79
+ def __init__ (self , force_read_only : bool = False , ** kwargs ):
80
+ self ._force_read_only : bool = force_read_only
81
+
58
82
@classmethod
59
83
@abc .abstractmethod
60
84
def supported_item_types (cls ) -> Iterable [str ]:
61
85
pass
62
86
63
87
@classmethod
64
88
@abc .abstractmethod
65
- def is_writeable (cls ) -> bool :
89
+ def _is_writeable (cls ) -> bool :
66
90
pass
67
91
92
+ def is_writeable (self ) -> bool :
93
+ if self ._force_read_only :
94
+ return False
95
+ return self .__class__ ._is_writeable ()
96
+
68
97
@abc .abstractmethod
69
98
def register_archive (self , kiara : "Kiara" ):
70
99
pass
@@ -125,7 +154,7 @@ class BaseArchive(KiaraArchive, Generic[ARCHIVE_CONFIG_CLS]):
125
154
126
155
@classmethod
127
156
def create_new_config (
128
- cls , store_id : str , stores_base_path : str
157
+ cls , store_id : uuid . UUID , stores_base_path : str
129
158
) -> ARCHIVE_CONFIG_CLS :
130
159
131
160
log_message (
@@ -139,12 +168,22 @@ def create_new_config(
139
168
store_id = store_id , stores_base_path = stores_base_path
140
169
)
141
170
142
- def __init__ (self , archive_id : uuid .UUID , config : ARCHIVE_CONFIG_CLS ):
171
+ def __init__ (
172
+ self ,
173
+ archive_id : uuid .UUID ,
174
+ config : ARCHIVE_CONFIG_CLS ,
175
+ force_read_only : bool = False ,
176
+ ):
143
177
178
+ super ().__init__ (force_read_only = force_read_only )
144
179
self ._archive_id : uuid .UUID = archive_id
145
180
self ._config : ARCHIVE_CONFIG_CLS = config
146
181
self ._kiara : Union ["Kiara" , None ] = None
147
182
183
+ @classmethod
184
+ def _is_writeable (cls ) -> bool :
185
+ return False
186
+
148
187
def _get_config (self ) -> ARCHIVE_CONFIG_CLS :
149
188
return self ._config
150
189
0 commit comments