exonware-xwlazy 0.1.0.10__py3-none-any.whl → 0.1.0.19__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.
Files changed (89) hide show
  1. exonware/__init__.py +22 -0
  2. exonware/xwlazy/__init__.py +0 -0
  3. exonware/xwlazy/common/__init__.py +47 -0
  4. exonware/xwlazy/common/base.py +58 -0
  5. exonware/xwlazy/common/cache.py +506 -0
  6. exonware/xwlazy/common/logger.py +268 -0
  7. exonware/xwlazy/common/services/__init__.py +72 -0
  8. exonware/xwlazy/common/services/dependency_mapper.py +234 -0
  9. exonware/xwlazy/common/services/install_async_utils.py +169 -0
  10. exonware/xwlazy/common/services/install_cache_utils.py +257 -0
  11. exonware/xwlazy/common/services/keyword_detection.py +292 -0
  12. exonware/xwlazy/common/services/spec_cache.py +173 -0
  13. exonware/xwlazy/common/services/state_manager.py +86 -0
  14. exonware/xwlazy/common/strategies/__init__.py +28 -0
  15. exonware/xwlazy/common/strategies/caching_dict.py +45 -0
  16. exonware/xwlazy/common/strategies/caching_installation.py +89 -0
  17. exonware/xwlazy/common/strategies/caching_lfu.py +67 -0
  18. exonware/xwlazy/common/strategies/caching_lru.py +64 -0
  19. exonware/xwlazy/common/strategies/caching_multitier.py +60 -0
  20. exonware/xwlazy/common/strategies/caching_ttl.py +60 -0
  21. exonware/xwlazy/config.py +195 -0
  22. exonware/xwlazy/contracts.py +1410 -0
  23. exonware/xwlazy/defs.py +397 -0
  24. exonware/xwlazy/errors.py +284 -0
  25. exonware/xwlazy/facade.py +1049 -0
  26. exonware/xwlazy/module/__init__.py +18 -0
  27. exonware/xwlazy/module/base.py +569 -0
  28. exonware/xwlazy/module/data.py +17 -0
  29. exonware/xwlazy/module/facade.py +247 -0
  30. exonware/xwlazy/module/importer_engine.py +2161 -0
  31. exonware/xwlazy/module/strategies/__init__.py +22 -0
  32. exonware/xwlazy/module/strategies/module_helper_lazy.py +94 -0
  33. exonware/xwlazy/module/strategies/module_helper_simple.py +66 -0
  34. exonware/xwlazy/module/strategies/module_manager_advanced.py +112 -0
  35. exonware/xwlazy/module/strategies/module_manager_simple.py +96 -0
  36. exonware/xwlazy/package/__init__.py +18 -0
  37. exonware/xwlazy/package/base.py +807 -0
  38. exonware/xwlazy/package/conf.py +331 -0
  39. exonware/xwlazy/package/data.py +17 -0
  40. exonware/xwlazy/package/facade.py +481 -0
  41. exonware/xwlazy/package/services/__init__.py +84 -0
  42. exonware/xwlazy/package/services/async_install_handle.py +89 -0
  43. exonware/xwlazy/package/services/config_manager.py +246 -0
  44. exonware/xwlazy/package/services/discovery.py +374 -0
  45. exonware/xwlazy/package/services/host_packages.py +149 -0
  46. exonware/xwlazy/package/services/install_async.py +278 -0
  47. exonware/xwlazy/package/services/install_cache.py +146 -0
  48. exonware/xwlazy/package/services/install_interactive.py +60 -0
  49. exonware/xwlazy/package/services/install_policy.py +158 -0
  50. exonware/xwlazy/package/services/install_registry.py +56 -0
  51. exonware/xwlazy/package/services/install_result.py +17 -0
  52. exonware/xwlazy/package/services/install_sbom.py +154 -0
  53. exonware/xwlazy/package/services/install_utils.py +83 -0
  54. exonware/xwlazy/package/services/installer_engine.py +408 -0
  55. exonware/xwlazy/package/services/lazy_installer.py +720 -0
  56. exonware/xwlazy/package/services/manifest.py +506 -0
  57. exonware/xwlazy/package/services/strategy_registry.py +188 -0
  58. exonware/xwlazy/package/strategies/__init__.py +57 -0
  59. exonware/xwlazy/package/strategies/package_discovery_file.py +130 -0
  60. exonware/xwlazy/package/strategies/package_discovery_hybrid.py +85 -0
  61. exonware/xwlazy/package/strategies/package_discovery_manifest.py +102 -0
  62. exonware/xwlazy/package/strategies/package_execution_async.py +114 -0
  63. exonware/xwlazy/package/strategies/package_execution_cached.py +91 -0
  64. exonware/xwlazy/package/strategies/package_execution_pip.py +100 -0
  65. exonware/xwlazy/package/strategies/package_execution_wheel.py +107 -0
  66. exonware/xwlazy/package/strategies/package_mapping_discovery_first.py +101 -0
  67. exonware/xwlazy/package/strategies/package_mapping_hybrid.py +106 -0
  68. exonware/xwlazy/package/strategies/package_mapping_manifest_first.py +101 -0
  69. exonware/xwlazy/package/strategies/package_policy_allow_list.py +58 -0
  70. exonware/xwlazy/package/strategies/package_policy_deny_list.py +58 -0
  71. exonware/xwlazy/package/strategies/package_policy_permissive.py +47 -0
  72. exonware/xwlazy/package/strategies/package_timing_clean.py +68 -0
  73. exonware/xwlazy/package/strategies/package_timing_full.py +67 -0
  74. exonware/xwlazy/package/strategies/package_timing_smart.py +69 -0
  75. exonware/xwlazy/package/strategies/package_timing_temporary.py +67 -0
  76. exonware/xwlazy/runtime/__init__.py +18 -0
  77. exonware/xwlazy/runtime/adaptive_learner.py +131 -0
  78. exonware/xwlazy/runtime/base.py +276 -0
  79. exonware/xwlazy/runtime/facade.py +95 -0
  80. exonware/xwlazy/runtime/intelligent_selector.py +173 -0
  81. exonware/xwlazy/runtime/metrics.py +64 -0
  82. exonware/xwlazy/runtime/performance.py +39 -0
  83. exonware/xwlazy/version.py +2 -2
  84. exonware_xwlazy-0.1.0.19.dist-info/METADATA +456 -0
  85. exonware_xwlazy-0.1.0.19.dist-info/RECORD +87 -0
  86. exonware_xwlazy-0.1.0.10.dist-info/METADATA +0 -0
  87. exonware_xwlazy-0.1.0.10.dist-info/RECORD +0 -6
  88. {exonware_xwlazy-0.1.0.10.dist-info → exonware_xwlazy-0.1.0.19.dist-info}/WHEEL +0 -0
  89. {exonware_xwlazy-0.1.0.10.dist-info → exonware_xwlazy-0.1.0.19.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,247 @@
1
+ """
2
+ Module Operations Facade
3
+
4
+ Main facade: XWModuleHelper extends AModuleHelper
5
+ Provides concrete implementation for all module operations.
6
+ Uses strategy pattern for caching, helper, and manager strategies.
7
+ """
8
+
9
+ import sys
10
+ import importlib
11
+ import importlib.util
12
+ from typing import Optional, Dict
13
+ from types import ModuleType
14
+
15
+ from .base import AModuleHelper, APackageHelper
16
+ # Lazy import to avoid circular dependency
17
+ from typing import TYPE_CHECKING
18
+ if TYPE_CHECKING:
19
+ from ..package.facade import XWPackageHelper
20
+
21
+ # Import from importer_engine for hook and module operations
22
+ from . import importer_engine
23
+
24
+ # Import strategy interfaces
25
+ from ..contracts import ICachingStrategy, IModuleHelperStrategy, IModuleManagerStrategy
26
+
27
+ # Import default strategies
28
+ from ..common.strategies import LRUCache
29
+ from .strategies import LazyHelper, AdvancedManager
30
+ from ..package.services.strategy_registry import StrategyRegistry
31
+
32
+
33
+ class XWModuleHelper(AModuleHelper):
34
+ """
35
+ Concrete implementation of AModuleHelper.
36
+
37
+ Provides simple, clean API for working with modules (what you import).
38
+ Uses XWPackageHelper for package operations and DependencyMapper for module-to-package mapping.
39
+ """
40
+
41
+ def __init__(
42
+ self,
43
+ package_name: str = 'default',
44
+ package_helper: Optional[APackageHelper] = None,
45
+ *,
46
+ # Strategy injection
47
+ caching_strategy: Optional[ICachingStrategy] = None,
48
+ helper_strategy: Optional[IModuleHelperStrategy] = None,
49
+ manager_strategy: Optional[IModuleManagerStrategy] = None
50
+ ):
51
+ """
52
+ Initialize XW module helper.
53
+
54
+ Args:
55
+ package_name: Package name for isolation (defaults to 'default')
56
+ package_helper: Optional package helper instance. If None, creates XWPackageHelper.
57
+ caching_strategy: Optional caching strategy. If None, uses LRUCache.
58
+ helper_strategy: Optional helper strategy. If None, uses LazyHelper.
59
+ manager_strategy: Optional manager strategy. If None, uses AdvancedManager.
60
+ """
61
+ if package_helper is None:
62
+ # Lazy import to avoid circular dependency
63
+ from ..package.facade import XWPackageHelper
64
+ package_helper = XWPackageHelper(package_name)
65
+ super().__init__(package_name, package_helper)
66
+ self._package_name = package_name
67
+ self._package_helper = package_helper
68
+
69
+ # Check registry for stored strategies, otherwise use defaults
70
+ if caching_strategy is None:
71
+ caching_strategy = StrategyRegistry.get_module_strategy(package_name, 'caching')
72
+ if caching_strategy is None:
73
+ caching_strategy = LRUCache(max_size=1000)
74
+ if helper_strategy is None:
75
+ helper_strategy = StrategyRegistry.get_module_strategy(package_name, 'helper')
76
+ if helper_strategy is None:
77
+ helper_strategy = LazyHelper()
78
+ if manager_strategy is None:
79
+ manager_strategy = StrategyRegistry.get_module_strategy(package_name, 'manager')
80
+ if manager_strategy is None:
81
+ manager_strategy = AdvancedManager(
82
+ package_name,
83
+ package_helper,
84
+ caching_strategy,
85
+ helper_strategy
86
+ )
87
+
88
+ # Store strategies
89
+ self._caching = caching_strategy
90
+ self._helper = helper_strategy
91
+ self._manager = manager_strategy
92
+
93
+ def _check_module_importability(self, module_name: str) -> bool:
94
+ """
95
+ Check if module is importable.
96
+
97
+ Uses importlib.util.find_spec to check if module can be imported.
98
+
99
+ Args:
100
+ module_name: Module name to check
101
+
102
+ Returns:
103
+ True if importable, False otherwise
104
+ """
105
+ try:
106
+ spec = importlib.util.find_spec(module_name)
107
+ return spec is not None
108
+ except (ValueError, AttributeError, ImportError):
109
+ return False
110
+
111
+ def _import_module(self, module_name: str) -> ModuleType:
112
+ """
113
+ Import a module.
114
+
115
+ Uses importlib.import_module to import the module.
116
+
117
+ Args:
118
+ module_name: Module name to import
119
+
120
+ Returns:
121
+ Imported module
122
+
123
+ Raises:
124
+ ImportError: If module cannot be imported
125
+ """
126
+ return importlib.import_module(module_name)
127
+
128
+ def _invalidate_import_caches(self) -> None:
129
+ """
130
+ Invalidate import caches.
131
+
132
+ Uses importlib.invalidate_caches() to clear Python's import caches.
133
+ """
134
+ importlib.invalidate_caches()
135
+ sys.path_importer_cache.clear()
136
+
137
+ def _create_package_helper(self) -> APackageHelper:
138
+ """
139
+ Create a package helper instance.
140
+
141
+ Returns:
142
+ XWPackageHelper instance
143
+ """
144
+ from ..package.facade import XWPackageHelper
145
+ return XWPackageHelper(self._package_name)
146
+
147
+ # Strategy swapping methods
148
+ def swap_cache_strategy(self, new_strategy: ICachingStrategy) -> None:
149
+ """
150
+ Swap cache strategy at runtime.
151
+
152
+ Args:
153
+ new_strategy: New caching strategy to use
154
+ """
155
+ self._caching = new_strategy
156
+ # Update manager if it uses caching
157
+ if hasattr(self._manager, '_caching'):
158
+ self._manager._caching = new_strategy
159
+
160
+ def swap_helper_strategy(self, new_strategy: IModuleHelperStrategy) -> None:
161
+ """
162
+ Swap helper/engine strategy at runtime.
163
+
164
+ Args:
165
+ new_strategy: New helper strategy to use
166
+ """
167
+ self._helper = new_strategy
168
+ # Update manager if it uses helper
169
+ if hasattr(self._manager, '_helper'):
170
+ self._manager._helper = new_strategy
171
+
172
+ def swap_manager_strategy(self, new_strategy: IModuleManagerStrategy) -> None:
173
+ """
174
+ Swap manager strategy at runtime.
175
+
176
+ Args:
177
+ new_strategy: New manager strategy to use
178
+ """
179
+ self._manager = new_strategy
180
+
181
+ # Abstract methods from AModule that need implementation
182
+ def install_hook(self) -> None:
183
+ """
184
+ Install the import hook into sys.meta_path.
185
+
186
+ Delegates to manager strategy.
187
+ """
188
+ self._manager.install_hook()
189
+
190
+ def uninstall_hook(self) -> None:
191
+ """
192
+ Uninstall the import hook from sys.meta_path.
193
+
194
+ Delegates to manager strategy.
195
+ """
196
+ self._manager.uninstall_hook()
197
+
198
+ def is_hook_installed(self) -> bool:
199
+ """
200
+ Check if import hook is installed.
201
+
202
+ Uses importer_engine.is_import_hook_installed() to check hook status.
203
+
204
+ Returns:
205
+ True if hook is installed, False otherwise
206
+ """
207
+ return importer_engine.is_import_hook_installed(self._package_name)
208
+
209
+ def handle_import_error(self, module_name: str) -> Optional[ModuleType]:
210
+ """
211
+ Handle ImportError by attempting to install and re-import.
212
+
213
+ Delegates to manager strategy.
214
+
215
+ Args:
216
+ module_name: Name of module that failed to import
217
+
218
+ Returns:
219
+ Imported module if successful, None otherwise
220
+ """
221
+ return self._manager.handle_import_error(module_name)
222
+
223
+ def load_module(self, module_path: str) -> ModuleType:
224
+ """
225
+ Load a module lazily.
226
+
227
+ Delegates to manager strategy.
228
+
229
+ Args:
230
+ module_path: Full module path to load
231
+
232
+ Returns:
233
+ Loaded module
234
+ """
235
+ return self._manager.load_module(module_path)
236
+
237
+ def unload_module(self, module_path: str) -> None:
238
+ """
239
+ Unload a module from cache.
240
+
241
+ Delegates to manager strategy.
242
+
243
+ Args:
244
+ module_path: Module path to unload
245
+ """
246
+ self._manager.unload_module(module_path)
247
+