womm-cli 4.0.0__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 (218) hide show
  1. womm/__init__.py +53 -0
  2. womm/__main__.py +48 -0
  3. womm/_version.py +10 -0
  4. womm/assets/copier/meta/copier.yml +15 -0
  5. womm/assets/copier/meta/template/README.md.jinja +32 -0
  6. womm/assets/copier/meta/template/copier.yml.jinja +13 -0
  7. womm/assets/copier/meta/template/template/.gitkeep +0 -0
  8. womm/assets/copier/official/javascript/copier.yml +104 -0
  9. womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
  10. womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
  11. womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
  12. womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
  13. womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
  14. womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
  15. womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
  16. womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
  17. womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
  18. womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
  19. womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
  20. womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
  21. womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
  22. womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
  23. womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
  24. womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
  25. womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
  26. womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
  27. womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
  28. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
  29. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
  30. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
  31. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
  32. womm/assets/copier/official/python/copier.yml +107 -0
  33. womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
  34. womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
  35. womm/assets/copier/official/python/template/.python-version.jinja +1 -0
  36. womm/assets/copier/official/python/template/README.md.jinja +83 -0
  37. womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
  38. womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
  39. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
  40. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
  41. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
  42. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
  43. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
  44. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
  45. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
  46. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
  47. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
  48. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
  49. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
  50. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
  51. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
  52. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
  53. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
  54. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
  55. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
  56. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
  57. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
  58. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
  59. womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
  60. womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
  61. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
  62. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
  63. womm/bin/refresh_env.cmd +130 -0
  64. womm/cli.py +111 -0
  65. womm/commands/__init__.py +30 -0
  66. womm/commands/core/__init__.py +29 -0
  67. womm/commands/core/doctor.py +52 -0
  68. womm/commands/core/path.py +337 -0
  69. womm/commands/project/__init__.py +31 -0
  70. womm/commands/project/create.py +128 -0
  71. womm/commands/project/setup.py +438 -0
  72. womm/commands/project/template.py +160 -0
  73. womm/commands/system/__init__.py +31 -0
  74. womm/commands/system/context/__init__.py +82 -0
  75. womm/commands/system/context/backup.py +344 -0
  76. womm/commands/system/context/inventory.py +111 -0
  77. womm/commands/system/context/registration.py +290 -0
  78. womm/commands/system/deps.py +165 -0
  79. womm/commands/system/system.py +130 -0
  80. womm/exceptions/__init__.py +69 -0
  81. womm/exceptions/common/__init__.py +55 -0
  82. womm/exceptions/common/command_service.py +91 -0
  83. womm/exceptions/common/file_service.py +60 -0
  84. womm/exceptions/common/security_service.py +44 -0
  85. womm/exceptions/common/validation_service.py +70 -0
  86. womm/exceptions/context/__init__.py +27 -0
  87. womm/exceptions/context/context_service.py +55 -0
  88. womm/exceptions/project/__init__.py +29 -0
  89. womm/exceptions/project/project_service.py +59 -0
  90. womm/exceptions/system/__init__.py +25 -0
  91. womm/exceptions/system/system_service.py +53 -0
  92. womm/interfaces/__init__.py +71 -0
  93. womm/interfaces/context/__init__.py +34 -0
  94. womm/interfaces/context/menu_interface.py +686 -0
  95. womm/interfaces/context/registry_interface.py +562 -0
  96. womm/interfaces/context/script_detector_interface.py +208 -0
  97. womm/interfaces/context/script_registrar.py +264 -0
  98. womm/interfaces/core/__init__.py +26 -0
  99. womm/interfaces/core/doctor_interface.py +102 -0
  100. womm/interfaces/dependencies/__init__.py +28 -0
  101. womm/interfaces/dependencies/deps_interface.py +160 -0
  102. womm/interfaces/project/__init__.py +36 -0
  103. womm/interfaces/project/create_interface.py +162 -0
  104. womm/interfaces/project/detection_interface.py +181 -0
  105. womm/interfaces/project/manager_interface.py +99 -0
  106. womm/interfaces/project/setup_interface.py +477 -0
  107. womm/interfaces/project/template_store_interface.py +196 -0
  108. womm/interfaces/system/__init__.py +32 -0
  109. womm/interfaces/system/detector_interface.py +84 -0
  110. womm/interfaces/system/environment_interface.py +110 -0
  111. womm/interfaces/system/path_interface.py +570 -0
  112. womm/services/__init__.py +70 -0
  113. womm/services/common/__init__.py +33 -0
  114. womm/services/common/base_validation_service.py +450 -0
  115. womm/services/common/command_runner_service.py +647 -0
  116. womm/services/common/file_scanner_service.py +483 -0
  117. womm/services/common/security_validator_service.py +348 -0
  118. womm/services/context/__init__.py +37 -0
  119. womm/services/context/backup_entries.py +148 -0
  120. womm/services/context/parameters.py +515 -0
  121. womm/services/context/registry_paths.py +56 -0
  122. womm/services/context/registry_service.py +573 -0
  123. womm/services/context/validation_service.py +691 -0
  124. womm/services/dependencies/__init__.py +29 -0
  125. womm/services/dependencies/probe.py +102 -0
  126. womm/services/project/__init__.py +48 -0
  127. womm/services/project/copier_project_creation_service.py +111 -0
  128. womm/services/project/destination_guard.py +96 -0
  129. womm/services/project/detection_service.py +354 -0
  130. womm/services/project/env_utils.py +333 -0
  131. womm/services/project/javascript_environment_service.py +348 -0
  132. womm/services/project/python_environment_service.py +245 -0
  133. womm/services/project/setup_profile_resolver.py +146 -0
  134. womm/services/project/template_store_service.py +344 -0
  135. womm/services/project/validation_service.py +418 -0
  136. womm/services/system/__init__.py +32 -0
  137. womm/services/system/detector_service.py +704 -0
  138. womm/services/system/environment_service.py +494 -0
  139. womm/services/system/path_service.py +642 -0
  140. womm/shared/__init__.py +30 -0
  141. womm/shared/configs/__init__.py +51 -0
  142. womm/shared/configs/context/__init__.py +43 -0
  143. womm/shared/configs/context/context_config.py +125 -0
  144. womm/shared/configs/context/context_file_types_config.py +159 -0
  145. womm/shared/configs/context/context_limits_config.py +187 -0
  146. womm/shared/configs/context/context_paths_config.py +115 -0
  147. womm/shared/configs/context/context_types_config.py +65 -0
  148. womm/shared/configs/context/script_config.py +219 -0
  149. womm/shared/configs/dependencies/__init__.py +32 -0
  150. womm/shared/configs/dependencies/runtime_config.py +46 -0
  151. womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
  152. womm/shared/configs/logging_config.py +89 -0
  153. womm/shared/configs/project/__init__.py +33 -0
  154. womm/shared/configs/project/project_config.py +109 -0
  155. womm/shared/configs/project/project_structure_config.py +88 -0
  156. womm/shared/configs/project/python_project_config.py +165 -0
  157. womm/shared/configs/security/__init__.py +26 -0
  158. womm/shared/configs/security/security_patterns_config.py +242 -0
  159. womm/shared/configs/system/__init__.py +28 -0
  160. womm/shared/configs/system/system_detector_config.py +210 -0
  161. womm/shared/configs/system/system_environment_config.py +101 -0
  162. womm/shared/models/__init__.py +13 -0
  163. womm/shared/models/template_source.py +65 -0
  164. womm/shared/paths.py +192 -0
  165. womm/shared/results/__init__.py +138 -0
  166. womm/shared/results/base.py +85 -0
  167. womm/shared/results/command_results.py +61 -0
  168. womm/shared/results/context_results.py +345 -0
  169. womm/shared/results/dependency_results.py +110 -0
  170. womm/shared/results/doctor_results.py +41 -0
  171. womm/shared/results/file_results.py +97 -0
  172. womm/shared/results/project_results.py +163 -0
  173. womm/shared/results/security_results.py +128 -0
  174. womm/shared/results/system_results.py +268 -0
  175. womm/shared/results/template_results.py +43 -0
  176. womm/shared/runtime.py +36 -0
  177. womm/ui/__init__.py +31 -0
  178. womm/ui/common/__init__.py +39 -0
  179. womm/ui/common/interactive_menu.py +246 -0
  180. womm/ui/common/logging.py +184 -0
  181. womm/ui/common/prompts.py +93 -0
  182. womm/ui/context/__init__.py +31 -0
  183. womm/ui/context/display.py +485 -0
  184. womm/ui/context/menu_display.py +189 -0
  185. womm/ui/context/wizard.py +557 -0
  186. womm/ui/project/__init__.py +42 -0
  187. womm/ui/project/create/create_completion_summaries.py +55 -0
  188. womm/ui/project/project_wizard.py +174 -0
  189. womm/ui/project/setup/setup_completion_summaries.py +111 -0
  190. womm/ui/project/templates/template_store_display.py +128 -0
  191. womm/ui/system/__init__.py +60 -0
  192. womm/ui/system/display.py +531 -0
  193. womm/ui/system/path_display.py +387 -0
  194. womm/utils/__init__.py +23 -0
  195. womm/utils/common/__init__.py +49 -0
  196. womm/utils/common/file_scanner_utils.py +110 -0
  197. womm/utils/common/path_resolver_utils.py +127 -0
  198. womm/utils/common/safe_fs_utils.py +135 -0
  199. womm/utils/context/__init__.py +54 -0
  200. womm/utils/context/core_utils.py +345 -0
  201. womm/utils/context/icon_utils.py +259 -0
  202. womm/utils/project/__init__.py +106 -0
  203. womm/utils/project/asset_utils.py +154 -0
  204. womm/utils/project/core_utils.py +391 -0
  205. womm/utils/project/file_utils.py +494 -0
  206. womm/utils/project/platform_utils.py +170 -0
  207. womm/utils/project/validation_utils.py +273 -0
  208. womm/utils/security/__init__.py +46 -0
  209. womm/utils/security/security_validation_utils.py +258 -0
  210. womm/utils/system/__init__.py +69 -0
  211. womm/utils/system/detector_utils.py +299 -0
  212. womm/utils/system/environment_utils.py +172 -0
  213. womm/utils/system/path_utils.py +101 -0
  214. womm_cli-4.0.0.dist-info/METADATA +203 -0
  215. womm_cli-4.0.0.dist-info/RECORD +218 -0
  216. womm_cli-4.0.0.dist-info/WHEEL +4 -0
  217. womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
  218. womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,704 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # SYSTEM DETECTOR SERVICE - System Detection Service
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ SystemDetectorService - Service for advanced system detection.
9
+
10
+ Detects OS, architecture, package managers, and development
11
+ environments. Provides comprehensive system information for WOMM.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ # ///////////////////////////////////////////////////////////////
17
+ # IMPORTS
18
+ # ///////////////////////////////////////////////////////////////
19
+ # Standard library imports
20
+ import json
21
+ import logging
22
+ import os
23
+ import platform
24
+ import shutil
25
+ from pathlib import Path
26
+
27
+ # Local imports
28
+ from ...exceptions.common import ValidationServiceError
29
+ from ...exceptions.system import SystemServiceError
30
+ from ...shared.configs.system import PackageManagerConfig, SystemDetectorConfig
31
+ from ...shared.results import SystemInfoResult
32
+ from ...utils.system import (
33
+ create_editor_entry,
34
+ create_package_manager_entry,
35
+ create_shell_entry,
36
+ extract_version_first_line,
37
+ extract_version_from_stdout,
38
+ generate_recommendations,
39
+ get_best_package_manager,
40
+ )
41
+ from ..common.command_runner_service import CommandRunnerService
42
+
43
+ # ///////////////////////////////////////////////////////////////
44
+ # LOGGER SETUP
45
+ # ///////////////////////////////////////////////////////////////
46
+
47
+ logger = logging.getLogger(__name__)
48
+ _command_runner = CommandRunnerService()
49
+
50
+
51
+ # ///////////////////////////////////////////////////////////////
52
+ # SYSTEM DETECTOR SERVICE CLASS
53
+ # ///////////////////////////////////////////////////////////////
54
+
55
+
56
+ class SystemDetectorService:
57
+ """System detector service for real-time system detection.
58
+
59
+ Detects system information on instantiation for accurate, up-to-date results.
60
+ """
61
+
62
+ def __init__(self) -> None:
63
+ """Initialize the system detector service with fresh detection."""
64
+ try:
65
+ # Initialization is critical - raise exceptions on failure
66
+ system_info_result = self.get_system_info()
67
+ if not system_info_result.success:
68
+ raise SystemServiceError(
69
+ operation="initialization",
70
+ reason=system_info_result.message or "Failed to get system info",
71
+ details=system_info_result.error or "",
72
+ )
73
+ self.system_info = {
74
+ "platform": system_info_result.platform,
75
+ "platform_release": system_info_result.platform_release,
76
+ "platform_version": system_info_result.platform_version,
77
+ "architecture": system_info_result.architecture,
78
+ "processor": system_info_result.processor,
79
+ "python_version": system_info_result.python_version,
80
+ "python_implementation": system_info_result.python_implementation,
81
+ "node": system_info_result.node,
82
+ "user": system_info_result.user,
83
+ "home": system_info_result.home,
84
+ "shell": system_info_result.shell,
85
+ "terminal": system_info_result.terminal,
86
+ "path_separator": system_info_result.path_separator,
87
+ "line_separator": system_info_result.line_separator,
88
+ }
89
+ self.package_managers = self.detect_package_managers()
90
+ self.dev_environments = self.detect_development_environments()
91
+ except (SystemServiceError, ValidationServiceError):
92
+ # Re-raise programming errors and critical errors
93
+ raise
94
+ except Exception as e:
95
+ # Wrap unexpected external exceptions - critical init error
96
+ raise SystemServiceError(
97
+ operation="initialization",
98
+ reason=f"Failed to initialize system detector: {e}",
99
+ details=f"Exception type: {type(e).__name__}",
100
+ ) from e
101
+
102
+ # ///////////////////////////////////////////////////////////////
103
+ # PUBLIC METHODS
104
+ # ///////////////////////////////////////////////////////////////
105
+
106
+ def get_system_info(self) -> SystemInfoResult:
107
+ """
108
+ Returns basic system information.
109
+
110
+ Returns:
111
+ SystemInfoResult: System information result
112
+
113
+ Raises:
114
+ SystemInfoError: If system information gathering fails critically
115
+ """
116
+ try:
117
+ return SystemInfoResult(
118
+ success=True,
119
+ message="System information retrieved successfully",
120
+ platform=platform.system(),
121
+ platform_release=platform.release(),
122
+ platform_version=platform.version(),
123
+ architecture=platform.machine(),
124
+ processor=platform.processor(),
125
+ python_version=platform.python_version(),
126
+ python_implementation=platform.python_implementation(),
127
+ node=platform.node(),
128
+ user=os.environ.get("USER", os.environ.get("USERNAME", "unknown")),
129
+ home=str(Path.home()),
130
+ shell=os.environ.get("SHELL", "unknown"), # nosec B604 - dataclass field named `shell`, not a subprocess argument
131
+ terminal=os.environ.get("TERM", "unknown"),
132
+ path_separator=os.pathsep,
133
+ line_separator=os.linesep,
134
+ )
135
+ except OSError as e:
136
+ # Critical system errors - raise exception
137
+ raise SystemServiceError(
138
+ operation="platform_info",
139
+ reason=f"Failed to gather system information: {e}",
140
+ details=f"Exception type: {type(e).__name__}",
141
+ ) from e
142
+ except Exception as e:
143
+ # Wrap unexpected external exceptions - critical error
144
+ raise SystemServiceError(
145
+ operation="platform_info",
146
+ reason=f"Failed to gather system information: {e}",
147
+ details=f"Exception type: {type(e).__name__}",
148
+ ) from e
149
+
150
+ def detect_package_managers(
151
+ self,
152
+ ) -> dict[str, dict[str, str | bool | int | None]]:
153
+ """
154
+ Detects all available package managers.
155
+
156
+ Returns:
157
+ Dict[str, Dict]: Dictionary of detected package managers
158
+
159
+ Raises:
160
+ PackageManagerDetectionError: If package manager detection fails
161
+ """
162
+ try:
163
+ managers: dict[str, dict[str, str | bool | int | None]] = {}
164
+
165
+ # Windows
166
+ if self.system_info["platform"] == "Windows":
167
+ managers.update(self._detect_windows_managers())
168
+
169
+ # macOS
170
+ elif self.system_info["platform"] == "Darwin":
171
+ managers.update(self._detect_macos_managers())
172
+
173
+ # Linux
174
+ elif self.system_info["platform"] == "Linux":
175
+ managers.update(self._detect_linux_managers())
176
+
177
+ return managers
178
+
179
+ except SystemServiceError:
180
+ # Re-raise specialized exceptions as-is
181
+ raise
182
+ except Exception as e:
183
+ # Wrap unexpected external exceptions
184
+ raise SystemServiceError(
185
+ operation="package_manager_detection",
186
+ reason=f"Failed to detect package managers: {e}",
187
+ details=f"Exception type: {type(e).__name__}",
188
+ ) from e
189
+
190
+ # ///////////////////////////////////////////////////////////////
191
+ # PRIVATE METHODS
192
+ # ///////////////////////////////////////////////////////////////
193
+
194
+ def _detect_windows_managers(
195
+ self,
196
+ ) -> dict[str, dict[str, str | bool | int | None]]:
197
+ """
198
+ Detects Windows package managers.
199
+
200
+ Returns:
201
+ Dict[str, Dict]: Dictionary of Windows package managers
202
+
203
+ Raises:
204
+ PackageManagerDetectionError: If Windows package manager detection fails
205
+ """
206
+ try:
207
+ managers: dict[str, dict[str, str | bool | int | None]] = {}
208
+
209
+ for (
210
+ manager_name,
211
+ metadata,
212
+ ) in PackageManagerConfig.get_windows_managers().items():
213
+ command = metadata.get("command")
214
+ if not isinstance(command, str):
215
+ logger.warning(
216
+ f"Invalid command value for {manager_name}: {command}"
217
+ )
218
+ continue
219
+
220
+ availability_result = _command_runner.check_command_available(command)
221
+ if availability_result.is_available:
222
+ try:
223
+ result = _command_runner.run_silent([command, "--version"])
224
+ version = extract_version_from_stdout(
225
+ result.stdout if bool(result) else None
226
+ )
227
+ except Exception as e:
228
+ logger.warning(f"Failed to get {manager_name} version: {e}")
229
+ version = "unknown"
230
+
231
+ managers[manager_name] = create_package_manager_entry(
232
+ manager_name, version, metadata
233
+ )
234
+
235
+ return managers
236
+
237
+ except Exception as e:
238
+ # Wrap unexpected external exceptions
239
+ raise SystemServiceError(
240
+ operation="package_manager_detection:windows",
241
+ reason=f"Failed to detect Windows package managers: {e}",
242
+ details=f"Exception type: {type(e).__name__}",
243
+ ) from e
244
+
245
+ def _detect_macos_managers(
246
+ self,
247
+ ) -> dict[str, dict[str, str | bool | int | None]]:
248
+ """
249
+ Detects macOS package managers.
250
+
251
+ Returns:
252
+ Dict[str, Dict]: Dictionary of macOS package managers
253
+
254
+ Raises:
255
+ PackageManagerDetectionError: If macOS package manager detection fails
256
+ """
257
+ try:
258
+ managers: dict[str, dict[str, str | bool | int | None]] = {}
259
+
260
+ for (
261
+ manager_name,
262
+ metadata,
263
+ ) in PackageManagerConfig.get_macos_managers().items():
264
+ command = metadata.get("command")
265
+ if not isinstance(command, str):
266
+ logger.warning(
267
+ f"Invalid command value for {manager_name}: {command}"
268
+ )
269
+ continue
270
+ # Homebrew uses check_command_available, MacPorts uses shutil.which
271
+ availability_result = (
272
+ _command_runner.check_command_available(command)
273
+ if command == "brew"
274
+ else None
275
+ )
276
+ is_available = (
277
+ availability_result.is_available
278
+ if availability_result
279
+ else bool(shutil.which(command))
280
+ )
281
+
282
+ if is_available:
283
+ try:
284
+ version_args = (
285
+ ["--version"] if command == "brew" else ["version"]
286
+ )
287
+ result = _command_runner.run_silent([command, *version_args])
288
+ version = (
289
+ extract_version_first_line(
290
+ result.stdout if bool(result) else None
291
+ )
292
+ if command == "brew"
293
+ else extract_version_from_stdout(
294
+ result.stdout if bool(result) else None
295
+ )
296
+ )
297
+ except Exception as e:
298
+ logger.warning(f"Failed to get {manager_name} version: {e}")
299
+ version = "unknown"
300
+
301
+ managers[manager_name] = create_package_manager_entry(
302
+ manager_name, version, metadata
303
+ )
304
+
305
+ return managers
306
+
307
+ except Exception as e:
308
+ # Wrap unexpected external exceptions
309
+ raise SystemServiceError(
310
+ operation="package_manager_detection:macos",
311
+ reason=f"Failed to detect macOS package managers: {e}",
312
+ details=f"Exception type: {type(e).__name__}",
313
+ ) from e
314
+
315
+ def _detect_linux_managers(
316
+ self,
317
+ ) -> dict[str, dict[str, str | bool | int | None]]:
318
+ """
319
+ Detects Linux package managers.
320
+
321
+ Returns:
322
+ Dict[str, Dict]: Dictionary of Linux package managers
323
+
324
+ Raises:
325
+ PackageManagerDetectionError: If Linux package manager detection fails
326
+ """
327
+ try:
328
+ managers: dict[str, dict[str, str | bool | int | None]] = {}
329
+
330
+ for (
331
+ manager_name,
332
+ metadata,
333
+ ) in PackageManagerConfig.get_linux_managers().items():
334
+ command = metadata.get("command")
335
+ if not isinstance(command, str):
336
+ logger.warning(
337
+ f"Invalid command value for {manager_name}: {command}"
338
+ )
339
+ continue
340
+ # APT uses check_command_available, others use shutil.which
341
+ availability_result = (
342
+ _command_runner.check_command_available(command)
343
+ if command == "apt"
344
+ else None
345
+ )
346
+ is_available = (
347
+ availability_result.is_available
348
+ if availability_result
349
+ else bool(shutil.which(command))
350
+ )
351
+
352
+ if is_available:
353
+ try:
354
+ result = _command_runner.run_silent([command, "--version"])
355
+ version = extract_version_first_line(
356
+ result.stdout if bool(result) else None
357
+ )
358
+ except Exception as e:
359
+ logger.warning(f"Failed to get {manager_name} version: {e}")
360
+ version = "unknown"
361
+
362
+ managers[manager_name] = create_package_manager_entry(
363
+ manager_name, version, metadata
364
+ )
365
+
366
+ return managers
367
+
368
+ except Exception as e:
369
+ # Wrap unexpected external exceptions
370
+ raise SystemServiceError(
371
+ operation="package_manager_detection:linux",
372
+ reason=f"Failed to detect Linux package managers: {e}",
373
+ details=f"Exception type: {type(e).__name__}",
374
+ ) from e
375
+
376
+ def detect_development_environments(
377
+ self,
378
+ ) -> dict[str, dict[str, str | bool]]:
379
+ """
380
+ Detects development environments.
381
+
382
+ Returns:
383
+ Dict[str, Dict]: Dictionary of detected development environments
384
+
385
+ Raises:
386
+ DevelopmentEnvironmentDetectionError: If development environment detection fails
387
+ """
388
+ try:
389
+ envs: dict[str, dict[str, str | bool]] = {}
390
+ platform_name = self.system_info["platform"]
391
+
392
+ # Editors/IDEs - filter by platform for relevance
393
+ editor_configs = self._get_platform_editors(platform_name)
394
+ for cmd, name in editor_configs.items():
395
+ cmd_path = shutil.which(cmd)
396
+ if cmd_path:
397
+ version = "unknown"
398
+ try:
399
+ # Use full path returned by shutil.which to handle .CMD/.BAT on Windows
400
+ result = _command_runner.run_silent([cmd_path, "--version"])
401
+ if result.returncode == 0 and result.stdout:
402
+ version = extract_version_first_line(result.stdout)
403
+ else:
404
+ # Log when version extraction fails
405
+ logger.debug(
406
+ f"Could not extract version for {cmd}: "
407
+ f"returncode={result.returncode}, stdout={bool(result.stdout)}"
408
+ )
409
+ except Exception as e:
410
+ logger.debug(f"Failed to get version for {cmd}: {e}")
411
+
412
+ envs[cmd] = create_editor_entry(cmd, name, version)
413
+
414
+ # Shells - filter by platform for relevance
415
+ shell_configs = self._get_platform_shells(platform_name)
416
+ for cmd, name in shell_configs.items():
417
+ if shutil.which(cmd):
418
+ version = self._get_shell_version(cmd)
419
+ envs[f"shell_{cmd}"] = create_shell_entry(cmd, name)
420
+ # Add version to shell entry if available
421
+ if version and version != "unknown":
422
+ envs[f"shell_{cmd}"]["version"] = version
423
+
424
+ return envs
425
+
426
+ except Exception as e:
427
+ # Wrap unexpected external exceptions
428
+ raise SystemServiceError(
429
+ operation="development_environment_detection",
430
+ reason=f"Failed to detect development environments: {e}",
431
+ details=f"Exception type: {type(e).__name__}",
432
+ ) from e
433
+
434
+ def _get_platform_editors(self, platform_name: str) -> dict[str, str]:
435
+ """
436
+ Get relevant editors for the current platform.
437
+
438
+ Args:
439
+ platform_name: Name of the platform (Windows, Darwin, Linux)
440
+
441
+ Returns:
442
+ Dict[str, str]: Platform-specific editor configurations
443
+ """
444
+ if platform_name == "Windows":
445
+ # Windows: show native editors only
446
+ return {
447
+ "code": SystemDetectorConfig.EDITORS.get("code", "Visual Studio Code"),
448
+ }
449
+ elif platform_name == "Darwin":
450
+ # macOS: show common editors
451
+ return {
452
+ k: v
453
+ for k, v in SystemDetectorConfig.EDITORS.items()
454
+ if k in ["code", "vim", "nvim", "emacs", "subl"]
455
+ }
456
+ else: # Linux and others
457
+ # Linux: show all editors
458
+ return {
459
+ k: v
460
+ for k, v in SystemDetectorConfig.EDITORS.items()
461
+ if k not in ["atom"] # Atom is deprecated
462
+ }
463
+
464
+ def _get_platform_shells(self, platform_name: str) -> dict[str, str]:
465
+ """
466
+ Get relevant shells for the current platform.
467
+
468
+ Args:
469
+ platform_name: Name of the platform (Windows, Darwin, Linux)
470
+
471
+ Returns:
472
+ Dict[str, str]: Platform-specific shell configurations
473
+ """
474
+ if platform_name == "Windows":
475
+ # Windows: show native shells only (PowerShell, not bash/zsh from Git)
476
+ return {
477
+ "powershell": SystemDetectorConfig.SHELLS.get(
478
+ "powershell", "PowerShell"
479
+ ),
480
+ }
481
+ elif platform_name == "Darwin":
482
+ # macOS: show common shells
483
+ return {
484
+ k: v
485
+ for k, v in SystemDetectorConfig.SHELLS.items()
486
+ if k in ["bash", "zsh", "fish", "powershell"]
487
+ }
488
+ else: # Linux
489
+ # Linux: show all shells
490
+ return SystemDetectorConfig.SHELLS
491
+
492
+ def get_best_package_manager(self) -> str | None:
493
+ """
494
+ Returns the best available package manager.
495
+
496
+ Returns:
497
+ Optional[str]: Name of the best package manager or None
498
+
499
+ Raises:
500
+ SystemDetectionError: If package manager selection fails
501
+ """
502
+ try:
503
+ return get_best_package_manager(self.package_managers)
504
+ except Exception as e:
505
+ # Wrap unexpected external exceptions
506
+ raise SystemServiceError(
507
+ operation="best_package_manager",
508
+ reason=f"Failed to select best package manager: {e}",
509
+ details=f"Exception type: {type(e).__name__}",
510
+ ) from e
511
+
512
+ def _get_shell_version(self, shell: str) -> str:
513
+ """
514
+ Get shell version.
515
+
516
+ Args:
517
+ shell: Shell command name (bash, zsh, powershell, etc.)
518
+
519
+ Returns:
520
+ str: Version string or "unknown"
521
+ """
522
+ try:
523
+ if shell == "powershell":
524
+ # PowerShell requires special handling - use -Command with $PSVersionTable
525
+ result = _command_runner.run_silent(
526
+ ["powershell", "-Command", "$PSVersionTable.PSVersion"]
527
+ )
528
+ if result.returncode == 0 and result.stdout:
529
+ # PowerShell returns table format:
530
+ # Major Minor Build Revision
531
+ # ----- ----- ----- --------
532
+ # 5 1 26100 7462
533
+ lines = [
534
+ line.strip()
535
+ for line in result.stdout.strip().split("\n")
536
+ if line.strip()
537
+ ]
538
+ # Skip header and separator lines, get the data line
539
+ if len(lines) >= 3:
540
+ version_parts = lines[2].split()
541
+ if len(version_parts) >= 2:
542
+ # Format as "Major.Minor"
543
+ return f"{version_parts[0]}.{version_parts[1]}"
544
+ else:
545
+ # Other shells: try --version
546
+ result = _command_runner.run_silent([shell, "--version"])
547
+ if result.returncode == 0 and result.stdout:
548
+ version = extract_version_first_line(result.stdout)
549
+ if version and version != "unknown":
550
+ return version
551
+
552
+ return "unknown"
553
+
554
+ except Exception as e:
555
+ logger.debug(f"Failed to get version for shell {shell}: {e}")
556
+ return "unknown"
557
+
558
+ def can_install_package_manager(self) -> str | None:
559
+ """
560
+ Checks if a package manager can be installed.
561
+
562
+ Returns:
563
+ Optional[str]: Name of installable package manager or None
564
+
565
+ Raises:
566
+ SystemDetectionError: If package manager installation check fails
567
+ """
568
+ try:
569
+ if self.system_info["platform"] == "Windows" and (
570
+ shutil.which("powershell") or shutil.which("pwsh")
571
+ ):
572
+ # Can install Chocolatey via PowerShell
573
+ return "chocolatey"
574
+ elif self.system_info["platform"] == "Darwin" and shutil.which("curl"):
575
+ # Can install Homebrew via curl
576
+ return "homebrew"
577
+
578
+ return None
579
+
580
+ except Exception as e:
581
+ # Wrap unexpected external exceptions
582
+ raise SystemServiceError(
583
+ operation="package_manager_install_check",
584
+ reason=f"Failed to check package manager installation capability: {e}",
585
+ details=f"Exception type: {type(e).__name__}",
586
+ ) from e
587
+
588
+ def export_report(self, output_path: Path | None = None) -> Path:
589
+ """
590
+ Generates and exports a detailed system report.
591
+
592
+ Args:
593
+ output_path: Optional path for the output file
594
+
595
+ Returns:
596
+ Path: Path to the generated report file
597
+
598
+ Raises:
599
+ ReportGenerationError: If report generation or export fails
600
+ """
601
+ try:
602
+ # Input validation
603
+ if output_path is not None and not isinstance(output_path, Path):
604
+ raise SystemServiceError(
605
+ operation="report_validation",
606
+ reason="Output path must be a Path object",
607
+ details=f"Invalid output_path type: {type(output_path)}",
608
+ )
609
+
610
+ report = {
611
+ "system_info": self.system_info,
612
+ "package_managers": self.package_managers,
613
+ "development_environments": self.dev_environments,
614
+ "recommendations": self.get_recommendations(),
615
+ }
616
+
617
+ if output_path is None:
618
+ output_path = Path.cwd() / "system_report.json"
619
+
620
+ try:
621
+ with open(output_path, "w", encoding="utf-8") as f:
622
+ json.dump(report, f, indent=2, ensure_ascii=False)
623
+ except OSError as e:
624
+ raise SystemServiceError(
625
+ operation="report_write",
626
+ reason="Cannot write report file",
627
+ details=f"File: {output_path} | Error: {e}",
628
+ ) from e
629
+ except (TypeError, ValueError) as e:
630
+ raise SystemServiceError(
631
+ operation="report_serialization",
632
+ reason="Cannot serialize report data",
633
+ details=f"File: {output_path} | Error: {e}",
634
+ ) from e
635
+
636
+ return output_path
637
+
638
+ except SystemServiceError:
639
+ # Re-raise specialized exceptions as-is
640
+ raise
641
+ except Exception as e:
642
+ # Wrap unexpected external exceptions
643
+ raise SystemServiceError(
644
+ operation="report_generation",
645
+ reason=f"Failed to generate system report: {e}",
646
+ details=(
647
+ f"File: {output_path if output_path else 'unknown'} | "
648
+ f"Exception type: {type(e).__name__}"
649
+ ),
650
+ ) from e
651
+
652
+ def get_recommendations(self) -> dict[str, str]:
653
+ """
654
+ Generates recommendations based on detection.
655
+
656
+ Returns:
657
+ Dict[str, str]: Dictionary of recommendations
658
+
659
+ Raises:
660
+ SystemDetectionError: If recommendation generation fails
661
+ """
662
+ try:
663
+ best_manager = self.get_best_package_manager()
664
+ installable_manager = self.can_install_package_manager()
665
+
666
+ return generate_recommendations(
667
+ self.package_managers,
668
+ self.dev_environments,
669
+ best_manager,
670
+ installable_manager,
671
+ )
672
+
673
+ except Exception as e:
674
+ # Wrap unexpected external exceptions
675
+ raise SystemServiceError(
676
+ operation="recommendations",
677
+ reason=f"Failed to generate recommendations: {e}",
678
+ details=f"Exception type: {type(e).__name__}",
679
+ ) from e
680
+
681
+ def get_system_data(self) -> dict[str, object]:
682
+ """
683
+ Returns complete system data without any display logic.
684
+
685
+ Returns:
686
+ Dict: Complete system data dictionary
687
+
688
+ Raises:
689
+ SystemDetectionError: If system data retrieval fails
690
+ """
691
+ try:
692
+ return {
693
+ "system_info": self.system_info,
694
+ "package_managers": self.package_managers,
695
+ "dev_environments": self.dev_environments,
696
+ "recommendations": self.get_recommendations(),
697
+ }
698
+ except Exception as e:
699
+ # Wrap unexpected external exceptions
700
+ raise SystemServiceError(
701
+ operation="system_data",
702
+ reason=f"Failed to retrieve system data: {e}",
703
+ details=f"Exception type: {type(e).__name__}",
704
+ ) from e