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,348 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # JAVASCRIPT ENVIRONMENT SERVICE - JavaScript Environment Setup Service
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ JavaScript Environment Service - Singleton service for JavaScript environment setup.
9
+
10
+ Handles post-creation JavaScript/Node.js/React/Vue environment setup including:
11
+ - Dependency installation
12
+ - Development tools configuration
13
+ - Git repository initialization
14
+ - Git hooks setup
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ # ///////////////////////////////////////////////////////////////
20
+ # IMPORTS
21
+ # ///////////////////////////////////////////////////////////////
22
+ # Standard library imports
23
+ import logging
24
+ import shutil
25
+ from pathlib import Path
26
+ from threading import Lock
27
+ from typing import ClassVar
28
+
29
+ # Local imports
30
+ from ...exceptions.project import ProjectServiceError
31
+ from ...shared.results import ProjectCreationResult
32
+ from ...utils.project import validate_project_path
33
+ from ..common.command_runner_service import CommandRunnerService
34
+ from .env_utils import install_npm_dependencies, install_npm_dev_dependencies
35
+
36
+ # ///////////////////////////////////////////////////////////////
37
+ # LOGGER SETUP
38
+ # ///////////////////////////////////////////////////////////////
39
+
40
+ logger = logging.getLogger(__name__)
41
+
42
+ # ///////////////////////////////////////////////////////////////
43
+ # CONSTANTS
44
+ # ///////////////////////////////////////////////////////////////
45
+
46
+ JAVASCRIPT_PROJECT_TYPES = frozenset({"javascript", "node", "react", "vue"})
47
+
48
+
49
+ def _validate_javascript_project_type(project_type: str) -> None:
50
+ """Validate a JavaScript service project type."""
51
+ if project_type not in JAVASCRIPT_PROJECT_TYPES:
52
+ supported_types = ", ".join(sorted(JAVASCRIPT_PROJECT_TYPES))
53
+ raise ValueError(
54
+ f"Unsupported JavaScript project type: {project_type}. "
55
+ f"Supported types: {supported_types}"
56
+ )
57
+
58
+
59
+ # ///////////////////////////////////////////////////////////////
60
+ # JAVASCRIPT ENVIRONMENT SERVICE CLASS
61
+ # ///////////////////////////////////////////////////////////////
62
+
63
+
64
+ class JavaScriptEnvironmentService:
65
+ """Singleton service for JavaScript environment setup operations."""
66
+
67
+ _instance: ClassVar[JavaScriptEnvironmentService | None] = None
68
+ _initialized: ClassVar[bool] = False
69
+ _lock: ClassVar[Lock] = Lock()
70
+
71
+ def __new__(cls) -> JavaScriptEnvironmentService:
72
+ """Create or return the singleton instance.
73
+
74
+ Returns:
75
+ JavaScriptEnvironmentService: The singleton instance
76
+ """
77
+ with cls._lock:
78
+ if cls._instance is None:
79
+ cls._instance = super().__new__(cls)
80
+ return cls._instance
81
+
82
+ def __init__(self) -> None:
83
+ """Initialize JavaScript environment service (only once)."""
84
+ if JavaScriptEnvironmentService._initialized:
85
+ return
86
+
87
+ self._command_runner = CommandRunnerService()
88
+ self.logger = logging.getLogger(__name__)
89
+ JavaScriptEnvironmentService._initialized = True
90
+
91
+ def install_dependencies(
92
+ self,
93
+ project_path: Path,
94
+ project_type: str,
95
+ ) -> ProjectCreationResult:
96
+ """Install project dependencies.
97
+
98
+ Args:
99
+ project_path: Path to the project
100
+ project_type: Type of JavaScript project (node, react, vue)
101
+
102
+ Returns:
103
+ ProjectCreationResult: Result of dependency installation
104
+
105
+ Raises:
106
+ ProjectServiceError: If dependency installation fails
107
+ """
108
+ try:
109
+ validate_project_path(project_path, must_exist=True, require_empty=False)
110
+ _validate_javascript_project_type(project_type)
111
+
112
+ success = install_npm_dependencies(project_path)
113
+ if not success:
114
+ raise ProjectServiceError(
115
+ operation="install_dependencies",
116
+ reason="npm install command failed",
117
+ details="npm install did not complete successfully",
118
+ )
119
+
120
+ return ProjectCreationResult(
121
+ success=True,
122
+ message="Dependencies installed successfully",
123
+ project_path=project_path,
124
+ project_type=project_type,
125
+ )
126
+
127
+ except ProjectServiceError:
128
+ raise
129
+ except Exception as e:
130
+ logger.exception("install_dependencies failed")
131
+ raise ProjectServiceError(
132
+ operation="install_dependencies",
133
+ reason=str(e),
134
+ details=f"Exception type: {type(e).__name__}",
135
+ ) from e
136
+
137
+ def setup_dev_tools(
138
+ self, project_path: Path, project_type: str
139
+ ) -> ProjectCreationResult:
140
+ """Set up development tools.
141
+
142
+ Args:
143
+ project_path: Path to the project
144
+ project_type: Type of JavaScript project (node, react, vue)
145
+
146
+ Returns:
147
+ ProjectCreationResult: Result of dev tools setup
148
+
149
+ Raises:
150
+ ProjectServiceError: If development tools setup fails
151
+ """
152
+ try:
153
+ validate_project_path(project_path, must_exist=True, require_empty=False)
154
+ _validate_javascript_project_type(project_type)
155
+
156
+ # Check if npm is available
157
+ if not shutil.which("npm"):
158
+ raise ProjectServiceError(
159
+ operation="setup_dev_tools",
160
+ reason="npm is not installed or not in PATH",
161
+ details="npm command not found in PATH",
162
+ )
163
+
164
+ # Install development dependencies
165
+ dev_dependencies = [
166
+ "eslint",
167
+ "prettier",
168
+ "husky",
169
+ "lint-staged",
170
+ "@types/node",
171
+ ]
172
+
173
+ # Add type-specific dev dependencies
174
+ if project_type == "react":
175
+ dev_dependencies.extend(
176
+ [
177
+ "@types/react",
178
+ "@types/react-dom",
179
+ "@testing-library/react",
180
+ "@testing-library/jest-dom",
181
+ ]
182
+ )
183
+ elif project_type == "vue":
184
+ dev_dependencies.extend(
185
+ [
186
+ "@vue/cli-service",
187
+ "@vue/compiler-sfc",
188
+ ]
189
+ )
190
+
191
+ # Install dev dependencies
192
+ success = install_npm_dev_dependencies(project_path, dev_dependencies)
193
+ if not success:
194
+ raise ProjectServiceError(
195
+ operation="setup_dev_tools",
196
+ reason="Failed to install development tools",
197
+ details="npm install dev tools command failed",
198
+ )
199
+
200
+ return ProjectCreationResult(
201
+ success=True,
202
+ message="Development tools installed successfully",
203
+ project_path=project_path,
204
+ project_type=project_type,
205
+ )
206
+
207
+ except ProjectServiceError:
208
+ raise
209
+ except Exception as e:
210
+ raise ProjectServiceError(
211
+ operation="setup_dev_tools",
212
+ reason=str(e),
213
+ details=f"Exception type: {type(e).__name__}",
214
+ ) from e
215
+
216
+ def setup_git_repository(self, project_path: Path) -> ProjectCreationResult:
217
+ """Initialize a Git repository for the project.
218
+
219
+ Args:
220
+ project_path: Path to the project
221
+
222
+ Returns:
223
+ ProjectCreationResult: Result of Git setup
224
+
225
+ Raises:
226
+ ProjectServiceError: If Git setup fails
227
+ """
228
+ try:
229
+ validate_project_path(project_path, must_exist=True, require_empty=False)
230
+
231
+ # Initialize git repository using CommandRunnerService
232
+ git_path = shutil.which("git")
233
+ if not git_path:
234
+ logger.info("Git not found, skipping repository initialization")
235
+ return ProjectCreationResult(
236
+ success=True,
237
+ message="Git repository setup skipped (git not found)",
238
+ project_path=project_path,
239
+ warnings=["Git not found in system PATH"],
240
+ )
241
+ result = self._command_runner.run(
242
+ [git_path, "init"],
243
+ description="Initialize Git repository",
244
+ cwd=project_path,
245
+ )
246
+
247
+ if result.returncode == 0:
248
+ return ProjectCreationResult(
249
+ success=True,
250
+ message="Git repository initialized successfully",
251
+ project_path=project_path,
252
+ )
253
+ else:
254
+ logger.warning(f"Failed to initialize Git repository: {result.stderr}")
255
+ return ProjectCreationResult(
256
+ success=False,
257
+ message="Failed to initialize Git repository",
258
+ project_path=project_path,
259
+ error=result.stderr,
260
+ )
261
+
262
+ except ProjectServiceError:
263
+ raise
264
+ except Exception as e:
265
+ raise ProjectServiceError(
266
+ operation="setup_git_repository",
267
+ reason=str(e),
268
+ details=f"Exception type: {type(e).__name__}",
269
+ ) from e
270
+
271
+ def setup_git_hooks(self, project_path: Path) -> ProjectCreationResult:
272
+ """Set up Git hooks with Husky.
273
+
274
+ Args:
275
+ project_path: Path to the project
276
+
277
+ Returns:
278
+ ProjectCreationResult: Result of Git hooks setup
279
+
280
+ Raises:
281
+ ProjectServiceError: If Git hooks setup fails
282
+ """
283
+ try:
284
+ validate_project_path(project_path, must_exist=True, require_empty=False)
285
+
286
+ # Initialize husky using CommandRunnerService
287
+ npx_path = shutil.which("npx")
288
+ if not npx_path:
289
+ logger.warning("npx not found, skipping Git hooks setup")
290
+ return ProjectCreationResult(
291
+ success=True,
292
+ message="Git hooks setup skipped (npx not found)",
293
+ project_path=project_path,
294
+ warnings=["npx not found in system PATH"],
295
+ )
296
+ result = self._command_runner.run(
297
+ [npx_path, "husky", "install"],
298
+ description="Install Husky Git hooks",
299
+ cwd=project_path,
300
+ )
301
+
302
+ if result.returncode == 0:
303
+ hook_result = self._command_runner.run(
304
+ [
305
+ npx_path,
306
+ "husky",
307
+ "add",
308
+ ".husky/pre-commit",
309
+ "npm run lint-staged",
310
+ ],
311
+ description="Add pre-commit hook",
312
+ cwd=project_path,
313
+ )
314
+ if hook_result.returncode != 0:
315
+ return ProjectCreationResult(
316
+ success=False,
317
+ message="Failed to create Git pre-commit hook",
318
+ project_path=project_path,
319
+ error=hook_result.stderr,
320
+ )
321
+ return ProjectCreationResult(
322
+ success=True,
323
+ message="Git hooks installed successfully",
324
+ project_path=project_path,
325
+ )
326
+ else:
327
+ return ProjectCreationResult(
328
+ success=False,
329
+ message="Failed to initialize Husky",
330
+ project_path=project_path,
331
+ error=result.stderr,
332
+ )
333
+
334
+ except ProjectServiceError:
335
+ raise
336
+ except Exception as e:
337
+ raise ProjectServiceError(
338
+ operation="setup_git_hooks",
339
+ reason=str(e),
340
+ details=f"Exception type: {type(e).__name__}",
341
+ ) from e
342
+
343
+
344
+ # ///////////////////////////////////////////////////////////////
345
+ # PUBLIC API
346
+ # ///////////////////////////////////////////////////////////////
347
+
348
+ __all__ = ["JavaScriptEnvironmentService"]
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # PYTHON ENVIRONMENT SERVICE - Python Environment Setup Service
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Python Environment Service - Singleton service for Python environment setup.
9
+
10
+ Handles post-creation Python environment setup including:
11
+ - Virtual environment setup
12
+ - Dependency installation
13
+ - Development tools configuration
14
+ - Git repository initialization
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ # ///////////////////////////////////////////////////////////////
20
+ # IMPORTS
21
+ # ///////////////////////////////////////////////////////////////
22
+ # Standard library imports
23
+ import logging
24
+ from pathlib import Path
25
+ from threading import Lock
26
+ from typing import ClassVar
27
+
28
+ # Local imports
29
+ from ...exceptions.project import ProjectServiceError
30
+ from ...shared.configs.project import PythonProjectConfig
31
+ from ...shared.results import ProjectCreationResult
32
+ from ...utils.project import create_python_dev_config_files, validate_project_path
33
+ from ..common.command_runner_service import CommandRunnerService
34
+ from .env_utils import create_virtual_environment, install_python_dependencies
35
+
36
+ # ///////////////////////////////////////////////////////////////
37
+ # LOGGER SETUP
38
+ # ///////////////////////////////////////////////////////////////
39
+
40
+ logger = logging.getLogger(__name__)
41
+
42
+ # ///////////////////////////////////////////////////////////////
43
+ # PYTHON ENVIRONMENT SERVICE CLASS
44
+ # ///////////////////////////////////////////////////////////////
45
+
46
+
47
+ class PythonEnvironmentService:
48
+ """Singleton service for Python environment setup operations."""
49
+
50
+ _instance: ClassVar[PythonEnvironmentService | None] = None
51
+ _initialized: ClassVar[bool] = False
52
+ _lock: ClassVar[Lock] = Lock()
53
+
54
+ def __new__(cls) -> PythonEnvironmentService:
55
+ """Create or return the singleton instance.
56
+
57
+ Returns:
58
+ PythonEnvironmentService: The singleton instance
59
+ """
60
+ with cls._lock:
61
+ if cls._instance is None:
62
+ cls._instance = super().__new__(cls)
63
+ return cls._instance
64
+
65
+ def __init__(self) -> None:
66
+ """Initialize Python environment service (only once)."""
67
+ if PythonEnvironmentService._initialized:
68
+ return
69
+
70
+ self._command_runner = CommandRunnerService()
71
+ self.logger = logging.getLogger(__name__)
72
+ PythonEnvironmentService._initialized = True
73
+
74
+ def setup_virtual_environment(self, project_path: Path) -> ProjectCreationResult:
75
+ """Set up Python virtual environment.
76
+
77
+ Args:
78
+ project_path: Path to the project
79
+
80
+ Returns:
81
+ ProjectCreationResult: Result of venv setup
82
+
83
+ Raises:
84
+ ProjectServiceError: If venv setup fails
85
+ """
86
+ try:
87
+ result = create_virtual_environment(project_path)
88
+ if isinstance(result, dict) and result.get("success"):
89
+ return ProjectCreationResult(
90
+ success=True,
91
+ message="Virtual environment created successfully",
92
+ project_path=project_path,
93
+ project_type="python",
94
+ )
95
+ else:
96
+ raise ProjectServiceError(
97
+ operation="setup_virtual_environment",
98
+ reason="Virtual environment creation returned failure",
99
+ )
100
+
101
+ except ProjectServiceError:
102
+ raise
103
+ except Exception as e:
104
+ logger.exception("Unexpected error in setup_virtual_environment")
105
+ raise ProjectServiceError(
106
+ operation="setup_virtual_environment",
107
+ reason=str(e),
108
+ details=f"Exception type: {type(e).__name__}",
109
+ ) from e
110
+
111
+ def install_dev_dependencies(self, project_path: Path) -> ProjectCreationResult:
112
+ """Install development dependencies.
113
+
114
+ Args:
115
+ project_path: Path to the project
116
+
117
+ Returns:
118
+ ProjectCreationResult: Result of dependency installation
119
+
120
+ Raises:
121
+ ProjectServiceError: If dependency installation fails
122
+ """
123
+ try:
124
+ success = install_python_dependencies(
125
+ project_path, PythonProjectConfig.DEV_REQUIREMENTS_FILE
126
+ )
127
+ return ProjectCreationResult(
128
+ success=success,
129
+ message=(
130
+ "Development dependencies installed successfully"
131
+ if success
132
+ else "Failed to install development dependencies"
133
+ ),
134
+ project_path=project_path,
135
+ project_type="python",
136
+ )
137
+
138
+ except ProjectServiceError:
139
+ raise
140
+ except Exception as e:
141
+ logger.exception("Unexpected error in install_dev_dependencies")
142
+ raise ProjectServiceError(
143
+ operation="install_dev_dependencies",
144
+ reason=str(e),
145
+ details=f"Exception type: {type(e).__name__}",
146
+ ) from e
147
+
148
+ def setup_dev_tools(self, project_path: Path) -> ProjectCreationResult:
149
+ """Set up development tools for existing project.
150
+
151
+ Args:
152
+ project_path: Path to the project
153
+
154
+ Returns:
155
+ ProjectCreationResult: Result of dev tools setup
156
+
157
+ Raises:
158
+ ProjectServiceError: If dev tools setup fails
159
+ """
160
+ try:
161
+ # Create development configuration files if they don't exist
162
+ create_python_dev_config_files(project_path)
163
+
164
+ # Install development dependencies
165
+ return self.install_dev_dependencies(project_path)
166
+
167
+ except ProjectServiceError:
168
+ raise
169
+ except Exception as e:
170
+ logger.exception("Unexpected error in setup_dev_tools")
171
+ raise ProjectServiceError(
172
+ operation="setup_dev_tools",
173
+ reason=str(e),
174
+ details=f"Exception type: {type(e).__name__}",
175
+ ) from e
176
+
177
+ def setup_git_repository(self, project_path: Path) -> ProjectCreationResult:
178
+ """Initialize a Git repository for the project.
179
+
180
+ Args:
181
+ project_path: Path to the project
182
+
183
+ Returns:
184
+ ProjectCreationResult: Result of Git setup
185
+
186
+ Raises:
187
+ ProjectServiceError: If Git setup fails
188
+ """
189
+ try:
190
+ validate_project_path(project_path, must_exist=True, require_empty=False)
191
+
192
+ # Check if git is available
193
+ import shutil
194
+
195
+ git_path = shutil.which("git")
196
+ if not git_path:
197
+ logger.info("Git not found, skipping repository initialization")
198
+ return ProjectCreationResult(
199
+ success=True,
200
+ message="Git repository setup skipped (git not found)",
201
+ project_path=project_path,
202
+ project_type="python",
203
+ warnings=["Git not found in system PATH"],
204
+ )
205
+
206
+ # Initialize git repository
207
+ result = self._command_runner.run(
208
+ [git_path, "init"],
209
+ description="Initialize Git repository",
210
+ cwd=project_path,
211
+ )
212
+
213
+ if result.returncode == 0:
214
+ return ProjectCreationResult(
215
+ success=True,
216
+ message="Git repository initialized successfully",
217
+ project_path=project_path,
218
+ project_type="python",
219
+ )
220
+ else:
221
+ logger.warning(f"Failed to initialize Git repository: {result.stderr}")
222
+ return ProjectCreationResult(
223
+ success=False,
224
+ message="Failed to initialize Git repository",
225
+ project_path=project_path,
226
+ project_type="python",
227
+ error=result.stderr,
228
+ )
229
+
230
+ except ProjectServiceError:
231
+ raise
232
+ except Exception as e:
233
+ logger.exception("Unexpected error in setup_git_repository")
234
+ raise ProjectServiceError(
235
+ operation="setup_git_repository",
236
+ reason=str(e),
237
+ details=f"Exception type: {type(e).__name__}",
238
+ ) from e
239
+
240
+
241
+ # ///////////////////////////////////////////////////////////////
242
+ # PUBLIC API
243
+ # ///////////////////////////////////////////////////////////////
244
+
245
+ __all__ = ["PythonEnvironmentService"]