exonware-xwlazy 0.1.0.11__py3-none-any.whl → 0.1.0.20__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 (96) hide show
  1. exonware/__init__.py +26 -0
  2. exonware/xwlazy/__init__.py +0 -0
  3. exonware/xwlazy/common/__init__.py +47 -0
  4. exonware/xwlazy/common/base.py +56 -0
  5. exonware/xwlazy/common/cache.py +504 -0
  6. exonware/xwlazy/common/logger.py +257 -0
  7. exonware/xwlazy/common/services/__init__.py +72 -0
  8. exonware/xwlazy/common/services/dependency_mapper.py +232 -0
  9. exonware/xwlazy/common/services/install_async_utils.py +165 -0
  10. exonware/xwlazy/common/services/install_cache_utils.py +245 -0
  11. exonware/xwlazy/common/services/keyword_detection.py +283 -0
  12. exonware/xwlazy/common/services/spec_cache.py +165 -0
  13. xwlazy/lazy/lazy_state.py → exonware/xwlazy/common/services/state_manager.py +0 -2
  14. exonware/xwlazy/common/strategies/__init__.py +28 -0
  15. exonware/xwlazy/common/strategies/caching_dict.py +44 -0
  16. exonware/xwlazy/common/strategies/caching_installation.py +88 -0
  17. exonware/xwlazy/common/strategies/caching_lfu.py +66 -0
  18. exonware/xwlazy/common/strategies/caching_lru.py +63 -0
  19. exonware/xwlazy/common/strategies/caching_multitier.py +59 -0
  20. exonware/xwlazy/common/strategies/caching_ttl.py +59 -0
  21. {xwlazy/lazy → exonware/xwlazy}/config.py +51 -21
  22. exonware/xwlazy/contracts.py +1396 -0
  23. exonware/xwlazy/defs.py +378 -0
  24. xwlazy/lazy/lazy_errors.py → exonware/xwlazy/errors.py +21 -16
  25. exonware/xwlazy/facade.py +991 -0
  26. exonware/xwlazy/module/__init__.py +18 -0
  27. exonware/xwlazy/module/base.py +565 -0
  28. exonware/xwlazy/module/data.py +17 -0
  29. exonware/xwlazy/module/facade.py +246 -0
  30. exonware/xwlazy/module/importer_engine.py +2117 -0
  31. exonware/xwlazy/module/strategies/__init__.py +22 -0
  32. exonware/xwlazy/module/strategies/module_helper_lazy.py +93 -0
  33. exonware/xwlazy/module/strategies/module_helper_simple.py +65 -0
  34. exonware/xwlazy/module/strategies/module_manager_advanced.py +111 -0
  35. exonware/xwlazy/module/strategies/module_manager_simple.py +95 -0
  36. exonware/xwlazy/package/__init__.py +18 -0
  37. exonware/xwlazy/package/base.py +798 -0
  38. xwlazy/lazy/host_conf.py → exonware/xwlazy/package/conf.py +61 -16
  39. exonware/xwlazy/package/data.py +17 -0
  40. exonware/xwlazy/package/facade.py +480 -0
  41. exonware/xwlazy/package/services/__init__.py +84 -0
  42. exonware/xwlazy/package/services/async_install_handle.py +87 -0
  43. exonware/xwlazy/package/services/config_manager.py +245 -0
  44. exonware/xwlazy/package/services/discovery.py +370 -0
  45. {xwlazy/lazy → exonware/xwlazy/package/services}/host_packages.py +43 -20
  46. exonware/xwlazy/package/services/install_async.py +277 -0
  47. exonware/xwlazy/package/services/install_cache.py +145 -0
  48. exonware/xwlazy/package/services/install_interactive.py +59 -0
  49. exonware/xwlazy/package/services/install_policy.py +156 -0
  50. exonware/xwlazy/package/services/install_registry.py +54 -0
  51. exonware/xwlazy/package/services/install_result.py +17 -0
  52. exonware/xwlazy/package/services/install_sbom.py +153 -0
  53. exonware/xwlazy/package/services/install_utils.py +79 -0
  54. exonware/xwlazy/package/services/installer_engine.py +406 -0
  55. exonware/xwlazy/package/services/lazy_installer.py +718 -0
  56. {xwlazy/lazy → exonware/xwlazy/package/services}/manifest.py +40 -33
  57. exonware/xwlazy/package/services/strategy_registry.py +186 -0
  58. exonware/xwlazy/package/strategies/__init__.py +57 -0
  59. exonware/xwlazy/package/strategies/package_discovery_file.py +129 -0
  60. exonware/xwlazy/package/strategies/package_discovery_hybrid.py +84 -0
  61. exonware/xwlazy/package/strategies/package_discovery_manifest.py +101 -0
  62. exonware/xwlazy/package/strategies/package_execution_async.py +113 -0
  63. exonware/xwlazy/package/strategies/package_execution_cached.py +90 -0
  64. exonware/xwlazy/package/strategies/package_execution_pip.py +99 -0
  65. exonware/xwlazy/package/strategies/package_execution_wheel.py +106 -0
  66. exonware/xwlazy/package/strategies/package_mapping_discovery_first.py +100 -0
  67. exonware/xwlazy/package/strategies/package_mapping_hybrid.py +105 -0
  68. exonware/xwlazy/package/strategies/package_mapping_manifest_first.py +100 -0
  69. exonware/xwlazy/package/strategies/package_policy_allow_list.py +57 -0
  70. exonware/xwlazy/package/strategies/package_policy_deny_list.py +57 -0
  71. exonware/xwlazy/package/strategies/package_policy_permissive.py +46 -0
  72. exonware/xwlazy/package/strategies/package_timing_clean.py +67 -0
  73. exonware/xwlazy/package/strategies/package_timing_full.py +66 -0
  74. exonware/xwlazy/package/strategies/package_timing_smart.py +68 -0
  75. exonware/xwlazy/package/strategies/package_timing_temporary.py +66 -0
  76. exonware/xwlazy/runtime/__init__.py +18 -0
  77. exonware/xwlazy/runtime/adaptive_learner.py +129 -0
  78. exonware/xwlazy/runtime/base.py +274 -0
  79. exonware/xwlazy/runtime/facade.py +94 -0
  80. exonware/xwlazy/runtime/intelligent_selector.py +170 -0
  81. exonware/xwlazy/runtime/metrics.py +60 -0
  82. exonware/xwlazy/runtime/performance.py +37 -0
  83. exonware/xwlazy/version.py +2 -2
  84. {exonware_xwlazy-0.1.0.11.dist-info → exonware_xwlazy-0.1.0.20.dist-info}/METADATA +89 -11
  85. exonware_xwlazy-0.1.0.20.dist-info/RECORD +87 -0
  86. exonware_xwlazy-0.1.0.11.dist-info/RECORD +0 -20
  87. xwlazy/__init__.py +0 -34
  88. xwlazy/lazy/__init__.py +0 -301
  89. xwlazy/lazy/bootstrap.py +0 -106
  90. xwlazy/lazy/lazy_base.py +0 -465
  91. xwlazy/lazy/lazy_contracts.py +0 -290
  92. xwlazy/lazy/lazy_core.py +0 -3727
  93. xwlazy/lazy/logging_utils.py +0 -194
  94. xwlazy/version.py +0 -77
  95. {exonware_xwlazy-0.1.0.11.dist-info → exonware_xwlazy-0.1.0.20.dist-info}/WHEEL +0 -0
  96. {exonware_xwlazy-0.1.0.11.dist-info → exonware_xwlazy-0.1.0.20.dist-info}/licenses/LICENSE +0 -0
@@ -1,8 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  """
4
- xwlazy.lazy.manifest
5
- --------------------
4
+ xwlazy.common.utils.manifest
5
+ ----------------------------
6
6
 
7
7
  Centralized loader for per-package dependency manifests. A manifest can be
8
8
  declared either as a JSON file located in the target project's root directory
@@ -18,7 +18,7 @@ It also keeps lightweight caches with file-modification tracking so repeated
18
18
  lookups do not hit the filesystem unnecessarily.
19
19
  """
20
20
 
21
- from dataclasses import dataclass, field
21
+ from dataclasses import field
22
22
  import importlib.util
23
23
  import json
24
24
  import os
@@ -42,11 +42,9 @@ DEFAULT_MANIFEST_FILENAMES: Tuple[str, ...] = (
42
42
 
43
43
  ENV_MANIFEST_PATH = "XWLAZY_MANIFEST_PATH"
44
44
 
45
-
46
45
  def _normalize_package_name(package_name: Optional[str]) -> str:
47
46
  return (package_name or "global").strip().lower()
48
47
 
49
-
50
48
  def _normalize_prefix(prefix: str) -> str:
51
49
  prefix = prefix.strip()
52
50
  if not prefix:
@@ -55,7 +53,6 @@ def _normalize_prefix(prefix: str) -> str:
55
53
  prefix = f"{prefix}."
56
54
  return prefix
57
55
 
58
-
59
56
  def _normalize_wrap_hints(values: Iterable[Any]) -> List[str]:
60
57
  hints: List[str] = []
61
58
  for value in values:
@@ -66,29 +63,8 @@ def _normalize_wrap_hints(values: Iterable[Any]) -> List[str]:
66
63
  hints.append(hint)
67
64
  return hints
68
65
 
69
-
70
- @dataclass(frozen=True)
71
- class PackageManifest:
72
- """Resolved manifest data for a single package."""
73
-
74
- package: str
75
- dependencies: Dict[str, str] = field(default_factory=dict)
76
- watched_prefixes: Tuple[str, ...] = ()
77
- async_installs: bool = False
78
- async_workers: int = 1
79
- class_wrap_prefixes: Tuple[str, ...] = ()
80
- metadata: Dict[str, Any] = field(default_factory=dict)
81
-
82
- def get_dependency(self, import_name: str) -> Optional[str]:
83
- """Return the declared package for the given import name."""
84
- if not import_name:
85
- return None
86
- direct = self.dependencies.get(import_name)
87
- if direct is not None:
88
- return direct
89
- # Case-insensitive fallback for convenience
90
- return self.dependencies.get(import_name.lower())
91
-
66
+ # PackageManifest moved to defs.py - import it from there
67
+ from ...defs import PackageManifest
92
68
 
93
69
  class LazyManifestLoader:
94
70
  """
@@ -133,6 +109,28 @@ class LazyManifestLoader:
133
109
  self._shared_dependency_maps.clear()
134
110
  self._generation += 1
135
111
 
112
+ def sync_manifest_configuration(self, package_name: str) -> None:
113
+ """
114
+ Sync configuration from manifest for a specific package.
115
+
116
+ This method forces a reload of the manifest and clears caches
117
+ to ensure the latest configuration is used.
118
+
119
+ Args:
120
+ package_name: The package name to sync configuration for
121
+ """
122
+ with self._lock:
123
+ # Clear cache for this package
124
+ package_key = _normalize_package_name(package_name)
125
+ if package_key in self._manifest_cache:
126
+ del self._manifest_cache[package_key]
127
+ if package_key in self._source_signatures:
128
+ del self._source_signatures[package_key]
129
+ # Increment generation to invalidate shared caches
130
+ self._generation += 1
131
+ # Force reload by getting manifest
132
+ self.get_manifest(package_key)
133
+
136
134
  # --------------------------------------------------------------------- #
137
135
  # Public API
138
136
  # --------------------------------------------------------------------- #
@@ -453,11 +451,9 @@ class LazyManifestLoader:
453
451
  "wrap_class_prefixes": ordered_wrap_hints,
454
452
  }
455
453
 
456
-
457
454
  _manifest_loader: Optional[LazyManifestLoader] = None
458
455
  _manifest_loader_lock = RLock()
459
456
 
460
-
461
457
  def get_manifest_loader() -> LazyManifestLoader:
462
458
  """
463
459
  Return the process-wide manifest loader instance.
@@ -472,18 +468,29 @@ def get_manifest_loader() -> LazyManifestLoader:
472
468
  _manifest_loader = LazyManifestLoader()
473
469
  return _manifest_loader
474
470
 
475
-
476
471
  def refresh_manifest_cache() -> None:
477
472
  """Forcefully clear the shared manifest loader cache."""
478
473
  loader = get_manifest_loader()
479
474
  loader.clear_cache()
480
475
 
476
+ def sync_manifest_configuration(package_name: str) -> None:
477
+ """
478
+ Sync configuration from manifest for a specific package.
479
+
480
+ This is a convenience function that calls the manifest loader's
481
+ sync_manifest_configuration method.
482
+
483
+ Args:
484
+ package_name: The package name to sync configuration for
485
+ """
486
+ loader = get_manifest_loader()
487
+ loader.sync_manifest_configuration(package_name)
481
488
 
482
489
  __all__ = [
483
490
  "PackageManifest",
484
491
  "LazyManifestLoader",
485
492
  "get_manifest_loader",
486
493
  "refresh_manifest_cache",
494
+ "sync_manifest_configuration",
487
495
  ]
488
496
 
489
-
@@ -0,0 +1,186 @@
1
+ """
2
+ Strategy Registry
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Registry to store custom strategies per package for both package and module operations.
11
+ """
12
+
13
+ import threading
14
+ from typing import Dict, Optional, Any, TYPE_CHECKING
15
+
16
+ if TYPE_CHECKING:
17
+ from ...contracts import (
18
+ IInstallExecutionStrategy,
19
+ IInstallTimingStrategy,
20
+ IDiscoveryStrategy,
21
+ IPolicyStrategy,
22
+ IMappingStrategy,
23
+ IModuleHelperStrategy,
24
+ IModuleManagerStrategy,
25
+ ICachingStrategy,
26
+ )
27
+
28
+ class StrategyRegistry:
29
+ """Registry to store custom strategies per package."""
30
+
31
+ # Package strategies
32
+ _package_execution_strategies: Dict[str, 'IInstallExecutionStrategy'] = {}
33
+ _package_timing_strategies: Dict[str, 'IInstallTimingStrategy'] = {}
34
+ _package_discovery_strategies: Dict[str, 'IDiscoveryStrategy'] = {}
35
+ _package_policy_strategies: Dict[str, 'IPolicyStrategy'] = {}
36
+ _package_mapping_strategies: Dict[str, 'IMappingStrategy'] = {}
37
+
38
+ # Module strategies
39
+ _module_helper_strategies: Dict[str, 'IModuleHelperStrategy'] = {}
40
+ _module_manager_strategies: Dict[str, 'IModuleManagerStrategy'] = {}
41
+ _module_caching_strategies: Dict[str, 'ICachingStrategy'] = {}
42
+
43
+ _lock = threading.RLock()
44
+
45
+ @classmethod
46
+ def set_package_strategy(
47
+ cls,
48
+ package_name: str,
49
+ strategy_type: str,
50
+ strategy: Any,
51
+ ) -> None:
52
+ """
53
+ Set a package strategy for a package.
54
+
55
+ Args:
56
+ package_name: Package name
57
+ strategy_type: One of 'execution', 'timing', 'discovery', 'policy', 'mapping'
58
+ strategy: Strategy instance
59
+ """
60
+ package_key = package_name.lower()
61
+ with cls._lock:
62
+ if strategy_type == 'execution':
63
+ cls._package_execution_strategies[package_key] = strategy
64
+ elif strategy_type == 'timing':
65
+ cls._package_timing_strategies[package_key] = strategy
66
+ elif strategy_type == 'discovery':
67
+ cls._package_discovery_strategies[package_key] = strategy
68
+ elif strategy_type == 'policy':
69
+ cls._package_policy_strategies[package_key] = strategy
70
+ elif strategy_type == 'mapping':
71
+ cls._package_mapping_strategies[package_key] = strategy
72
+ else:
73
+ raise ValueError(f"Unknown package strategy type: {strategy_type}")
74
+
75
+ @classmethod
76
+ def get_package_strategy(
77
+ cls,
78
+ package_name: str,
79
+ strategy_type: str,
80
+ ) -> Optional[Any]:
81
+ """
82
+ Get a package strategy for a package.
83
+
84
+ Args:
85
+ package_name: Package name
86
+ strategy_type: One of 'execution', 'timing', 'discovery', 'policy', 'mapping'
87
+
88
+ Returns:
89
+ Strategy instance or None if not set
90
+ """
91
+ package_key = package_name.lower()
92
+ with cls._lock:
93
+ if strategy_type == 'execution':
94
+ return cls._package_execution_strategies.get(package_key)
95
+ elif strategy_type == 'timing':
96
+ return cls._package_timing_strategies.get(package_key)
97
+ elif strategy_type == 'discovery':
98
+ return cls._package_discovery_strategies.get(package_key)
99
+ elif strategy_type == 'policy':
100
+ return cls._package_policy_strategies.get(package_key)
101
+ elif strategy_type == 'mapping':
102
+ return cls._package_mapping_strategies.get(package_key)
103
+ else:
104
+ raise ValueError(f"Unknown package strategy type: {strategy_type}")
105
+
106
+ @classmethod
107
+ def set_module_strategy(
108
+ cls,
109
+ package_name: str,
110
+ strategy_type: str,
111
+ strategy: Any,
112
+ ) -> None:
113
+ """
114
+ Set a module strategy for a package.
115
+
116
+ Args:
117
+ package_name: Package name
118
+ strategy_type: One of 'helper', 'manager', 'caching'
119
+ strategy: Strategy instance
120
+ """
121
+ package_key = package_name.lower()
122
+ with cls._lock:
123
+ if strategy_type == 'helper':
124
+ cls._module_helper_strategies[package_key] = strategy
125
+ elif strategy_type == 'manager':
126
+ cls._module_manager_strategies[package_key] = strategy
127
+ elif strategy_type == 'caching':
128
+ cls._module_caching_strategies[package_key] = strategy
129
+ else:
130
+ raise ValueError(f"Unknown module strategy type: {strategy_type}")
131
+
132
+ @classmethod
133
+ def get_module_strategy(
134
+ cls,
135
+ package_name: str,
136
+ strategy_type: str,
137
+ ) -> Optional[Any]:
138
+ """
139
+ Get a module strategy for a package.
140
+
141
+ Args:
142
+ package_name: Package name
143
+ strategy_type: One of 'helper', 'manager', 'caching'
144
+
145
+ Returns:
146
+ Strategy instance or None if not set
147
+ """
148
+ package_key = package_name.lower()
149
+ with cls._lock:
150
+ if strategy_type == 'helper':
151
+ return cls._module_helper_strategies.get(package_key)
152
+ elif strategy_type == 'manager':
153
+ return cls._module_manager_strategies.get(package_key)
154
+ elif strategy_type == 'caching':
155
+ return cls._module_caching_strategies.get(package_key)
156
+ else:
157
+ raise ValueError(f"Unknown module strategy type: {strategy_type}")
158
+
159
+ @classmethod
160
+ def clear_package_strategies(cls, package_name: str) -> None:
161
+ """Clear all package strategies for a package."""
162
+ package_key = package_name.lower()
163
+ with cls._lock:
164
+ cls._package_execution_strategies.pop(package_key, None)
165
+ cls._package_timing_strategies.pop(package_key, None)
166
+ cls._package_discovery_strategies.pop(package_key, None)
167
+ cls._package_policy_strategies.pop(package_key, None)
168
+ cls._package_mapping_strategies.pop(package_key, None)
169
+
170
+ @classmethod
171
+ def clear_module_strategies(cls, package_name: str) -> None:
172
+ """Clear all module strategies for a package."""
173
+ package_key = package_name.lower()
174
+ with cls._lock:
175
+ cls._module_helper_strategies.pop(package_key, None)
176
+ cls._module_manager_strategies.pop(package_key, None)
177
+ cls._module_caching_strategies.pop(package_key, None)
178
+
179
+ @classmethod
180
+ def clear_all_strategies(cls, package_name: str) -> None:
181
+ """Clear all strategies (package and module) for a package."""
182
+ cls.clear_package_strategies(package_name)
183
+ cls.clear_module_strategies(package_name)
184
+
185
+ __all__ = ['StrategyRegistry']
186
+
@@ -0,0 +1,57 @@
1
+ """
2
+ Package Strategies
3
+
4
+ All package strategy implementations.
5
+ """
6
+
7
+ # Mapping strategies
8
+ from .package_mapping_manifest_first import ManifestFirstMapping
9
+ from .package_mapping_discovery_first import DiscoveryFirstMapping
10
+ from .package_mapping_hybrid import HybridMapping
11
+
12
+ # Policy strategies
13
+ from .package_policy_permissive import PermissivePolicy
14
+ from .package_policy_allow_list import AllowListPolicy
15
+ from .package_policy_deny_list import DenyListPolicy
16
+
17
+ # Timing strategies
18
+ from .package_timing_smart import SmartTiming
19
+ from .package_timing_full import FullTiming
20
+ from .package_timing_clean import CleanTiming
21
+ from .package_timing_temporary import TemporaryTiming
22
+
23
+ # Execution strategies
24
+ from .package_execution_pip import PipExecution
25
+ from .package_execution_wheel import WheelExecution
26
+ from .package_execution_cached import CachedExecution
27
+ from .package_execution_async import AsyncExecution
28
+
29
+ # Discovery strategies
30
+ from .package_discovery_file import FileBasedDiscovery
31
+ from .package_discovery_manifest import ManifestBasedDiscovery
32
+ from .package_discovery_hybrid import HybridDiscovery
33
+
34
+ __all__ = [
35
+ # Mapping strategies
36
+ 'ManifestFirstMapping',
37
+ 'DiscoveryFirstMapping',
38
+ 'HybridMapping',
39
+ # Policy strategies
40
+ 'PermissivePolicy',
41
+ 'AllowListPolicy',
42
+ 'DenyListPolicy',
43
+ # Timing strategies
44
+ 'SmartTiming',
45
+ 'FullTiming',
46
+ 'CleanTiming',
47
+ 'TemporaryTiming',
48
+ # Execution strategies
49
+ 'PipExecution',
50
+ 'WheelExecution',
51
+ 'CachedExecution',
52
+ 'AsyncExecution',
53
+ # Discovery strategies
54
+ 'FileBasedDiscovery',
55
+ 'ManifestBasedDiscovery',
56
+ 'HybridDiscovery',
57
+ ]
@@ -0,0 +1,129 @@
1
+ """
2
+ File-Based Discovery Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+
8
+ Generation Date: 15-Nov-2025
9
+
10
+ File-based discovery - discovers dependencies from project files.
11
+ """
12
+
13
+ from pathlib import Path
14
+ from typing import Dict, Optional, Any
15
+ from ...package.base import ADiscoveryStrategy
16
+
17
+ class FileBasedDiscovery(ADiscoveryStrategy):
18
+ """
19
+ File-based discovery strategy - discovers dependencies from project files.
20
+
21
+ Reads from pyproject.toml, requirements.txt, setup.py, etc.
22
+ """
23
+
24
+ def __init__(self, project_root: Optional[Path] = None):
25
+ """
26
+ Initialize file-based discovery strategy.
27
+
28
+ Args:
29
+ project_root: Project root directory (auto-detected if None)
30
+ """
31
+ self._project_root = project_root or self._detect_project_root()
32
+
33
+ def _detect_project_root(self) -> Path:
34
+ """Detect project root directory."""
35
+ import os
36
+ cwd = Path.cwd()
37
+
38
+ # Look for common project markers
39
+ markers = ['pyproject.toml', 'requirements.txt', 'setup.py', '.git']
40
+ for marker in markers:
41
+ current = cwd
42
+ for _ in range(5): # Search up to 5 levels
43
+ if (current / marker).exists():
44
+ return current
45
+ parent = current.parent
46
+ if parent == current: # Reached filesystem root
47
+ break
48
+ current = parent
49
+
50
+ return cwd
51
+
52
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
53
+ """
54
+ Discover dependencies from project files.
55
+
56
+ Args:
57
+ project_root: Optional project root (uses instance root if None)
58
+
59
+ Returns:
60
+ Dict mapping import_name -> package_name
61
+ """
62
+ root = Path(project_root) if project_root else self._project_root
63
+ dependencies = {}
64
+
65
+ # Check pyproject.toml
66
+ pyproject = root / "pyproject.toml"
67
+ if pyproject.exists():
68
+ try:
69
+ import tomllib
70
+ except ImportError:
71
+ try:
72
+ import tomli as tomllib
73
+ except ImportError:
74
+ tomllib = None
75
+
76
+ if tomllib:
77
+ with open(pyproject, 'rb') as f:
78
+ data = tomllib.load(f)
79
+ project = data.get('project', {})
80
+ deps = project.get('dependencies', [])
81
+ for dep in deps:
82
+ # Parse dependency spec (e.g., "pandas>=1.0" -> "pandas")
83
+ package_name = dep.split('>=')[0].split('==')[0].split('!=')[0].strip()
84
+ # Use package name as import name (heuristic)
85
+ import_name = package_name.replace('-', '_')
86
+ dependencies[import_name] = package_name
87
+
88
+ # Check requirements.txt
89
+ requirements = root / "requirements.txt"
90
+ if requirements.exists():
91
+ with open(requirements, 'r', encoding='utf-8') as f:
92
+ for line in f:
93
+ line = line.strip()
94
+ if line and not line.startswith('#'):
95
+ # Parse requirement (e.g., "pandas>=1.0" -> "pandas")
96
+ package_name = line.split('>=')[0].split('==')[0].split('!=')[0].strip()
97
+ import_name = package_name.replace('-', '_')
98
+ dependencies[import_name] = package_name
99
+
100
+ return dependencies
101
+
102
+ def get_source(self, import_name: str) -> Optional[str]:
103
+ """
104
+ Get the source of a discovered dependency.
105
+
106
+ Args:
107
+ import_name: Import name to check
108
+
109
+ Returns:
110
+ Source file name or None
111
+ """
112
+ root = self._project_root
113
+
114
+ # Check pyproject.toml
115
+ pyproject = root / "pyproject.toml"
116
+ if pyproject.exists():
117
+ deps = self.discover()
118
+ if import_name in deps:
119
+ return "pyproject.toml"
120
+
121
+ # Check requirements.txt
122
+ requirements = root / "requirements.txt"
123
+ if requirements.exists():
124
+ deps = self.discover()
125
+ if import_name in deps:
126
+ return "requirements.txt"
127
+
128
+ return None
129
+
@@ -0,0 +1,84 @@
1
+ """
2
+ Hybrid Discovery Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Hybrid discovery - combines file-based and manifest-based discovery.
11
+ """
12
+
13
+ from pathlib import Path
14
+ from typing import Dict, Optional, Any
15
+ from ...package.base import ADiscoveryStrategy
16
+ from .package_discovery_file import FileBasedDiscovery
17
+ from .package_discovery_manifest import ManifestBasedDiscovery
18
+
19
+ class HybridDiscovery(ADiscoveryStrategy):
20
+ """
21
+ Hybrid discovery strategy - combines file-based and manifest-based discovery.
22
+
23
+ Priority: Manifest > File-based
24
+ """
25
+
26
+ def __init__(self, package_name: str = 'default', project_root: Optional[Path] = None):
27
+ """
28
+ Initialize hybrid discovery strategy.
29
+
30
+ Args:
31
+ package_name: Package name for isolation
32
+ project_root: Project root directory (auto-detected if None)
33
+ """
34
+ self._package_name = package_name
35
+ self._project_root = project_root
36
+ self._file_discovery = FileBasedDiscovery(project_root)
37
+ self._manifest_discovery = ManifestBasedDiscovery(package_name, project_root)
38
+
39
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
40
+ """
41
+ Discover dependencies from all sources.
42
+
43
+ Priority: Manifest > File-based
44
+
45
+ Args:
46
+ project_root: Optional project root (uses instance root if None)
47
+
48
+ Returns:
49
+ Dict mapping import_name -> package_name
50
+ """
51
+ dependencies = {}
52
+
53
+ # First, get file-based dependencies
54
+ file_deps = self._file_discovery.discover(project_root)
55
+ dependencies.update(file_deps)
56
+
57
+ # Then, overlay manifest dependencies (takes precedence)
58
+ manifest_deps = self._manifest_discovery.discover(project_root)
59
+ dependencies.update(manifest_deps) # Manifest overrides file-based
60
+
61
+ return dependencies
62
+
63
+ def get_source(self, import_name: str) -> Optional[str]:
64
+ """
65
+ Get the source of a discovered dependency.
66
+
67
+ Args:
68
+ import_name: Import name to check
69
+
70
+ Returns:
71
+ Source file name or "hybrid"
72
+ """
73
+ # Check manifest first (higher priority)
74
+ manifest_source = self._manifest_discovery.get_source(import_name)
75
+ if manifest_source:
76
+ return manifest_source
77
+
78
+ # Check file-based
79
+ file_source = self._file_discovery.get_source(import_name)
80
+ if file_source:
81
+ return file_source
82
+
83
+ return None
84
+
@@ -0,0 +1,101 @@
1
+ """
2
+ Manifest-Based Discovery Strategy
3
+
4
+ Company: eXonware.com
5
+ Author: Eng. Muhammad AlShehri
6
+ Email: connect@exonware.com
7
+
8
+ Generation Date: 15-Nov-2025
9
+
10
+ Manifest-based discovery - discovers dependencies from manifest files.
11
+ """
12
+
13
+ from pathlib import Path
14
+ from typing import Dict, Optional, Any
15
+ from ...package.base import ADiscoveryStrategy
16
+
17
+ class ManifestBasedDiscovery(ADiscoveryStrategy):
18
+ """
19
+ Manifest-based discovery strategy - discovers dependencies from manifest files.
20
+
21
+ Reads from xwlazy.manifest.json or pyproject.toml [tool.xwlazy] section.
22
+ """
23
+
24
+ def __init__(self, package_name: str = 'default', project_root: Optional[Path] = None):
25
+ """
26
+ Initialize manifest-based discovery strategy.
27
+
28
+ Args:
29
+ package_name: Package name for isolation
30
+ project_root: Project root directory (auto-detected if None)
31
+ """
32
+ self._package_name = package_name
33
+ self._project_root = project_root or self._detect_project_root()
34
+
35
+ def _detect_project_root(self) -> Path:
36
+ """Detect project root directory."""
37
+ import os
38
+ cwd = Path.cwd()
39
+
40
+ # Look for manifest files
41
+ markers = ['xwlazy.manifest.json', 'lazy.manifest.json', '.xwlazy.manifest.json', 'pyproject.toml']
42
+ for marker in markers:
43
+ current = cwd
44
+ for _ in range(5): # Search up to 5 levels
45
+ if (current / marker).exists():
46
+ return current
47
+ parent = current.parent
48
+ if parent == current: # Reached filesystem root
49
+ break
50
+ current = parent
51
+
52
+ return cwd
53
+
54
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
55
+ """
56
+ Discover dependencies from manifest files.
57
+
58
+ Args:
59
+ project_root: Optional project root (uses instance root if None)
60
+
61
+ Returns:
62
+ Dict mapping import_name -> package_name
63
+ """
64
+ # Lazy import to avoid circular dependency
65
+ from ...package.manifest import get_manifest_loader
66
+
67
+ loader = get_manifest_loader()
68
+ manifest = loader.get_manifest(self._package_name)
69
+
70
+ if manifest and manifest.dependencies:
71
+ return manifest.dependencies.copy()
72
+
73
+ return {}
74
+
75
+ def get_source(self, import_name: str) -> Optional[str]:
76
+ """
77
+ Get the source of a discovered dependency.
78
+
79
+ Args:
80
+ import_name: Import name to check
81
+
82
+ Returns:
83
+ Source file name (e.g., "xwlazy.manifest.json")
84
+ """
85
+ from ...package.manifest import get_manifest_loader
86
+
87
+ loader = get_manifest_loader()
88
+ manifest = loader.get_manifest(self._package_name)
89
+
90
+ if manifest and manifest.dependencies and import_name in manifest.dependencies:
91
+ # Try to find which file was used
92
+ root = self._project_root
93
+ for filename in ['xwlazy.manifest.json', 'lazy.manifest.json', '.xwlazy.manifest.json']:
94
+ if (root / filename).exists():
95
+ return filename
96
+ # Check pyproject.toml
97
+ if (root / "pyproject.toml").exists():
98
+ return "pyproject.toml [tool.xwlazy]"
99
+
100
+ return None
101
+