sibi-dst 0.3.59__py3-none-any.whl → 0.3.60__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ from .airflow_manager import AirflowDAGManager
14
14
  from .credentials import *
15
15
  from .update_planner import UpdatePlanner
16
16
  from .data_wrapper import DataWrapper
17
- from .storage_config import StorageConfig
17
+ from .storage_config import StorageConfig, FsRegistry
18
18
  from .data_from_http_source import DataFromHttpSource
19
19
  from .webdav_client import WebDAVClient
20
20
  from .manifest_manager import MissingManifestManager
@@ -37,7 +37,9 @@ __all__ = [
37
37
  "ClickHouseWriter",
38
38
  "AirflowDAGManager",
39
39
  "StorageConfig",
40
+ "FsRegistry",
40
41
  "DataFromHttpSource",
41
42
  "WebDAVClient",
42
43
  "MissingManifestManager",
43
44
  ]
45
+
@@ -1,3 +1,7 @@
1
+ from threading import RLock
2
+ from typing import Dict, Callable, Any
3
+
4
+ from sibi_dst.utils import Logger
1
5
  from .storage_manager import StorageManager
2
6
  from .credentials import ConfigManager
3
7
 
@@ -46,4 +50,58 @@ class StorageConfig:
46
50
  # defaulting to local filesystem
47
51
  self.filesystem_type = 'file'
48
52
  self.filesystem_options = {}
49
- self.filesystem_options = {k: v for k, v in self.filesystem_options.items() if v}
53
+ self.filesystem_options = {k: v for k, v in self.filesystem_options.items() if v}
54
+
55
+ class FsRegistry:
56
+ def __init__(self, debug: bool = False, logger: Logger = None):
57
+ self._storage_registry: Dict[str, Callable[[], Any]]={}
58
+ self._fs_instance_cache: Dict[str, object] = {}
59
+ self._lock = RLock()
60
+ self.debug = debug
61
+
62
+ if logger:
63
+ self.logger = logger
64
+ else:
65
+ self.logger = Logger.default_logger(logger_name="FsRegistry")
66
+ self.logger.set_level(Logger.DEBUG if self.debug else Logger.INFO)
67
+
68
+ def register(self, name:str, manager: Any):
69
+ """
70
+ Registers a filesystem manager instance with a name.
71
+ :param name: Name of the filesystem instance.
72
+ :param manager: Filesystem manager instance to register.
73
+ """
74
+ if not hasattr(manager, 'get_fs_instance'):
75
+ raise TypeError("Manager must have a 'get_fs_instance' method.")
76
+ self._storage_registry[name] = lambda: manager
77
+
78
+
79
+ def get_fs_instance(self, name: str='source') -> object:
80
+ """
81
+ Retrieve a filesystem instance from a registered storage manager.
82
+ Caches instances per name.
83
+ """
84
+ if name in self._fs_instance_cache:
85
+ return self._fs_instance_cache[name]
86
+
87
+ if name not in self._storage_registry:
88
+ raise ValueError(f"Storage '{name}' has not been registered.")
89
+
90
+ manager = self._storage_registry[name]()
91
+ fs = manager.get_fs_instance()
92
+ self._fs_instance_cache[name] = fs
93
+ return fs
94
+
95
+ def unregister_fs(self, name: str):
96
+ """
97
+ Unregister a storage and clear its cached fs instance.
98
+ """
99
+ self._storage_registry.pop(name, None)
100
+ self._fs_instance_cache.pop(name, None)
101
+
102
+
103
+ def clear_fs_cache(self):
104
+ """
105
+ Clear all cached fs instances.
106
+ """
107
+ self._fs_instance_cache.clear()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sibi-dst
3
- Version: 0.3.59
3
+ Version: 0.3.60
4
4
  Summary: Data Science Toolkit
5
5
  Author: Luis Valverde
6
6
  Author-email: lvalverdeb@gmail.com
@@ -38,7 +38,7 @@ sibi_dst/osmnx_helper/basemaps/router_plotter.py,sha256=UAiijn-J-jjX4YnL0_P9SFqT
38
38
  sibi_dst/osmnx_helper/utils.py,sha256=BzuY8CtYnBAAO8UAr_M7EOk6CP1zcifNLs8pkdFZEFg,20577
39
39
  sibi_dst/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  sibi_dst/tests/test_data_wrapper_class.py,sha256=6uFmZR2DxnxQz49L5jT2ehlKvlLnpUHMLFB_PqqUq7k,3336
41
- sibi_dst/utils/__init__.py,sha256=I-LeSCEnnOKunblmCrv_KTBzbsr7Rx1MEWM9TypDqWM,1203
41
+ sibi_dst/utils/__init__.py,sha256=w0_q4rl3yD7x1Q5yWxH-GN_3Ju1XlebIzm3nJdrUeGE,1234
42
42
  sibi_dst/utils/airflow_manager.py,sha256=-d44EKUZNYJyp4wuNwRvilRQktunArPOB5fZuWdQv10,7526
43
43
  sibi_dst/utils/clickhouse_writer.py,sha256=iAUe4_Kn2WR1xZjpLW2FOWCWfOTw6fCGMTUcWxIQJ60,9877
44
44
  sibi_dst/utils/credentials.py,sha256=cHJPPsmVyijqbUQIq7WWPe-lIallA-mI5RAy3YUuRME,1724
@@ -53,7 +53,7 @@ sibi_dst/utils/log_utils.py,sha256=77xACRagKU83H9vn7aVeBzkQjxWlbe4dg4KuxPRCgvw,4
53
53
  sibi_dst/utils/manifest_manager.py,sha256=abm97TuWgJqNViPXMbpl5W7ttrg1BeiJkf2SMGc4hd8,5512
54
54
  sibi_dst/utils/parquet_saver.py,sha256=O62xwPfphOpKgEiHqnts20CPSU96pxs49Cg7PVetLK0,8193
55
55
  sibi_dst/utils/phone_formatter.py,sha256=tsVTDamuthFYgy4-5UwmQkPQ-FGTGH7MjZyH8utAkIY,4945
56
- sibi_dst/utils/storage_config.py,sha256=Cg8EOGLZ_5v9sunaQHZLYHdp5FDkgPrCVVNHF-ys5sQ,2181
56
+ sibi_dst/utils/storage_config.py,sha256=TE15H-7d0mqwYPSUgrdidK9U7N7p87Z8JfUQH4-jdPs,4123
57
57
  sibi_dst/utils/storage_manager.py,sha256=btecX7ggNb7rfu5EK9Xuu2q_FZA7r_rB_tfhQ8V96qc,6567
58
58
  sibi_dst/utils/update_planner.py,sha256=dJXLC-KdbWrCs-MFe7Xa8F-ZhlNJq8P1szjLAzMJZk0,9684
59
59
  sibi_dst/utils/webdav_client.py,sha256=pYF1UsGOuxYeGLq7aBfwZFvkvD4meOcbbaiZ4d6GW9I,7107
@@ -77,6 +77,6 @@ sibi_dst/v2/df_helper/core/_params_config.py,sha256=DYx2drDz3uF-lSPzizPkchhy-kxR
77
77
  sibi_dst/v2/df_helper/core/_query_config.py,sha256=Y8LVSyaKuVkrPluRDkQoOwuXHQxner1pFWG3HPfnDHM,441
78
78
  sibi_dst/v2/utils/__init__.py,sha256=6H4cvhqTiFufnFPETBF0f8beVVMpfJfvUs6Ne0TQZNY,58
79
79
  sibi_dst/v2/utils/log_utils.py,sha256=rfk5VsLAt-FKpv6aPTC1FToIPiyrnHAFFBAkHme24po,4123
80
- sibi_dst-0.3.59.dist-info/METADATA,sha256=zYb_0a1ImTPUxB4raHM8cvip0_oZSot52N8okr3r_ZY,4292
81
- sibi_dst-0.3.59.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
82
- sibi_dst-0.3.59.dist-info/RECORD,,
80
+ sibi_dst-0.3.60.dist-info/METADATA,sha256=WuBvzuHMuZBUpHF2-dAO65MI1e5EhuZ1-Hvil3oQY6o,4292
81
+ sibi_dst-0.3.60.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
82
+ sibi_dst-0.3.60.dist-info/RECORD,,