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,331 @@
1
+ """
2
+ #exonware/xwlazy/src/exonware/xwlazy/package/conf.py
3
+
4
+ Host-facing configuration helpers for enabling lazy mode via `exonware.conf`.
5
+
6
+ This module centralizes the legacy configuration surface so host packages no
7
+ longer need to ship their own lazy bootstrap logic. Consumers import
8
+ ``exonware.conf`` as before, while the real implementation now lives in
9
+ ``xwlazy.package.conf`` to keep lazy concerns within the xwlazy project.
10
+
11
+ Company: eXonware.com
12
+ Author: Eng. Muhammad AlShehri
13
+ Email: connect@exonware.com
14
+ Version: 0.1.0.19
15
+ Generation Date: 10-Oct-2025
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import importlib
21
+ import importlib.metadata
22
+ import subprocess
23
+ import sys
24
+ import types
25
+ import warnings
26
+ from typing import Any, Dict, Optional
27
+
28
+ # Import from new structure
29
+ from .services.host_packages import refresh_host_package
30
+ from ..facade import (
31
+ config_package_lazy_install_enabled,
32
+ install_import_hook,
33
+ uninstall_import_hook,
34
+ is_import_hook_installed,
35
+ is_lazy_install_enabled,
36
+ )
37
+ from ..defs import get_preset_mode
38
+ from .services.config_manager import LazyInstallConfig
39
+
40
+ __all__ = ['get_conf_module', '_PackageConfig', '_FilteredStderr', '_LazyConfModule', '_setup_global_warning_filter']
41
+
42
+
43
+ class _PackageConfig:
44
+ """Per-package configuration wrapper."""
45
+
46
+ def __init__(self, package_name: str, parent_conf: "_LazyConfModule"):
47
+ self._package_name = package_name
48
+ self._parent_conf = parent_conf
49
+
50
+ @property
51
+ def lazy_install(self) -> bool:
52
+ """Return lazy install status for this package."""
53
+ return is_lazy_install_enabled(self._package_name)
54
+
55
+ @lazy_install.setter
56
+ def lazy_install(self, value: bool) -> None:
57
+ """Enable/disable lazy mode for this package."""
58
+ if value:
59
+ # Default to "smart" mode when enabling lazy install
60
+ config_package_lazy_install_enabled(self._package_name, True, mode="smart", install_hook=False)
61
+ install_import_hook(self._package_name)
62
+ refresh_host_package(self._package_name)
63
+ else:
64
+ config_package_lazy_install_enabled(self._package_name, False, install_hook=False)
65
+ uninstall_import_hook(self._package_name)
66
+
67
+ def lazy_install_status(self) -> Dict[str, Any]:
68
+ """Return runtime status for this package."""
69
+ return {
70
+ "package": self._package_name,
71
+ "enabled": is_lazy_install_enabled(self._package_name),
72
+ "hook_installed": is_import_hook_installed(self._package_name),
73
+ "active": is_lazy_install_enabled(self._package_name)
74
+ and is_import_hook_installed(self._package_name),
75
+ }
76
+
77
+ def is_lazy_active(self) -> bool:
78
+ """Return True if lazy install + hook are active."""
79
+ return self.lazy_install_status()["active"]
80
+
81
+
82
+ class _FilteredStderr:
83
+ """Stderr wrapper that filters out specific warning messages."""
84
+
85
+ def __init__(self, original_stderr: Any, filter_patterns: list[str]):
86
+ self._original = original_stderr
87
+ self._filter_patterns = filter_patterns
88
+
89
+ def write(self, text: str) -> int:
90
+ """Write to stderr, filtering out unwanted warnings."""
91
+ # Case-insensitive matching to catch all variations
92
+ if any(pattern.lower() in text.lower() for pattern in self._filter_patterns):
93
+ return len(text) # Pretend we wrote it, but don't actually write
94
+ return self._original.write(text)
95
+
96
+ def flush(self) -> None:
97
+ """Flush the original stderr."""
98
+ self._original.flush()
99
+
100
+ def reconfigure(self, *args, **kwargs):
101
+ """Handle reconfigure calls - update original reference and reapply filter."""
102
+ result = self._original.reconfigure(*args, **kwargs)
103
+ # Ensure filter stays active
104
+ if sys.stderr is not self:
105
+ sys.stderr = self # type: ignore[assignment]
106
+ return result
107
+
108
+ def __getattr__(self, name: str):
109
+ """Delegate all other attributes to original stderr."""
110
+ return getattr(self._original, name)
111
+
112
+
113
+ class _LazyConfModule(types.ModuleType):
114
+ """Configuration module for all exonware packages."""
115
+
116
+ def __init__(self, name: str, doc: Optional[str]) -> None:
117
+ super().__init__(name, doc)
118
+ self._package_configs: Dict[str, _PackageConfig] = {}
119
+ self._suppress_warnings: bool = True # Default: suppress warnings
120
+ self._original_stderr: Optional[Any] = None
121
+ self._filtered_stderr: Optional[_FilteredStderr] = None
122
+ # Set up warning suppression by default
123
+ self._setup_warning_filter()
124
+
125
+ # ------------------------------------------------------------------ helpers
126
+ def _is_xwlazy_installed(self) -> bool:
127
+ try:
128
+ importlib.metadata.distribution("exonware-xwlazy")
129
+ return True
130
+ except importlib.metadata.PackageNotFoundError:
131
+ try:
132
+ importlib.metadata.distribution("xwlazy")
133
+ return True
134
+ except importlib.metadata.PackageNotFoundError:
135
+ return False
136
+ except Exception:
137
+ try:
138
+ import exonware.xwlazy # noqa: F401
139
+ return True
140
+ except ImportError:
141
+ return False
142
+
143
+ def _ensure_xwlazy_installed(self) -> None:
144
+ if self._is_xwlazy_installed():
145
+ return
146
+ try:
147
+ result = subprocess.run(
148
+ [sys.executable, "-m", "pip", "install", "exonware-xwlazy"],
149
+ capture_output=True,
150
+ text=True,
151
+ check=False,
152
+ )
153
+ if result.returncode == 0:
154
+ print("[OK] Installed exonware-xwlazy for lazy mode")
155
+ else:
156
+ print(f"[WARN] Failed to install exonware-xwlazy: {result.stderr}")
157
+ except Exception as exc: # pragma: no cover - best effort
158
+ print(f"[WARN] Could not install exonware-xwlazy: {exc}")
159
+
160
+ def _uninstall_xwlazy(self) -> None:
161
+ if not self._is_xwlazy_installed():
162
+ return
163
+ try:
164
+ subprocess.run(
165
+ [sys.executable, "-m", "pip", "uninstall", "-y", "exonware-xwlazy", "xwlazy"],
166
+ capture_output=True,
167
+ text=True,
168
+ check=False,
169
+ )
170
+ print("[OK] Uninstalled exonware-xwlazy (lazy mode disabled)")
171
+ except Exception as exc: # pragma: no cover
172
+ print(f"[WARN] Could not uninstall exonware-xwlazy: {exc}")
173
+
174
+ def _get_global_lazy_status(self) -> Dict[str, Any]:
175
+ """Return aggregate status for DX tooling."""
176
+ installed = self._is_xwlazy_installed()
177
+ # Check all known packages, not just those in _package_configs
178
+ # This ensures we catch hooks installed via register_host_package
179
+ known_packages = list(self._package_configs.keys())
180
+ # Also check common package names that might have hooks installed
181
+ for pkg_name in ("xwsystem", "xwnode", "xwdata", "xwschema", "xwaction", "xwentity"):
182
+ if pkg_name not in known_packages and is_import_hook_installed(pkg_name):
183
+ known_packages.append(pkg_name)
184
+
185
+ hook_installed = any(is_import_hook_installed(pkg) for pkg in known_packages)
186
+ # Check if any package has lazy active (including those not yet in _package_configs)
187
+ active_configs = any(cfg.is_lazy_active() for cfg in self._package_configs.values())
188
+ # Also check directly for packages with hooks and enabled lazy install
189
+ active_direct = any(
190
+ is_import_hook_installed(pkg) and is_lazy_install_enabled(pkg)
191
+ for pkg in known_packages
192
+ )
193
+
194
+ return {
195
+ "xwlazy_installed": installed,
196
+ "enabled": installed,
197
+ "hook_installed": hook_installed,
198
+ "active": active_configs or active_direct,
199
+ }
200
+
201
+ def _setup_warning_filter(self) -> None:
202
+ """Set up or remove the stderr warning filter based on current setting."""
203
+ global _ORIGINAL_STDERR, _FILTERED_STDERR
204
+ if self._suppress_warnings:
205
+ # Use global filter (already set up at module import)
206
+ if _FILTERED_STDERR is not None and sys.stderr is not _FILTERED_STDERR:
207
+ sys.stderr = _FILTERED_STDERR # type: ignore[assignment]
208
+ else:
209
+ # Restore original stderr if we were filtering
210
+ if _ORIGINAL_STDERR is not None and sys.stderr is _FILTERED_STDERR:
211
+ sys.stderr = _ORIGINAL_STDERR
212
+
213
+ # ---------------------------------------------------------------- attr API
214
+ def __getattr__(self, name: str):
215
+ package_names = ("xwsystem", "xwnode", "xwdata", "xwschema", "xwaction", "xwentity")
216
+ if name in package_names:
217
+ if name not in self._package_configs:
218
+ self._package_configs[name] = _PackageConfig(name, self)
219
+ return self._package_configs[name]
220
+
221
+ if name == "lazy_install":
222
+ return self._is_xwlazy_installed()
223
+ if name == "lazy":
224
+ # Return current lazy mode setting
225
+ # Check if any package has lazy enabled and return its mode
226
+ for pkg_name in package_names:
227
+ if is_lazy_install_enabled(pkg_name):
228
+ mode_config = LazyInstallConfig.get_mode_config(pkg_name)
229
+ if mode_config:
230
+ # Return preset name if matches, otherwise return mode string
231
+ from ..defs import PRESET_MODES
232
+ for preset_name, preset_config in PRESET_MODES.items():
233
+ if (preset_config.load_mode == mode_config.load_mode and
234
+ preset_config.install_mode == mode_config.install_mode):
235
+ return preset_name
236
+ return LazyInstallConfig.get_mode(pkg_name)
237
+ return "none"
238
+ if name == "lazy_install_status":
239
+ return self._get_global_lazy_status
240
+ if name == "is_lazy_active":
241
+ return any(cfg.is_lazy_active() for cfg in self._package_configs.values())
242
+ if name == "suppress_warnings":
243
+ return self._suppress_warnings
244
+
245
+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
246
+
247
+ def __setattr__(self, name: str, value) -> None:
248
+ if name.startswith("_"):
249
+ super().__setattr__(name, value)
250
+ return
251
+ if name == "lazy_install":
252
+ if value:
253
+ self._ensure_xwlazy_installed()
254
+ # Enable with "smart" mode by default
255
+ package_names = ("xwsystem", "xwnode", "xwdata", "xwschema", "xwaction", "xwentity")
256
+ for pkg_name in package_names:
257
+ config_package_lazy_install_enabled(pkg_name, True, mode="smart", install_hook=True)
258
+ else:
259
+ package_names = ("xwsystem", "xwnode", "xwdata", "xwschema", "xwaction", "xwentity")
260
+ for pkg_name in package_names:
261
+ config_package_lazy_install_enabled(pkg_name, False, install_hook=False)
262
+ uninstall_import_hook(pkg_name)
263
+ self._uninstall_xwlazy()
264
+ return
265
+ if name == "lazy":
266
+ # Support exonware.conf.lazy = "lite"/"smart"/"full"/"clean"/"auto"
267
+ mode_map = {
268
+ "lite": "lite",
269
+ "smart": "smart",
270
+ "full": "full",
271
+ "clean": "clean",
272
+ "auto": "auto",
273
+ "temporary": "temporary",
274
+ "size_aware": "size_aware",
275
+ "none": "none",
276
+ }
277
+ mode = mode_map.get(str(value).lower(), "smart") # Default to "smart" instead of "auto"
278
+ # Apply to all known packages
279
+ package_names = ("xwsystem", "xwnode", "xwdata", "xwschema", "xwaction", "xwentity")
280
+ for pkg_name in package_names:
281
+ config_package_lazy_install_enabled(pkg_name, True, mode, install_hook=True)
282
+ return
283
+ if name == "suppress_warnings":
284
+ self._suppress_warnings = bool(value)
285
+ self._setup_warning_filter()
286
+ return
287
+ super().__setattr__(name, value)
288
+
289
+
290
+ _CONF_INSTANCE: Optional[_LazyConfModule] = None
291
+ _ORIGINAL_STDERR: Optional[Any] = None
292
+ _FILTERED_STDERR: Optional[_FilteredStderr] = None
293
+
294
+
295
+ def _setup_global_warning_filter() -> None:
296
+ """Set up global stderr filter for decimal module warnings (called at module import)."""
297
+ global _ORIGINAL_STDERR, _FILTERED_STDERR
298
+ # Check if a filter is already active (e.g., from exonware/__init__.py or conf.py)
299
+ # Check for both our filter class and the early filter class
300
+ if (hasattr(sys.stderr, '_original') or
301
+ isinstance(sys.stderr, _FilteredStderr) or
302
+ type(sys.stderr).__name__ == '_EarlyStderrFilter'):
303
+ # Filter already active, use existing one
304
+ _FILTERED_STDERR = sys.stderr # type: ignore[assignment]
305
+ return
306
+ if _ORIGINAL_STDERR is None:
307
+ # If stderr has _original, it's already wrapped - use that as original
308
+ if hasattr(sys.stderr, '_original'):
309
+ _ORIGINAL_STDERR = sys.stderr._original
310
+ else:
311
+ _ORIGINAL_STDERR = sys.stderr
312
+ if _FILTERED_STDERR is None:
313
+ _FILTERED_STDERR = _FilteredStderr(
314
+ _ORIGINAL_STDERR,
315
+ ["mpd_setminalloc", "MPD_MINALLOC", "ignoring request to set", "libmpdec", "context.c:57"]
316
+ )
317
+ if sys.stderr is not _FILTERED_STDERR:
318
+ sys.stderr = _FILTERED_STDERR # type: ignore[assignment]
319
+
320
+
321
+ # Set up warning filter immediately when module is imported (default: suppress warnings)
322
+ # Note: conf.py may have already set up a filter, which is fine
323
+ _setup_global_warning_filter()
324
+
325
+
326
+ def get_conf_module(name: str = "exonware.conf", doc: Optional[str] = None) -> types.ModuleType:
327
+ """Return (and memoize) the shared conf module instance."""
328
+ global _CONF_INSTANCE
329
+ if _CONF_INSTANCE is None:
330
+ _CONF_INSTANCE = _LazyConfModule(name, doc)
331
+ return _CONF_INSTANCE
@@ -0,0 +1,17 @@
1
+ """
2
+ Package Data - Immutable data structure for packages.
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+ Version: 0.1.0.19
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Re-export PackageData from defs.py for backward compatibility.
11
+ """
12
+
13
+ # Re-export from defs.py
14
+ from ..defs import PackageData
15
+
16
+ __all__ = ['PackageData']
17
+