@@ -92,11 +92,12 @@ class ConfigLoader:
92
92
_path_to_config : Optional [str ] = None
93
93
_remote_config_location : Optional [str ] = None
94
94
path_to_default_config : Optional [str ] = None
95
- path_to_overwrite_config : Optional [str ] = None
95
+ _path_to_overwrite_config : Optional [str ] = None
96
96
97
97
_custom_config : dict = {}
98
98
_merge_upstream : bool = False
99
99
_config_dir : Optional [str ] = None
100
+ __config_loaded : bool = False
100
101
101
102
file_helper : FileHelper = FileHelper ()
102
103
dict_helper : DictHelper = DictHelper ()
@@ -115,18 +116,8 @@ def __init__(
115
116
else :
116
117
self .config_dir = PyFunceble .storage .CONFIG_DIRECTORY
117
118
118
- self .path_to_config = os .path .join (
119
- self .config_dir ,
120
- PyFunceble .storage .CONFIGURATION_FILENAME ,
121
- )
122
-
123
119
self .path_to_remote_config = None
124
120
125
- self .path_to_overwrite_config = os .path .join (
126
- self .config_dir ,
127
- ".PyFunceble.overwrite.yaml" ,
128
- )
129
-
130
121
if merge_upstream is not None :
131
122
self .merge_upstream = merge_upstream
132
123
elif EnvironmentVariableHelper ("PYFUNCEBLE_AUTO_CONFIGURATION" ).exists ():
@@ -206,14 +197,82 @@ def conditional_switch(config: dict) -> dict:
206
197
207
198
return config
208
199
209
- @staticmethod
210
- def is_already_loaded () -> bool :
200
+ def is_already_loaded (self ) -> bool :
211
201
"""
212
202
Checks if the configuration was already loaded.
213
203
"""
214
204
215
205
return bool (PyFunceble .storage .CONFIGURATION )
216
206
207
+ def __is_completely_loaded (self ) -> bool :
208
+ """
209
+ Checks if the configuration was completely loaded.
210
+ """
211
+
212
+ return self .is_already_loaded () and bool (self .__config_loaded )
213
+
214
+ @property
215
+ def path_to_config (self ) -> Optional [str ]:
216
+ """
217
+ Provides the current state of the :code:`_path_to_config` attribute.
218
+ """
219
+
220
+ if self ._path_to_config is None :
221
+ self ._path_to_config = os .path .join (
222
+ self .config_dir ,
223
+ PyFunceble .storage .CONFIGURATION_FILENAME ,
224
+ )
225
+
226
+ return self ._path_to_config
227
+
228
+ @path_to_config .setter
229
+ def path_to_config (self , value : str ) -> None :
230
+ """
231
+ Sets the path to the configuration file.
232
+
233
+ :param value:
234
+ The value to set.
235
+
236
+ :raise TypeError:
237
+ When value is not a :py:class:`str`.
238
+ """
239
+
240
+ if not isinstance (value , str ):
241
+ raise TypeError (f"<value> should be { str } , { type (value )} given." )
242
+
243
+ self ._path_to_config = value
244
+
245
+ @property
246
+ def path_to_overwrite_config (self ) -> Optional [str ]:
247
+ """
248
+ Provides the current state of the :code:`_path_to_overwrite_config` attribute.
249
+ """
250
+
251
+ if self ._path_to_overwrite_config is None :
252
+ self ._path_to_overwrite_config = os .path .join (
253
+ self .config_dir ,
254
+ ".PyFunceble.overwrite.yaml" ,
255
+ )
256
+
257
+ return self ._path_to_overwrite_config
258
+
259
+ @path_to_overwrite_config .setter
260
+ def path_to_overwrite_config (self , value : str ) -> None :
261
+ """
262
+ Sets the path to the overwrite configuration file.
263
+
264
+ :param value:
265
+ The value to set.
266
+
267
+ :raise TypeError:
268
+ When value is not a :py:class:`str`.
269
+ """
270
+
271
+ if not isinstance (value , str ):
272
+ raise TypeError (f"<value> should be { str } , { type (value )} given." )
273
+
274
+ self ._path_to_overwrite_config = value
275
+
217
276
@property
218
277
def config_dir (self ) -> Optional [str ]:
219
278
"""
@@ -239,6 +298,9 @@ def config_dir(self, value: str) -> None:
239
298
raise TypeError (f"<value> should be { str } , { type (value )} given." )
240
299
241
300
self ._config_dir = value
301
+ # Reset the path to the configuration file.
302
+ self ._path_to_config = None
303
+ self ._path_to_overwrite_config = None
242
304
243
305
def set_config_dir (self , value : str ) -> "ConfigLoader" :
244
306
"""
@@ -385,9 +447,8 @@ def install_missing_infrastructure_files(
385
447
386
448
return self
387
449
388
- @classmethod
389
450
def download_dynamic_infrastructure_files (
390
- cls ,
451
+ self ,
391
452
) -> "ConfigLoader" :
392
453
"""
393
454
Downloads all the dynamicly (generated) infrastructure files.
@@ -400,7 +461,7 @@ def download_dynamic_infrastructure_files(
400
461
401
462
## pragma: no cover ## Underlying download methods already tested.
402
463
403
- if not cls .is_already_loaded ():
464
+ if not self .is_already_loaded ():
404
465
IANADownloader ().start ()
405
466
PublicSuffixDownloader ().start ()
406
467
UserAgentsDownloader ().start ()
@@ -494,7 +555,7 @@ def download_remote_config(src: str, dest: str = None) -> None:
494
555
config ,
495
556
)
496
557
497
- if not self .is_already_loaded ():
558
+ if not self .__is_completely_loaded ():
498
559
self .install_missing_infrastructure_files ()
499
560
self .download_dynamic_infrastructure_files ()
500
561
download_remote_config (
@@ -593,6 +654,8 @@ def start(self) -> "ConfigLoader":
593
654
# Early load user agents to allow usage of defined user agents.
594
655
UserAgentDataset ().get_latest ()
595
656
657
+ self .__config_loaded = True
658
+
596
659
return self
597
660
598
661
def destroy (self , keep_custom : bool = False ) -> "ConfigLoader" :
@@ -620,4 +683,6 @@ def destroy(self, keep_custom: bool = False) -> "ConfigLoader":
620
683
# This is not a mistake.
621
684
self ._custom_config = {}
622
685
686
+ self .__config_loaded = False
687
+
623
688
return self
0 commit comments