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,642 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # SYSTEM PATH SERVICE - User PATH Utilities (Singleton)
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ SystemPathService - cross-platform PATH management helpers for WOMM.
9
+
10
+ Provides registry (Windows) and shell-file (Unix) operations to read,
11
+ add, or remove PATH entries. Stateless utilities live in
12
+ `womm/utils/system/system_path.py`.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ # ///////////////////////////////////////////////////////////////
18
+ # IMPORTS
19
+ # ///////////////////////////////////////////////////////////////
20
+ # Standard library imports
21
+ import logging
22
+ import os
23
+ import platform
24
+ from pathlib import Path
25
+ from threading import Lock
26
+ from typing import ClassVar
27
+
28
+ # Local imports
29
+ from ...exceptions.common import ValidationServiceError
30
+ from ...exceptions.system import SystemServiceError
31
+ from ...shared.results import PathOperationResult
32
+ from ...shared.results.base import CommandResult
33
+ from ...utils.system import deduplicate_path_entries, extract_path_from_reg_output
34
+ from ..common.command_runner_service import CommandRunnerService
35
+
36
+ # ///////////////////////////////////////////////////////////////
37
+ # LOGGER SETUP
38
+ # ///////////////////////////////////////////////////////////////
39
+
40
+ logger = logging.getLogger(__name__)
41
+ _command_runner = CommandRunnerService()
42
+
43
+
44
+ # ///////////////////////////////////////////////////////////////
45
+ # PUBLIC SERVICE CLASS
46
+ # ///////////////////////////////////////////////////////////////
47
+
48
+
49
+ class SystemPathService:
50
+ """Cross-platform PATH management (singleton)."""
51
+
52
+ _instance: ClassVar[SystemPathService | None] = None
53
+ _initialized: ClassVar[bool] = False
54
+ _lock: ClassVar[Lock] = Lock()
55
+
56
+ def __new__(cls) -> SystemPathService:
57
+ with cls._lock:
58
+ if cls._instance is None:
59
+ cls._instance = super().__new__(cls)
60
+ return cls._instance
61
+
62
+ def __init__(self) -> None:
63
+ if SystemPathService._initialized:
64
+ return
65
+ SystemPathService._initialized = True
66
+
67
+ # ///////////////////////////////////////////////////////////////
68
+ # PUBLIC METHODS
69
+ # ///////////////////////////////////////////////////////////////
70
+
71
+ def get_current_system_path(self) -> PathOperationResult:
72
+ """
73
+ Get current system PATH value.
74
+
75
+ Returns:
76
+ PathOperationResult: Result with current PATH entries
77
+
78
+ Raises:
79
+ RegistryError: If registry query fails critically
80
+ UserPathError: If PATH extraction fails critically
81
+ """
82
+ import time
83
+
84
+ start_time = time.time()
85
+ try:
86
+ if platform.system() == "Windows":
87
+ query = self._query_registry_path()
88
+ try:
89
+ path_str = extract_path_from_reg_output(query.stdout)
90
+ path_entries = path_str.split(";") if path_str else []
91
+ return PathOperationResult(
92
+ success=True,
93
+ message="PATH retrieved successfully from registry",
94
+ entry_path="",
95
+ operation="get",
96
+ path_modified=False,
97
+ path_entries=[p.strip() for p in path_entries if p.strip()],
98
+ modification_time=time.time() - start_time,
99
+ )
100
+ except Exception as e:
101
+ # Business logic error - return result
102
+ return PathOperationResult(
103
+ success=False,
104
+ message=f"Failed to extract PATH from registry output: {e}",
105
+ error=str(e),
106
+ entry_path="",
107
+ operation="get",
108
+ path_modified=False,
109
+ path_entries=[],
110
+ modification_time=time.time() - start_time,
111
+ )
112
+ # Unix systems
113
+ path_str = os.environ.get("PATH", "")
114
+ path_entries = path_str.split(":") if path_str else []
115
+ return PathOperationResult(
116
+ success=True,
117
+ message="PATH retrieved successfully from environment",
118
+ entry_path="",
119
+ operation="get",
120
+ path_modified=False,
121
+ path_entries=[p.strip() for p in path_entries if p.strip()],
122
+ modification_time=time.time() - start_time,
123
+ )
124
+
125
+ except (SystemServiceError, ValidationServiceError):
126
+ # Re-raise programming errors and critical errors
127
+ raise
128
+ except Exception as e:
129
+ # Wrap unexpected external exceptions - critical error
130
+ raise SystemServiceError(
131
+ operation="path_get",
132
+ reason=f"Failed to get current system PATH: {e}",
133
+ details=f"Exception type: {type(e).__name__}",
134
+ ) from e
135
+
136
+ def setup_windows_path(
137
+ self, entry_path: str, original_path: str
138
+ ) -> PathOperationResult:
139
+ """
140
+ Setup WOMM in Windows PATH (user registry HKCU).
141
+
142
+ Args:
143
+ entry_path: Path entry to add
144
+ original_path: Original PATH value
145
+
146
+ Returns:
147
+ PathOperationResult: Result of the PATH setup operation
148
+
149
+ Raises:
150
+ ValidationError: If entry_path is invalid (programming error)
151
+ RegistryError: If registry operations fail critically
152
+ """
153
+ import time
154
+
155
+ start_time = time.time()
156
+ try:
157
+ # Validation errors are programming errors - raise exception
158
+ self._validate_entry(entry_path, "Windows PATH setup")
159
+ if not original_path:
160
+ raise ValidationServiceError(
161
+ operation="setup_windows_path",
162
+ field="original_path",
163
+ reason="Original path cannot be empty",
164
+ details="Empty original path provided for Windows PATH setup",
165
+ )
166
+
167
+ query = self._query_registry_path()
168
+ current_path = extract_path_from_reg_output(self._ensure_str(query.stdout))
169
+
170
+ current_entries = self._normalize_list(current_path)
171
+ normalized_womm = str(Path(entry_path))
172
+
173
+ # Business logic: path already present - return success result
174
+ if normalized_womm in current_entries:
175
+ return PathOperationResult(
176
+ success=True,
177
+ message=f"PATH entry already present: {normalized_womm}",
178
+ entry_path=normalized_womm,
179
+ operation="add",
180
+ path_modified=False,
181
+ path_entries=current_entries,
182
+ modification_time=time.time() - start_time,
183
+ )
184
+
185
+ # Add new entry
186
+ updated_entries = [*current_entries, normalized_womm]
187
+ updated_path = deduplicate_path_entries(";".join(updated_entries))
188
+
189
+ self._write_registry_path(updated_path)
190
+
191
+ return PathOperationResult(
192
+ success=True,
193
+ message=f"PATH entry added successfully: {normalized_womm}",
194
+ entry_path=normalized_womm,
195
+ operation="add",
196
+ path_modified=True,
197
+ path_entries=updated_entries,
198
+ modification_time=time.time() - start_time,
199
+ )
200
+
201
+ except (ValidationServiceError, SystemServiceError):
202
+ # Re-raise programming errors and critical errors
203
+ raise
204
+ except Exception as e:
205
+ # Wrap unexpected external exceptions - critical error
206
+ raise SystemServiceError(
207
+ operation="path_add_windows",
208
+ reason=f"Unexpected error during Windows PATH setup: {e}",
209
+ details=(
210
+ f"Exception type: {type(e).__name__}, "
211
+ f"Entry path: {entry_path}, Original PATH: {original_path}"
212
+ ),
213
+ ) from e
214
+
215
+ def remove_from_windows_path(self, entry_path: str) -> PathOperationResult:
216
+ """
217
+ Remove WOMM from Windows PATH (user registry HKCU).
218
+
219
+ Args:
220
+ entry_path: Path entry to remove
221
+
222
+ Returns:
223
+ PathOperationResult: Result of the PATH removal operation
224
+
225
+ Raises:
226
+ ValidationError: If entry_path is invalid (programming error)
227
+ RegistryError: If registry operations fail critically
228
+ """
229
+ import time
230
+
231
+ start_time = time.time()
232
+ try:
233
+ # Validation errors are programming errors - raise exception
234
+ self._validate_entry(entry_path, "Windows PATH removal")
235
+
236
+ query = self._query_registry_path()
237
+ current_path = extract_path_from_reg_output(self._ensure_str(query.stdout))
238
+
239
+ def _norm(p: str) -> str:
240
+ try:
241
+ return str(Path(p).resolve()) if p else ""
242
+ except Exception as e:
243
+ logger.warning(f"Failed to resolve path '{p}': {e}")
244
+ return p
245
+
246
+ path_entries = [p.strip() for p in current_path.split(";") if p.strip()]
247
+ normalized_womm = _norm(entry_path)
248
+
249
+ updated_entries: list[str] = []
250
+ removed_paths: list[str] = []
251
+
252
+ for entry in path_entries:
253
+ normalized_entry = _norm(entry)
254
+ if normalized_entry and normalized_entry != normalized_womm:
255
+ updated_entries.append(entry)
256
+ elif normalized_entry == normalized_womm:
257
+ removed_paths.append(entry)
258
+
259
+ # Business logic: path not found - return success result
260
+ if not removed_paths:
261
+ return PathOperationResult(
262
+ success=True,
263
+ message=f"PATH entry not found: {entry_path}",
264
+ entry_path=entry_path,
265
+ operation="remove",
266
+ path_modified=False,
267
+ path_entries=path_entries,
268
+ modification_time=time.time() - start_time,
269
+ )
270
+
271
+ # Remove entry
272
+ updated_path = ";".join(updated_entries)
273
+ self._write_registry_path(updated_path)
274
+
275
+ return PathOperationResult(
276
+ success=True,
277
+ message=f"PATH entry removed successfully: {entry_path}",
278
+ entry_path=entry_path,
279
+ operation="remove",
280
+ path_modified=True,
281
+ path_entries=updated_entries,
282
+ modification_time=time.time() - start_time,
283
+ )
284
+
285
+ except (ValidationServiceError, SystemServiceError):
286
+ # Re-raise programming errors and critical errors
287
+ raise
288
+ except Exception as e:
289
+ # Wrap unexpected external exceptions - critical error
290
+ raise SystemServiceError(
291
+ operation="path_remove_windows",
292
+ reason=f"Unexpected error during Windows PATH removal: {e}",
293
+ details=(
294
+ f"Exception type: {type(e).__name__}, Entry path: {entry_path}"
295
+ ),
296
+ ) from e
297
+
298
+ def setup_unix_path(
299
+ self, entry_path: str, original_path: str
300
+ ) -> PathOperationResult:
301
+ """
302
+ Setup WOMM in Unix PATH via shell rc files.
303
+
304
+ Args:
305
+ entry_path: Path entry to add
306
+ original_path: Original PATH value
307
+
308
+ Returns:
309
+ PathOperationResult: Result of the PATH setup operation
310
+
311
+ Raises:
312
+ ValidationError: If entry_path is invalid (programming error)
313
+ FileSystemError: If file operations fail critically
314
+ """
315
+ import time
316
+
317
+ start_time = time.time()
318
+ try:
319
+ # Validation errors are programming errors - raise exception
320
+ self._validate_entry(entry_path, "Unix PATH setup")
321
+ if not original_path:
322
+ raise ValidationServiceError(
323
+ operation="setup_unix_path",
324
+ field="original_path",
325
+ reason="Original path cannot be empty",
326
+ details="Empty original path provided for Unix PATH setup",
327
+ )
328
+
329
+ shell_rc_files = [
330
+ Path.home() / ".bashrc",
331
+ Path.home() / ".zshrc",
332
+ Path.home() / ".profile",
333
+ ]
334
+
335
+ target_rc = next((rc for rc in shell_rc_files if rc.exists()), None) or (
336
+ Path.home() / ".bashrc"
337
+ )
338
+
339
+ womm_export_line = f'export PATH="{entry_path}:$PATH"'
340
+ womm_path_comment = "# Added by Works On My Machine (womm path add)"
341
+
342
+ # Business logic: path already present - return success result
343
+ if target_rc.exists():
344
+ with open(target_rc, encoding="utf-8") as f:
345
+ if entry_path in f.read():
346
+ return PathOperationResult(
347
+ success=True,
348
+ message=f"PATH entry already present in {target_rc}: {entry_path}",
349
+ entry_path=entry_path,
350
+ operation="add",
351
+ path_modified=False,
352
+ path_entries=[],
353
+ modification_time=time.time() - start_time,
354
+ )
355
+
356
+ # Add new entry
357
+ try:
358
+ with open(target_rc, "a", encoding="utf-8") as f:
359
+ f.write(f"\n{womm_path_comment}\n{womm_export_line}\n")
360
+ except (PermissionError, OSError) as e:
361
+ # Critical file system error - raise exception
362
+ raise SystemServiceError(
363
+ operation="shell_rc_write",
364
+ reason="Cannot write to shell configuration file",
365
+ details=f"path={target_rc} | Error: {e}",
366
+ ) from e
367
+
368
+ return PathOperationResult(
369
+ success=True,
370
+ message=f"PATH entry added successfully to {target_rc}: {entry_path}",
371
+ entry_path=entry_path,
372
+ operation="add",
373
+ path_modified=True,
374
+ path_entries=[entry_path],
375
+ modification_time=time.time() - start_time,
376
+ )
377
+
378
+ except (ValidationServiceError, SystemServiceError):
379
+ # Re-raise programming errors and critical errors
380
+ raise
381
+ except Exception as e:
382
+ # Wrap unexpected external exceptions - critical error
383
+ raise SystemServiceError(
384
+ operation="path_add_unix",
385
+ reason=f"Unexpected error during Unix PATH setup: {e}",
386
+ details=(
387
+ f"Exception type: {type(e).__name__}, "
388
+ f"Entry path: {entry_path}, Original PATH: {original_path}"
389
+ ),
390
+ ) from e
391
+
392
+ def remove_from_unix_path(self, entry_path: str) -> PathOperationResult:
393
+ """
394
+ Remove WOMM from Unix PATH via shell rc files.
395
+
396
+ Args:
397
+ entry_path: Path entry to remove
398
+
399
+ Returns:
400
+ PathOperationResult: Result of the PATH removal operation
401
+
402
+ Raises:
403
+ ValidationError: If entry_path is invalid (programming error)
404
+ FileSystemError: If file operations fail critically
405
+ """
406
+ import time
407
+
408
+ start_time = time.time()
409
+ try:
410
+ # Validation errors are programming errors - raise exception
411
+ self._validate_entry(entry_path, "Unix PATH removal")
412
+
413
+ shell_rc_files = [
414
+ Path.home() / ".bashrc",
415
+ Path.home() / ".zshrc",
416
+ Path.home() / ".profile",
417
+ ]
418
+
419
+ removed_from_files: list[str] = []
420
+ path_entries: list[str] = []
421
+
422
+ for rc_file in shell_rc_files:
423
+ if not rc_file.exists():
424
+ continue
425
+
426
+ try:
427
+ with open(rc_file, encoding="utf-8") as f:
428
+ lines = f.readlines()
429
+ except (PermissionError, OSError) as e:
430
+ # Critical file system error - raise exception
431
+ raise SystemServiceError(
432
+ operation="shell_rc_read",
433
+ reason="Cannot read shell configuration file",
434
+ details=f"path={rc_file} | Error: {e}",
435
+ ) from e
436
+
437
+ updated_lines: list[str] = []
438
+ removed_lines: list[str] = []
439
+
440
+ for line in lines:
441
+ if "export PATH=" in line and entry_path in line:
442
+ removed_lines.append(line.strip())
443
+ continue
444
+
445
+ updated_lines.append(line)
446
+
447
+ if removed_lines:
448
+ try:
449
+ with open(rc_file, "w", encoding="utf-8") as f:
450
+ f.writelines(updated_lines)
451
+ except (PermissionError, OSError) as e:
452
+ # Critical file system error - raise exception
453
+ raise SystemServiceError(
454
+ operation="shell_rc_write",
455
+ reason="Cannot write to shell configuration file",
456
+ details=f"path={rc_file} | Error: {e}",
457
+ ) from e
458
+
459
+ removed_from_files.append(str(rc_file))
460
+
461
+ # Business logic: path not found - return success result
462
+ if not removed_from_files:
463
+ return PathOperationResult(
464
+ success=True,
465
+ message=f"PATH entry not found in any shell config file: {entry_path}",
466
+ entry_path=entry_path,
467
+ operation="remove",
468
+ path_modified=False,
469
+ path_entries=path_entries,
470
+ modification_time=time.time() - start_time,
471
+ )
472
+
473
+ # Entry removed
474
+ return PathOperationResult(
475
+ success=True,
476
+ message=f"PATH entry removed successfully from {len(removed_from_files)} file(s): {entry_path}",
477
+ entry_path=entry_path,
478
+ operation="remove",
479
+ path_modified=True,
480
+ path_entries=path_entries,
481
+ modification_time=time.time() - start_time,
482
+ )
483
+
484
+ except (ValidationServiceError, SystemServiceError):
485
+ # Re-raise programming errors and critical errors
486
+ raise
487
+ except Exception as e:
488
+ # Wrap unexpected external exceptions - critical error
489
+ raise SystemServiceError(
490
+ operation="path_remove_unix",
491
+ reason=f"Unexpected error during Unix PATH removal: {e}",
492
+ details=(
493
+ f"Exception type: {type(e).__name__}, Entry path: {entry_path}"
494
+ ),
495
+ ) from e
496
+
497
+ def remove_from_path(self, entry_path: str) -> PathOperationResult:
498
+ """
499
+ Remove WOMM from PATH (cross-platform).
500
+
501
+ Args:
502
+ entry_path: Path entry to remove
503
+
504
+ Returns:
505
+ PathOperationResult: Result of the PATH removal operation
506
+
507
+ Raises:
508
+ ValidationError: If entry_path is invalid (programming error)
509
+ RegistryError: If registry operations fail critically (Windows)
510
+ FileSystemError: If file operations fail critically (Unix)
511
+ """
512
+ try:
513
+ # Validation errors are programming errors - raise exception
514
+ self._validate_entry(entry_path, "PATH removal")
515
+
516
+ if platform.system() == "Windows":
517
+ return self.remove_from_windows_path(entry_path)
518
+
519
+ return self.remove_from_unix_path(entry_path)
520
+
521
+ except (
522
+ ValidationServiceError,
523
+ SystemServiceError,
524
+ ):
525
+ # Re-raise programming errors and critical errors
526
+ raise
527
+ except Exception as e:
528
+ # Wrap unexpected external exceptions - critical error
529
+ raise SystemServiceError(
530
+ operation="path_remove",
531
+ reason=f"Unexpected error during PATH removal: {e}",
532
+ details=(
533
+ f"Exception type: {type(e).__name__}, Entry path: {entry_path}, "
534
+ f"Platform: {platform.system()}"
535
+ ),
536
+ ) from e
537
+
538
+ # ///////////////////////////////////////////////////////////////
539
+ # PRIVATE METHODS
540
+ # ///////////////////////////////////////////////////////////////
541
+
542
+ def _query_registry_path(self) -> CommandResult:
543
+ """Query Windows registry for PATH value.
544
+
545
+ Returns:
546
+ CommandResult: Result of registry query command
547
+
548
+ Raises:
549
+ RegistryError: If registry query fails
550
+ """
551
+ try:
552
+ result = _command_runner.run_silent(
553
+ ["reg", "query", "HKCU\\Environment", "/v", "PATH"],
554
+ capture_output=True,
555
+ )
556
+ except Exception as e:
557
+ raise SystemServiceError(
558
+ operation="registry_query",
559
+ reason=f"Failed to execute registry query: {e}",
560
+ details=(
561
+ f"registry_key=HKCU\\Environment | "
562
+ f"Exception type: {type(e).__name__}"
563
+ ),
564
+ ) from e
565
+
566
+ if result.returncode != 0:
567
+ raise SystemServiceError(
568
+ operation="registry_query",
569
+ reason="Failed to query Windows user PATH from registry",
570
+ details=(
571
+ f"registry_key=HKCU\\Environment | Return code: {result.returncode}"
572
+ ),
573
+ )
574
+
575
+ return result
576
+
577
+ def _write_registry_path(self, updated_path: str) -> None:
578
+ """Write PATH value to Windows registry."""
579
+ reg_result = _command_runner.run_silent(
580
+ [
581
+ "reg",
582
+ "add",
583
+ "HKCU\\Environment",
584
+ "/v",
585
+ "PATH",
586
+ "/t",
587
+ "REG_EXPAND_SZ",
588
+ "/d",
589
+ updated_path,
590
+ "/f",
591
+ ],
592
+ capture_output=True,
593
+ )
594
+
595
+ if reg_result.returncode != 0:
596
+ stderr_str = self._ensure_str(reg_result.stderr)
597
+ raise SystemServiceError(
598
+ operation="registry_update",
599
+ reason="Failed to update PATH in registry",
600
+ details=(
601
+ f"registry_key=HKCU\\Environment | "
602
+ f"Return code: {reg_result.returncode}, "
603
+ f"Stderr: {stderr_str}"
604
+ ),
605
+ )
606
+
607
+ @staticmethod
608
+ def _normalize_list(path_str: str) -> list[str]:
609
+ """Normalize PATH entries list."""
610
+ try:
611
+ entries = [p.strip() for p in path_str.split(";") if p.strip()]
612
+ return [str(Path(p)) for p in entries]
613
+ except Exception as e:
614
+ raise SystemServiceError(
615
+ operation="path_normalize",
616
+ reason="Failed to normalize PATH entries",
617
+ details=f"Exception type: {type(e).__name__}, Path string: {path_str}",
618
+ ) from e
619
+
620
+ @staticmethod
621
+ def _ensure_str(value: str | bytes) -> str:
622
+ """Ensure string value, decoding bytes if needed."""
623
+ return value.decode() if isinstance(value, bytes) else value
624
+
625
+ @staticmethod
626
+ def _validate_entry(entry_path: str, context: str) -> None:
627
+ """Validate entry path.
628
+
629
+ Args:
630
+ entry_path: Path entry to validate
631
+ context: Context for validation error message
632
+
633
+ Raises:
634
+ ValidationError: If entry_path is invalid (programming error)
635
+ """
636
+ if not entry_path:
637
+ raise ValidationServiceError(
638
+ operation=context,
639
+ field="entry_path",
640
+ reason="Entry path cannot be empty",
641
+ details=f"Empty entry path provided for {context}",
642
+ )
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # SHARED - Shared Utilities and Models
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Shared utilities and models for Works On My Machine.
9
+
10
+ This package contains common utility modules, models, and shared functionality
11
+ used across different parts of the WOMM system.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ # ///////////////////////////////////////////////////////////////
17
+ # IMPORTS
18
+ # ///////////////////////////////////////////////////////////////
19
+ # Local imports
20
+ from . import configs, paths, results
21
+
22
+ # ///////////////////////////////////////////////////////////////
23
+ # PUBLIC API
24
+ # ///////////////////////////////////////////////////////////////
25
+
26
+ __all__ = [
27
+ "configs",
28
+ "paths",
29
+ "results",
30
+ ]