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,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,130 @@
1
+ """
2
+ File-Based Discovery Strategy
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
+ 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
+
18
+ class FileBasedDiscovery(ADiscoveryStrategy):
19
+ """
20
+ File-based discovery strategy - discovers dependencies from project files.
21
+
22
+ Reads from pyproject.toml, requirements.txt, setup.py, etc.
23
+ """
24
+
25
+ def __init__(self, project_root: Optional[Path] = None):
26
+ """
27
+ Initialize file-based discovery strategy.
28
+
29
+ Args:
30
+ project_root: Project root directory (auto-detected if None)
31
+ """
32
+ self._project_root = project_root or self._detect_project_root()
33
+
34
+ def _detect_project_root(self) -> Path:
35
+ """Detect project root directory."""
36
+ import os
37
+ cwd = Path.cwd()
38
+
39
+ # Look for common project markers
40
+ markers = ['pyproject.toml', 'requirements.txt', 'setup.py', '.git']
41
+ for marker in markers:
42
+ current = cwd
43
+ for _ in range(5): # Search up to 5 levels
44
+ if (current / marker).exists():
45
+ return current
46
+ parent = current.parent
47
+ if parent == current: # Reached filesystem root
48
+ break
49
+ current = parent
50
+
51
+ return cwd
52
+
53
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
54
+ """
55
+ Discover dependencies from project files.
56
+
57
+ Args:
58
+ project_root: Optional project root (uses instance root if None)
59
+
60
+ Returns:
61
+ Dict mapping import_name -> package_name
62
+ """
63
+ root = Path(project_root) if project_root else self._project_root
64
+ dependencies = {}
65
+
66
+ # Check pyproject.toml
67
+ pyproject = root / "pyproject.toml"
68
+ if pyproject.exists():
69
+ try:
70
+ import tomllib
71
+ except ImportError:
72
+ try:
73
+ import tomli as tomllib
74
+ except ImportError:
75
+ tomllib = None
76
+
77
+ if tomllib:
78
+ with open(pyproject, 'rb') as f:
79
+ data = tomllib.load(f)
80
+ project = data.get('project', {})
81
+ deps = project.get('dependencies', [])
82
+ for dep in deps:
83
+ # Parse dependency spec (e.g., "pandas>=1.0" -> "pandas")
84
+ package_name = dep.split('>=')[0].split('==')[0].split('!=')[0].strip()
85
+ # Use package name as import name (heuristic)
86
+ import_name = package_name.replace('-', '_')
87
+ dependencies[import_name] = package_name
88
+
89
+ # Check requirements.txt
90
+ requirements = root / "requirements.txt"
91
+ if requirements.exists():
92
+ with open(requirements, 'r', encoding='utf-8') as f:
93
+ for line in f:
94
+ line = line.strip()
95
+ if line and not line.startswith('#'):
96
+ # Parse requirement (e.g., "pandas>=1.0" -> "pandas")
97
+ package_name = line.split('>=')[0].split('==')[0].split('!=')[0].strip()
98
+ import_name = package_name.replace('-', '_')
99
+ dependencies[import_name] = package_name
100
+
101
+ return dependencies
102
+
103
+ def get_source(self, import_name: str) -> Optional[str]:
104
+ """
105
+ Get the source of a discovered dependency.
106
+
107
+ Args:
108
+ import_name: Import name to check
109
+
110
+ Returns:
111
+ Source file name or None
112
+ """
113
+ root = self._project_root
114
+
115
+ # Check pyproject.toml
116
+ pyproject = root / "pyproject.toml"
117
+ if pyproject.exists():
118
+ deps = self.discover()
119
+ if import_name in deps:
120
+ return "pyproject.toml"
121
+
122
+ # Check requirements.txt
123
+ requirements = root / "requirements.txt"
124
+ if requirements.exists():
125
+ deps = self.discover()
126
+ if import_name in deps:
127
+ return "requirements.txt"
128
+
129
+ return None
130
+
@@ -0,0 +1,85 @@
1
+ """
2
+ Hybrid Discovery Strategy
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
+ 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
+
20
+ class HybridDiscovery(ADiscoveryStrategy):
21
+ """
22
+ Hybrid discovery strategy - combines file-based and manifest-based discovery.
23
+
24
+ Priority: Manifest > File-based
25
+ """
26
+
27
+ def __init__(self, package_name: str = 'default', project_root: Optional[Path] = None):
28
+ """
29
+ Initialize hybrid discovery strategy.
30
+
31
+ Args:
32
+ package_name: Package name for isolation
33
+ project_root: Project root directory (auto-detected if None)
34
+ """
35
+ self._package_name = package_name
36
+ self._project_root = project_root
37
+ self._file_discovery = FileBasedDiscovery(project_root)
38
+ self._manifest_discovery = ManifestBasedDiscovery(package_name, project_root)
39
+
40
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
41
+ """
42
+ Discover dependencies from all sources.
43
+
44
+ Priority: Manifest > File-based
45
+
46
+ Args:
47
+ project_root: Optional project root (uses instance root if None)
48
+
49
+ Returns:
50
+ Dict mapping import_name -> package_name
51
+ """
52
+ dependencies = {}
53
+
54
+ # First, get file-based dependencies
55
+ file_deps = self._file_discovery.discover(project_root)
56
+ dependencies.update(file_deps)
57
+
58
+ # Then, overlay manifest dependencies (takes precedence)
59
+ manifest_deps = self._manifest_discovery.discover(project_root)
60
+ dependencies.update(manifest_deps) # Manifest overrides file-based
61
+
62
+ return dependencies
63
+
64
+ def get_source(self, import_name: str) -> Optional[str]:
65
+ """
66
+ Get the source of a discovered dependency.
67
+
68
+ Args:
69
+ import_name: Import name to check
70
+
71
+ Returns:
72
+ Source file name or "hybrid"
73
+ """
74
+ # Check manifest first (higher priority)
75
+ manifest_source = self._manifest_discovery.get_source(import_name)
76
+ if manifest_source:
77
+ return manifest_source
78
+
79
+ # Check file-based
80
+ file_source = self._file_discovery.get_source(import_name)
81
+ if file_source:
82
+ return file_source
83
+
84
+ return None
85
+
@@ -0,0 +1,102 @@
1
+ """
2
+ Manifest-Based Discovery Strategy
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
+ 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
+
18
+ class ManifestBasedDiscovery(ADiscoveryStrategy):
19
+ """
20
+ Manifest-based discovery strategy - discovers dependencies from manifest files.
21
+
22
+ Reads from xwlazy.manifest.json or pyproject.toml [tool.xwlazy] section.
23
+ """
24
+
25
+ def __init__(self, package_name: str = 'default', project_root: Optional[Path] = None):
26
+ """
27
+ Initialize manifest-based discovery strategy.
28
+
29
+ Args:
30
+ package_name: Package name for isolation
31
+ project_root: Project root directory (auto-detected if None)
32
+ """
33
+ self._package_name = package_name
34
+ self._project_root = project_root or self._detect_project_root()
35
+
36
+ def _detect_project_root(self) -> Path:
37
+ """Detect project root directory."""
38
+ import os
39
+ cwd = Path.cwd()
40
+
41
+ # Look for manifest files
42
+ markers = ['xwlazy.manifest.json', 'lazy.manifest.json', '.xwlazy.manifest.json', 'pyproject.toml']
43
+ for marker in markers:
44
+ current = cwd
45
+ for _ in range(5): # Search up to 5 levels
46
+ if (current / marker).exists():
47
+ return current
48
+ parent = current.parent
49
+ if parent == current: # Reached filesystem root
50
+ break
51
+ current = parent
52
+
53
+ return cwd
54
+
55
+ def discover(self, project_root: Any = None) -> Dict[str, str]:
56
+ """
57
+ Discover dependencies from manifest files.
58
+
59
+ Args:
60
+ project_root: Optional project root (uses instance root if None)
61
+
62
+ Returns:
63
+ Dict mapping import_name -> package_name
64
+ """
65
+ # Lazy import to avoid circular dependency
66
+ from ...package.manifest import get_manifest_loader
67
+
68
+ loader = get_manifest_loader()
69
+ manifest = loader.get_manifest(self._package_name)
70
+
71
+ if manifest and manifest.dependencies:
72
+ return manifest.dependencies.copy()
73
+
74
+ return {}
75
+
76
+ def get_source(self, import_name: str) -> Optional[str]:
77
+ """
78
+ Get the source of a discovered dependency.
79
+
80
+ Args:
81
+ import_name: Import name to check
82
+
83
+ Returns:
84
+ Source file name (e.g., "xwlazy.manifest.json")
85
+ """
86
+ from ...package.manifest import get_manifest_loader
87
+
88
+ loader = get_manifest_loader()
89
+ manifest = loader.get_manifest(self._package_name)
90
+
91
+ if manifest and manifest.dependencies and import_name in manifest.dependencies:
92
+ # Try to find which file was used
93
+ root = self._project_root
94
+ for filename in ['xwlazy.manifest.json', 'lazy.manifest.json', '.xwlazy.manifest.json']:
95
+ if (root / filename).exists():
96
+ return filename
97
+ # Check pyproject.toml
98
+ if (root / "pyproject.toml").exists():
99
+ return "pyproject.toml [tool.xwlazy]"
100
+
101
+ return None
102
+
@@ -0,0 +1,114 @@
1
+ """
2
+ Async Execution Strategy
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
+ Async execution strategy - async pip install using asyncio.
11
+ Uses shared utilities from common/services/install_async_utils.
12
+ """
13
+
14
+ import sys
15
+ import asyncio
16
+ import subprocess
17
+ from typing import List, Any
18
+ from ...package.base import AInstallExecutionStrategy
19
+ from ...package.services.install_result import InstallResult, InstallStatus
20
+ from ...common.services.install_async_utils import async_install_package
21
+
22
+
23
+ class AsyncExecution(AInstallExecutionStrategy):
24
+ """
25
+ Async execution strategy - installs packages asynchronously using asyncio.
26
+
27
+ Uses asyncio subprocess for non-blocking installation.
28
+ Uses shared utilities from common/services/install_async_utils.
29
+ """
30
+
31
+ def execute_install(self, package_name: str, policy_args: List[str]) -> Any:
32
+ """
33
+ Execute installation asynchronously.
34
+
35
+ Note: This is a synchronous wrapper that runs async code.
36
+ For true async, use the async methods directly.
37
+
38
+ Args:
39
+ package_name: Package name to install
40
+ policy_args: Policy arguments
41
+
42
+ Returns:
43
+ InstallResult with success status
44
+ """
45
+ try:
46
+ # Run async install in event loop
47
+ loop = asyncio.get_event_loop()
48
+ if loop.is_running():
49
+ # If loop is running, use run_coroutine_threadsafe
50
+ future = asyncio.run_coroutine_threadsafe(
51
+ self._async_install(package_name, policy_args),
52
+ loop
53
+ )
54
+ return future.result(timeout=600) # 10 min timeout
55
+ else:
56
+ # If no loop running, use asyncio.run
57
+ return asyncio.run(self._async_install(package_name, policy_args))
58
+ except Exception as e:
59
+ return InstallResult(
60
+ package_name=package_name,
61
+ success=False,
62
+ status=InstallStatus.FAILED,
63
+ error=str(e)
64
+ )
65
+
66
+ async def _async_install(self, package_name: str, policy_args: List[str]) -> InstallResult:
67
+ """
68
+ Async installation implementation.
69
+
70
+ Args:
71
+ package_name: Package name to install
72
+ policy_args: Policy arguments
73
+
74
+ Returns:
75
+ InstallResult with success status
76
+ """
77
+ success, error_msg = await async_install_package(package_name, policy_args)
78
+
79
+ if success:
80
+ return InstallResult(
81
+ package_name=package_name,
82
+ success=True,
83
+ status=InstallStatus.SUCCESS,
84
+ source="pip-async"
85
+ )
86
+ else:
87
+ return InstallResult(
88
+ package_name=package_name,
89
+ success=False,
90
+ status=InstallStatus.FAILED,
91
+ error=error_msg or "Unknown error"
92
+ )
93
+
94
+ def execute_uninstall(self, package_name: str) -> bool:
95
+ """
96
+ Execute uninstallation using pip.
97
+
98
+ Args:
99
+ package_name: Package name to uninstall
100
+
101
+ Returns:
102
+ True if successful, False otherwise
103
+ """
104
+ try:
105
+ result = subprocess.run(
106
+ [sys.executable, '-m', 'pip', 'uninstall', '-y', package_name],
107
+ capture_output=True,
108
+ text=True,
109
+ check=True
110
+ )
111
+ return result.returncode == 0
112
+ except Exception:
113
+ return False
114
+
@@ -0,0 +1,91 @@
1
+ """
2
+ Cached Execution Strategy
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
+ Cached execution strategy - install from cached tree.
11
+ Uses shared utilities from common/services/install_cache_utils.
12
+ """
13
+
14
+ import sys
15
+ import subprocess
16
+ from pathlib import Path
17
+ from typing import List, Any, Optional
18
+ from ...package.base import AInstallExecutionStrategy
19
+ from ...package.services.install_result import InstallResult, InstallStatus
20
+ from ...common.services.install_cache_utils import (
21
+ get_cache_dir,
22
+ install_from_cached_tree,
23
+ )
24
+
25
+
26
+ class CachedExecution(AInstallExecutionStrategy):
27
+ """
28
+ Cached execution strategy - installs packages from cached installation tree.
29
+
30
+ Fastest installation method - copies from pre-extracted cache.
31
+ Uses shared utilities from common/services/install_cache_utils.
32
+ """
33
+
34
+ def __init__(self, cache_dir: Optional[Path] = None):
35
+ """
36
+ Initialize cached execution strategy.
37
+
38
+ Args:
39
+ cache_dir: Optional cache directory for installation trees
40
+ """
41
+ self._cache_dir = cache_dir
42
+
43
+ def execute_install(self, package_name: str, policy_args: List[str]) -> Any:
44
+ """
45
+ Execute installation from cached tree.
46
+
47
+ Args:
48
+ package_name: Package name to install
49
+ policy_args: Policy arguments (ignored for cached install)
50
+
51
+ Returns:
52
+ InstallResult with success status
53
+ """
54
+ success = install_from_cached_tree(package_name, self._cache_dir)
55
+
56
+ if success:
57
+ return InstallResult(
58
+ package_name=package_name,
59
+ success=True,
60
+ status=InstallStatus.SUCCESS,
61
+ source="cache-tree"
62
+ )
63
+ else:
64
+ return InstallResult(
65
+ package_name=package_name,
66
+ success=False,
67
+ status=InstallStatus.FAILED,
68
+ error="Cached installation tree not found"
69
+ )
70
+
71
+ def execute_uninstall(self, package_name: str) -> bool:
72
+ """
73
+ Execute uninstallation using pip.
74
+
75
+ Args:
76
+ package_name: Package name to uninstall
77
+
78
+ Returns:
79
+ True if successful, False otherwise
80
+ """
81
+ try:
82
+ result = subprocess.run(
83
+ [sys.executable, '-m', 'pip', 'uninstall', '-y', package_name],
84
+ capture_output=True,
85
+ text=True,
86
+ check=True
87
+ )
88
+ return result.returncode == 0
89
+ except Exception:
90
+ return False
91
+
@@ -0,0 +1,100 @@
1
+ """
2
+ Pip Execution Strategy
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
+ Pip execution strategy - direct pip install.
11
+ """
12
+
13
+ import sys
14
+ import subprocess
15
+ from typing import List, Any
16
+ from ...package.base import AInstallExecutionStrategy
17
+ from ...package.services.install_result import InstallResult, InstallStatus
18
+
19
+
20
+ class PipExecution(AInstallExecutionStrategy):
21
+ """
22
+ Pip execution strategy - installs packages directly using pip.
23
+
24
+ This is the default execution strategy that uses pip install.
25
+ """
26
+
27
+ def execute_install(self, package_name: str, policy_args: List[str]) -> Any:
28
+ """
29
+ Execute installation using pip.
30
+
31
+ Args:
32
+ package_name: Package name to install
33
+ policy_args: Policy arguments (index URLs, trusted hosts, etc.)
34
+
35
+ Returns:
36
+ InstallResult with success status
37
+ """
38
+ try:
39
+ pip_args = [sys.executable, '-m', 'pip', 'install']
40
+ if policy_args:
41
+ pip_args.extend(policy_args)
42
+ pip_args.append(package_name)
43
+
44
+ result = subprocess.run(
45
+ pip_args,
46
+ capture_output=True,
47
+ text=True,
48
+ check=True
49
+ )
50
+
51
+ if result.returncode == 0:
52
+ return InstallResult(
53
+ package_name=package_name,
54
+ success=True,
55
+ status=InstallStatus.SUCCESS,
56
+ source="pip"
57
+ )
58
+ else:
59
+ return InstallResult(
60
+ package_name=package_name,
61
+ success=False,
62
+ status=InstallStatus.FAILED,
63
+ error=result.stderr or "Unknown error"
64
+ )
65
+ except subprocess.CalledProcessError as e:
66
+ return InstallResult(
67
+ package_name=package_name,
68
+ success=False,
69
+ status=InstallStatus.FAILED,
70
+ error=e.stderr or str(e)
71
+ )
72
+ except Exception as e:
73
+ return InstallResult(
74
+ package_name=package_name,
75
+ success=False,
76
+ status=InstallStatus.FAILED,
77
+ error=str(e)
78
+ )
79
+
80
+ def execute_uninstall(self, package_name: str) -> bool:
81
+ """
82
+ Execute uninstallation using pip.
83
+
84
+ Args:
85
+ package_name: Package name to uninstall
86
+
87
+ Returns:
88
+ True if successful, False otherwise
89
+ """
90
+ try:
91
+ result = subprocess.run(
92
+ [sys.executable, '-m', 'pip', 'uninstall', '-y', package_name],
93
+ capture_output=True,
94
+ text=True,
95
+ check=True
96
+ )
97
+ return result.returncode == 0
98
+ except Exception:
99
+ return False
100
+