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.
- womm/__init__.py +53 -0
- womm/__main__.py +48 -0
- womm/_version.py +10 -0
- womm/assets/copier/meta/copier.yml +15 -0
- womm/assets/copier/meta/template/README.md.jinja +32 -0
- womm/assets/copier/meta/template/copier.yml.jinja +13 -0
- womm/assets/copier/meta/template/template/.gitkeep +0 -0
- womm/assets/copier/official/javascript/copier.yml +104 -0
- womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
- womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
- womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
- womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
- womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
- womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
- womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
- womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
- womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
- womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
- womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
- womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
- womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
- womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
- womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
- womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
- womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
- womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
- womm/assets/copier/official/python/copier.yml +107 -0
- womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
- womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
- womm/assets/copier/official/python/template/.python-version.jinja +1 -0
- womm/assets/copier/official/python/template/README.md.jinja +83 -0
- womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
- womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
- womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
- womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
- womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
- womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
- womm/bin/refresh_env.cmd +130 -0
- womm/cli.py +111 -0
- womm/commands/__init__.py +30 -0
- womm/commands/core/__init__.py +29 -0
- womm/commands/core/doctor.py +52 -0
- womm/commands/core/path.py +337 -0
- womm/commands/project/__init__.py +31 -0
- womm/commands/project/create.py +128 -0
- womm/commands/project/setup.py +438 -0
- womm/commands/project/template.py +160 -0
- womm/commands/system/__init__.py +31 -0
- womm/commands/system/context/__init__.py +82 -0
- womm/commands/system/context/backup.py +344 -0
- womm/commands/system/context/inventory.py +111 -0
- womm/commands/system/context/registration.py +290 -0
- womm/commands/system/deps.py +165 -0
- womm/commands/system/system.py +130 -0
- womm/exceptions/__init__.py +69 -0
- womm/exceptions/common/__init__.py +55 -0
- womm/exceptions/common/command_service.py +91 -0
- womm/exceptions/common/file_service.py +60 -0
- womm/exceptions/common/security_service.py +44 -0
- womm/exceptions/common/validation_service.py +70 -0
- womm/exceptions/context/__init__.py +27 -0
- womm/exceptions/context/context_service.py +55 -0
- womm/exceptions/project/__init__.py +29 -0
- womm/exceptions/project/project_service.py +59 -0
- womm/exceptions/system/__init__.py +25 -0
- womm/exceptions/system/system_service.py +53 -0
- womm/interfaces/__init__.py +71 -0
- womm/interfaces/context/__init__.py +34 -0
- womm/interfaces/context/menu_interface.py +686 -0
- womm/interfaces/context/registry_interface.py +562 -0
- womm/interfaces/context/script_detector_interface.py +208 -0
- womm/interfaces/context/script_registrar.py +264 -0
- womm/interfaces/core/__init__.py +26 -0
- womm/interfaces/core/doctor_interface.py +102 -0
- womm/interfaces/dependencies/__init__.py +28 -0
- womm/interfaces/dependencies/deps_interface.py +160 -0
- womm/interfaces/project/__init__.py +36 -0
- womm/interfaces/project/create_interface.py +162 -0
- womm/interfaces/project/detection_interface.py +181 -0
- womm/interfaces/project/manager_interface.py +99 -0
- womm/interfaces/project/setup_interface.py +477 -0
- womm/interfaces/project/template_store_interface.py +196 -0
- womm/interfaces/system/__init__.py +32 -0
- womm/interfaces/system/detector_interface.py +84 -0
- womm/interfaces/system/environment_interface.py +110 -0
- womm/interfaces/system/path_interface.py +570 -0
- womm/services/__init__.py +70 -0
- womm/services/common/__init__.py +33 -0
- womm/services/common/base_validation_service.py +450 -0
- womm/services/common/command_runner_service.py +647 -0
- womm/services/common/file_scanner_service.py +483 -0
- womm/services/common/security_validator_service.py +348 -0
- womm/services/context/__init__.py +37 -0
- womm/services/context/backup_entries.py +148 -0
- womm/services/context/parameters.py +515 -0
- womm/services/context/registry_paths.py +56 -0
- womm/services/context/registry_service.py +573 -0
- womm/services/context/validation_service.py +691 -0
- womm/services/dependencies/__init__.py +29 -0
- womm/services/dependencies/probe.py +102 -0
- womm/services/project/__init__.py +48 -0
- womm/services/project/copier_project_creation_service.py +111 -0
- womm/services/project/destination_guard.py +96 -0
- womm/services/project/detection_service.py +354 -0
- womm/services/project/env_utils.py +333 -0
- womm/services/project/javascript_environment_service.py +348 -0
- womm/services/project/python_environment_service.py +245 -0
- womm/services/project/setup_profile_resolver.py +146 -0
- womm/services/project/template_store_service.py +344 -0
- womm/services/project/validation_service.py +418 -0
- womm/services/system/__init__.py +32 -0
- womm/services/system/detector_service.py +704 -0
- womm/services/system/environment_service.py +494 -0
- womm/services/system/path_service.py +642 -0
- womm/shared/__init__.py +30 -0
- womm/shared/configs/__init__.py +51 -0
- womm/shared/configs/context/__init__.py +43 -0
- womm/shared/configs/context/context_config.py +125 -0
- womm/shared/configs/context/context_file_types_config.py +159 -0
- womm/shared/configs/context/context_limits_config.py +187 -0
- womm/shared/configs/context/context_paths_config.py +115 -0
- womm/shared/configs/context/context_types_config.py +65 -0
- womm/shared/configs/context/script_config.py +219 -0
- womm/shared/configs/dependencies/__init__.py +32 -0
- womm/shared/configs/dependencies/runtime_config.py +46 -0
- womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
- womm/shared/configs/logging_config.py +89 -0
- womm/shared/configs/project/__init__.py +33 -0
- womm/shared/configs/project/project_config.py +109 -0
- womm/shared/configs/project/project_structure_config.py +88 -0
- womm/shared/configs/project/python_project_config.py +165 -0
- womm/shared/configs/security/__init__.py +26 -0
- womm/shared/configs/security/security_patterns_config.py +242 -0
- womm/shared/configs/system/__init__.py +28 -0
- womm/shared/configs/system/system_detector_config.py +210 -0
- womm/shared/configs/system/system_environment_config.py +101 -0
- womm/shared/models/__init__.py +13 -0
- womm/shared/models/template_source.py +65 -0
- womm/shared/paths.py +192 -0
- womm/shared/results/__init__.py +138 -0
- womm/shared/results/base.py +85 -0
- womm/shared/results/command_results.py +61 -0
- womm/shared/results/context_results.py +345 -0
- womm/shared/results/dependency_results.py +110 -0
- womm/shared/results/doctor_results.py +41 -0
- womm/shared/results/file_results.py +97 -0
- womm/shared/results/project_results.py +163 -0
- womm/shared/results/security_results.py +128 -0
- womm/shared/results/system_results.py +268 -0
- womm/shared/results/template_results.py +43 -0
- womm/shared/runtime.py +36 -0
- womm/ui/__init__.py +31 -0
- womm/ui/common/__init__.py +39 -0
- womm/ui/common/interactive_menu.py +246 -0
- womm/ui/common/logging.py +184 -0
- womm/ui/common/prompts.py +93 -0
- womm/ui/context/__init__.py +31 -0
- womm/ui/context/display.py +485 -0
- womm/ui/context/menu_display.py +189 -0
- womm/ui/context/wizard.py +557 -0
- womm/ui/project/__init__.py +42 -0
- womm/ui/project/create/create_completion_summaries.py +55 -0
- womm/ui/project/project_wizard.py +174 -0
- womm/ui/project/setup/setup_completion_summaries.py +111 -0
- womm/ui/project/templates/template_store_display.py +128 -0
- womm/ui/system/__init__.py +60 -0
- womm/ui/system/display.py +531 -0
- womm/ui/system/path_display.py +387 -0
- womm/utils/__init__.py +23 -0
- womm/utils/common/__init__.py +49 -0
- womm/utils/common/file_scanner_utils.py +110 -0
- womm/utils/common/path_resolver_utils.py +127 -0
- womm/utils/common/safe_fs_utils.py +135 -0
- womm/utils/context/__init__.py +54 -0
- womm/utils/context/core_utils.py +345 -0
- womm/utils/context/icon_utils.py +259 -0
- womm/utils/project/__init__.py +106 -0
- womm/utils/project/asset_utils.py +154 -0
- womm/utils/project/core_utils.py +391 -0
- womm/utils/project/file_utils.py +494 -0
- womm/utils/project/platform_utils.py +170 -0
- womm/utils/project/validation_utils.py +273 -0
- womm/utils/security/__init__.py +46 -0
- womm/utils/security/security_validation_utils.py +258 -0
- womm/utils/system/__init__.py +69 -0
- womm/utils/system/detector_utils.py +299 -0
- womm/utils/system/environment_utils.py +172 -0
- womm/utils/system/path_utils.py +101 -0
- womm_cli-4.0.0.dist-info/METADATA +203 -0
- womm_cli-4.0.0.dist-info/RECORD +218 -0
- womm_cli-4.0.0.dist-info/WHEEL +4 -0
- womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
- womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PROJECT SETUP INTERFACE - Project Setup Interface
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Project setup interface for WOMM CLI.
|
|
9
|
+
|
|
10
|
+
Handles project setup operations following the MEF pattern.
|
|
11
|
+
Provides unified interface for setting up existing projects with development tools.
|
|
12
|
+
|
|
13
|
+
This interface orchestrates project creation services and converts service
|
|
14
|
+
exceptions into a typed ``ProjectSetupResult`` — it never raises.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# IMPORTS
|
|
21
|
+
# ///////////////////////////////////////////////////////////////
|
|
22
|
+
# Standard library imports
|
|
23
|
+
import logging
|
|
24
|
+
import tempfile
|
|
25
|
+
from collections.abc import Mapping
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
# Local imports
|
|
29
|
+
from ...exceptions.common import ValidationServiceError
|
|
30
|
+
from ...exceptions.project import ProjectServiceError
|
|
31
|
+
from ...services import (
|
|
32
|
+
JavaScriptEnvironmentService,
|
|
33
|
+
ProjectDetectionService,
|
|
34
|
+
PythonEnvironmentService,
|
|
35
|
+
)
|
|
36
|
+
from ...services.dependencies import probe
|
|
37
|
+
from ...services.project.copier_project_creation_service import (
|
|
38
|
+
CopierProjectCreationService,
|
|
39
|
+
ProjectCreationRequest,
|
|
40
|
+
)
|
|
41
|
+
from ...services.project.env_utils import get_virtual_environment_path
|
|
42
|
+
from ...services.project.setup_profile_resolver import (
|
|
43
|
+
SetupProfile,
|
|
44
|
+
resolve_setup_profile,
|
|
45
|
+
)
|
|
46
|
+
from ...shared.results import ProjectSetupResult
|
|
47
|
+
from ...utils.project import (
|
|
48
|
+
copy_asset_file,
|
|
49
|
+
validate_project_path,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# ///////////////////////////////////////////////////////////////
|
|
53
|
+
# LOGGER SETUP
|
|
54
|
+
# ///////////////////////////////////////////////////////////////
|
|
55
|
+
|
|
56
|
+
logger = logging.getLogger(__name__)
|
|
57
|
+
|
|
58
|
+
# ///////////////////////////////////////////////////////////////
|
|
59
|
+
# MAIN CLASS
|
|
60
|
+
# ///////////////////////////////////////////////////////////////
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ProjectSetupInterface:
|
|
64
|
+
"""
|
|
65
|
+
Interface for project setup operations.
|
|
66
|
+
|
|
67
|
+
This class provides a high-level interface for setting up existing projects,
|
|
68
|
+
orchestrating project setup services without rendering terminal output.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self):
|
|
72
|
+
"""Initialize the project setup interface."""
|
|
73
|
+
self._detection_service = ProjectDetectionService()
|
|
74
|
+
self._python_service = PythonEnvironmentService()
|
|
75
|
+
self._javascript_service = JavaScriptEnvironmentService()
|
|
76
|
+
self.logger = logging.getLogger(__name__)
|
|
77
|
+
|
|
78
|
+
# ///////////////////////////////////////////////////////////////
|
|
79
|
+
# PUBLIC METHODS
|
|
80
|
+
# ///////////////////////////////////////////////////////////////
|
|
81
|
+
|
|
82
|
+
def setup_project(
|
|
83
|
+
self,
|
|
84
|
+
project_path: Path,
|
|
85
|
+
project_type: str | None = None,
|
|
86
|
+
virtual_env: bool = False,
|
|
87
|
+
install_deps: bool = False,
|
|
88
|
+
setup_dev_tools: bool = False,
|
|
89
|
+
setup_git_hooks: bool = False,
|
|
90
|
+
template_answers: Mapping[str, object] | None = None,
|
|
91
|
+
**kwargs, # noqa: ARG002
|
|
92
|
+
) -> ProjectSetupResult:
|
|
93
|
+
"""Set up an existing project with development tools and configuration.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
project_path: Path to the existing project
|
|
97
|
+
project_type: Type of project (python, javascript, react, vue). Auto-detected if None.
|
|
98
|
+
virtual_env: Whether to create virtual environment (Python only)
|
|
99
|
+
install_deps: Whether to install dependencies
|
|
100
|
+
setup_dev_tools: Whether to set up development tools
|
|
101
|
+
setup_git_hooks: Whether to set up Git hooks
|
|
102
|
+
template_answers: Answers from a preceding Copier render, used only
|
|
103
|
+
to preserve its variant in generated editor configuration.
|
|
104
|
+
**kwargs: Additional project-specific options
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
ProjectSetupResult: Result containing setup information
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
# Validate project path
|
|
111
|
+
validate_project_path(project_path, must_exist=True, require_empty=False)
|
|
112
|
+
project_path = project_path.resolve()
|
|
113
|
+
|
|
114
|
+
# Auto-detect project type if not provided
|
|
115
|
+
if project_type is None:
|
|
116
|
+
detection_result = self._detection_service.detect_project_type(
|
|
117
|
+
project_path
|
|
118
|
+
)
|
|
119
|
+
detected_type = detection_result.project_type
|
|
120
|
+
if detected_type and detected_type != "unknown":
|
|
121
|
+
project_type = detected_type
|
|
122
|
+
else:
|
|
123
|
+
return ProjectSetupResult(
|
|
124
|
+
success=False,
|
|
125
|
+
project_path=project_path,
|
|
126
|
+
error=(
|
|
127
|
+
"Could not detect project type. Project type "
|
|
128
|
+
"detection failed. Please specify project type "
|
|
129
|
+
"manually."
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
if not project_type:
|
|
134
|
+
return ProjectSetupResult(
|
|
135
|
+
success=False,
|
|
136
|
+
project_path=project_path,
|
|
137
|
+
error="Project type is required",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Resolve the setup profile (language + VS Code variant)
|
|
141
|
+
profile = resolve_setup_profile(project_type)
|
|
142
|
+
if profile is None:
|
|
143
|
+
return ProjectSetupResult(
|
|
144
|
+
success=False,
|
|
145
|
+
project_path=project_path,
|
|
146
|
+
project_type=project_type,
|
|
147
|
+
error=(
|
|
148
|
+
f"Unsupported project type for setup: {project_type}. "
|
|
149
|
+
"Run 'womm setup detect --help' to see known types."
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Check dependencies
|
|
154
|
+
deps_error = self._check_dependencies(profile)
|
|
155
|
+
if deps_error:
|
|
156
|
+
return ProjectSetupResult(
|
|
157
|
+
success=False,
|
|
158
|
+
project_path=project_path,
|
|
159
|
+
project_type=project_type,
|
|
160
|
+
error=deps_error,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
files_modified = []
|
|
164
|
+
tools_configured = []
|
|
165
|
+
warnings = []
|
|
166
|
+
|
|
167
|
+
# Copy VSCode configuration
|
|
168
|
+
try:
|
|
169
|
+
self._copy_vscode_config(
|
|
170
|
+
project_path,
|
|
171
|
+
profile,
|
|
172
|
+
template_answers=template_answers,
|
|
173
|
+
)
|
|
174
|
+
tools_configured.append("vscode")
|
|
175
|
+
except Exception as e:
|
|
176
|
+
logger.warning(f"Failed to copy VSCode config: {e}")
|
|
177
|
+
warnings.append(f"VSCode configuration skipped: {e}")
|
|
178
|
+
|
|
179
|
+
# Set up project based on language family
|
|
180
|
+
if profile.language == "python":
|
|
181
|
+
result = self._setup_python_project(
|
|
182
|
+
project_path,
|
|
183
|
+
virtual_env=virtual_env,
|
|
184
|
+
install_deps=install_deps,
|
|
185
|
+
setup_dev_tools=setup_dev_tools,
|
|
186
|
+
setup_git_hooks=setup_git_hooks,
|
|
187
|
+
)
|
|
188
|
+
else:
|
|
189
|
+
result = self._setup_javascript_project(
|
|
190
|
+
project_path,
|
|
191
|
+
project_type,
|
|
192
|
+
install_deps=install_deps,
|
|
193
|
+
setup_dev_tools=setup_dev_tools,
|
|
194
|
+
setup_git_hooks=setup_git_hooks,
|
|
195
|
+
)
|
|
196
|
+
files_modified.extend(result.get("files_modified", []))
|
|
197
|
+
tools_configured.extend(result.get("tools_configured", []))
|
|
198
|
+
warnings.extend(result.get("warnings", []))
|
|
199
|
+
|
|
200
|
+
return ProjectSetupResult(
|
|
201
|
+
success=True,
|
|
202
|
+
project_path=project_path,
|
|
203
|
+
project_name=project_path.name,
|
|
204
|
+
project_type=project_type,
|
|
205
|
+
files_modified=files_modified,
|
|
206
|
+
tools_configured=tools_configured,
|
|
207
|
+
warnings=warnings if warnings else None,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
except (
|
|
211
|
+
ProjectServiceError,
|
|
212
|
+
ValidationServiceError,
|
|
213
|
+
ValueError,
|
|
214
|
+
OSError,
|
|
215
|
+
) as e:
|
|
216
|
+
reason = getattr(e, "reason", str(e))
|
|
217
|
+
return ProjectSetupResult(
|
|
218
|
+
success=False,
|
|
219
|
+
project_path=project_path if project_path else None,
|
|
220
|
+
project_type=project_type or "",
|
|
221
|
+
error=f"Failed to setup project: {reason}",
|
|
222
|
+
)
|
|
223
|
+
except Exception as e:
|
|
224
|
+
logger.error(f"Unexpected error during project setup: {e}", exc_info=True)
|
|
225
|
+
return ProjectSetupResult(
|
|
226
|
+
success=False,
|
|
227
|
+
project_path=project_path if project_path else None,
|
|
228
|
+
project_type=project_type or "",
|
|
229
|
+
error=f"Unexpected error during project setup: {e}",
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
# ///////////////////////////////////////////////////////////////
|
|
233
|
+
# PRIVATE METHODS
|
|
234
|
+
# ///////////////////////////////////////////////////////////////
|
|
235
|
+
|
|
236
|
+
def _setup_python_project(
|
|
237
|
+
self,
|
|
238
|
+
project_path: Path,
|
|
239
|
+
virtual_env: bool = False,
|
|
240
|
+
install_deps: bool = False,
|
|
241
|
+
setup_dev_tools: bool = False,
|
|
242
|
+
setup_git_hooks: bool = False,
|
|
243
|
+
) -> dict[str, list[str]]:
|
|
244
|
+
"""Set up Python project.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
project_path: Path to the project
|
|
248
|
+
virtual_env: Whether to create virtual environment
|
|
249
|
+
install_deps: Whether to install dependencies
|
|
250
|
+
setup_dev_tools: Whether to set up development tools
|
|
251
|
+
setup_git_hooks: Whether to set up Git hooks
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
dict: Metadata about setup with 'files_modified', 'tools_configured', 'warnings'
|
|
255
|
+
"""
|
|
256
|
+
files_modified = []
|
|
257
|
+
tools_configured = []
|
|
258
|
+
warnings = []
|
|
259
|
+
|
|
260
|
+
# Setup virtual environment
|
|
261
|
+
if virtual_env:
|
|
262
|
+
try:
|
|
263
|
+
venv_result = self._python_service.setup_virtual_environment(
|
|
264
|
+
project_path
|
|
265
|
+
)
|
|
266
|
+
if venv_result.success:
|
|
267
|
+
tools_configured.append("venv")
|
|
268
|
+
else:
|
|
269
|
+
warnings.append("Virtual environment setup failed")
|
|
270
|
+
except Exception as e:
|
|
271
|
+
logger.warning(f"Failed to setup venv: {e}")
|
|
272
|
+
warnings.append(f"Virtual environment setup skipped: {e}")
|
|
273
|
+
|
|
274
|
+
# setup_dev_tools installs the Python development dependencies itself.
|
|
275
|
+
if install_deps and not setup_dev_tools:
|
|
276
|
+
try:
|
|
277
|
+
deps_result = self._python_service.install_dev_dependencies(
|
|
278
|
+
project_path
|
|
279
|
+
)
|
|
280
|
+
if deps_result.success:
|
|
281
|
+
tools_configured.append("dependencies")
|
|
282
|
+
else:
|
|
283
|
+
warnings.append("Dependency installation failed")
|
|
284
|
+
except Exception as e:
|
|
285
|
+
logger.warning(f"Failed to install dependencies: {e}")
|
|
286
|
+
warnings.append(f"Dependency installation skipped: {e}")
|
|
287
|
+
|
|
288
|
+
# Setup dev tools
|
|
289
|
+
if setup_dev_tools:
|
|
290
|
+
try:
|
|
291
|
+
dev_tools_result = self._python_service.setup_dev_tools(project_path)
|
|
292
|
+
if dev_tools_result.success:
|
|
293
|
+
if install_deps:
|
|
294
|
+
tools_configured.append("dependencies")
|
|
295
|
+
tools_configured.append("dev_tools")
|
|
296
|
+
else:
|
|
297
|
+
warnings.append("Dev tools setup failed")
|
|
298
|
+
except Exception as e:
|
|
299
|
+
logger.warning(f"Failed to setup dev tools: {e}")
|
|
300
|
+
warnings.append(f"Dev tools setup skipped: {e}")
|
|
301
|
+
|
|
302
|
+
# Setup Git repository and hooks (if needed)
|
|
303
|
+
if setup_git_hooks:
|
|
304
|
+
try:
|
|
305
|
+
git_result = self._python_service.setup_git_repository(project_path)
|
|
306
|
+
if git_result.success:
|
|
307
|
+
tools_configured.append("git")
|
|
308
|
+
else:
|
|
309
|
+
warnings.append("Git repository setup failed")
|
|
310
|
+
except Exception as e:
|
|
311
|
+
logger.warning(f"Failed to setup git repository: {e}")
|
|
312
|
+
warnings.append(f"Git repository setup skipped: {e}")
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
"files_modified": files_modified,
|
|
316
|
+
"tools_configured": tools_configured,
|
|
317
|
+
"warnings": warnings,
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
def _setup_javascript_project(
|
|
321
|
+
self,
|
|
322
|
+
project_path: Path,
|
|
323
|
+
project_type: str,
|
|
324
|
+
install_deps: bool = False,
|
|
325
|
+
setup_dev_tools: bool = False,
|
|
326
|
+
setup_git_hooks: bool = False,
|
|
327
|
+
) -> dict[str, list[str]]:
|
|
328
|
+
"""Set up JavaScript project.
|
|
329
|
+
|
|
330
|
+
Args:
|
|
331
|
+
project_path: Path to the project
|
|
332
|
+
project_type: Type of JavaScript project (node, react, vue)
|
|
333
|
+
install_deps: Whether to install dependencies
|
|
334
|
+
setup_dev_tools: Whether to set up development tools
|
|
335
|
+
setup_git_hooks: Whether to set up Git hooks
|
|
336
|
+
|
|
337
|
+
Returns:
|
|
338
|
+
dict: Metadata about setup with 'files_modified', 'tools_configured', 'warnings'
|
|
339
|
+
"""
|
|
340
|
+
files_modified = []
|
|
341
|
+
tools_configured = []
|
|
342
|
+
warnings = []
|
|
343
|
+
|
|
344
|
+
# Install dependencies
|
|
345
|
+
if install_deps:
|
|
346
|
+
try:
|
|
347
|
+
deps_result = self._javascript_service.install_dependencies(
|
|
348
|
+
project_path, project_type
|
|
349
|
+
)
|
|
350
|
+
if deps_result.success:
|
|
351
|
+
tools_configured.append("dependencies")
|
|
352
|
+
else:
|
|
353
|
+
warnings.append("Dependency installation failed")
|
|
354
|
+
except Exception as e:
|
|
355
|
+
logger.warning(f"Failed to install dependencies: {e}")
|
|
356
|
+
warnings.append(f"Dependency installation skipped: {e}")
|
|
357
|
+
|
|
358
|
+
# Setup dev tools
|
|
359
|
+
if setup_dev_tools:
|
|
360
|
+
try:
|
|
361
|
+
dev_tools_result = self._javascript_service.setup_dev_tools(
|
|
362
|
+
project_path, project_type
|
|
363
|
+
)
|
|
364
|
+
if dev_tools_result.success:
|
|
365
|
+
tools_configured.append("dev_tools")
|
|
366
|
+
else:
|
|
367
|
+
warnings.append("Dev tools setup failed")
|
|
368
|
+
except Exception as e:
|
|
369
|
+
logger.warning(f"Failed to setup dev tools: {e}")
|
|
370
|
+
warnings.append(f"Dev tools setup skipped: {e}")
|
|
371
|
+
|
|
372
|
+
# Setup Git repository and hooks
|
|
373
|
+
if setup_git_hooks:
|
|
374
|
+
try:
|
|
375
|
+
git_result = self._javascript_service.setup_git_repository(project_path)
|
|
376
|
+
if git_result.success:
|
|
377
|
+
tools_configured.append("git")
|
|
378
|
+
else:
|
|
379
|
+
warnings.append("Git repository setup failed")
|
|
380
|
+
except Exception as e:
|
|
381
|
+
logger.warning(f"Failed to setup git repository: {e}")
|
|
382
|
+
warnings.append(f"Git repository setup skipped: {e}")
|
|
383
|
+
|
|
384
|
+
try:
|
|
385
|
+
hooks_result = self._javascript_service.setup_git_hooks(project_path)
|
|
386
|
+
if hooks_result.success:
|
|
387
|
+
tools_configured.append("git_hooks")
|
|
388
|
+
else:
|
|
389
|
+
warnings.append("Git hooks setup failed")
|
|
390
|
+
except Exception as e:
|
|
391
|
+
logger.warning(f"Failed to setup git hooks: {e}")
|
|
392
|
+
warnings.append(f"Git hooks setup skipped: {e}")
|
|
393
|
+
|
|
394
|
+
return {
|
|
395
|
+
"files_modified": files_modified,
|
|
396
|
+
"tools_configured": tools_configured,
|
|
397
|
+
"warnings": warnings,
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
def _copy_vscode_config(
|
|
401
|
+
self,
|
|
402
|
+
project_path: Path,
|
|
403
|
+
profile: SetupProfile,
|
|
404
|
+
template_answers: Mapping[str, object] | None = None,
|
|
405
|
+
) -> None:
|
|
406
|
+
"""Render VS Code configuration from the project's Copier template.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
project_path: Path to the project
|
|
410
|
+
profile: Resolved setup profile with its Copier template and answers.
|
|
411
|
+
template_answers: Optional answers from the project's initial render.
|
|
412
|
+
"""
|
|
413
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
414
|
+
rendered_project = Path(temp_dir) / "project"
|
|
415
|
+
CopierProjectCreationService().create(
|
|
416
|
+
ProjectCreationRequest(
|
|
417
|
+
template_source=profile.template_source,
|
|
418
|
+
destination=rendered_project,
|
|
419
|
+
answers={
|
|
420
|
+
**profile.answers,
|
|
421
|
+
**(template_answers or {}),
|
|
422
|
+
"project_name": project_path.name,
|
|
423
|
+
},
|
|
424
|
+
defaults=True,
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
source_dir = rendered_project / ".vscode"
|
|
429
|
+
if not source_dir.is_dir():
|
|
430
|
+
return
|
|
431
|
+
|
|
432
|
+
settings_file = source_dir / "settings.json"
|
|
433
|
+
if profile.language == "python" and settings_file.is_file():
|
|
434
|
+
venv_name = get_virtual_environment_path(project_path).name
|
|
435
|
+
if venv_name != ".venv":
|
|
436
|
+
settings = settings_file.read_text(encoding="utf-8")
|
|
437
|
+
settings_file.write_text(
|
|
438
|
+
settings.replace(
|
|
439
|
+
'"${workspaceFolder}/.venv"',
|
|
440
|
+
f'"${{workspaceFolder}}/{venv_name}"',
|
|
441
|
+
),
|
|
442
|
+
encoding="utf-8",
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
vscode_dir = project_path / ".vscode"
|
|
446
|
+
for source_file in source_dir.rglob("*"):
|
|
447
|
+
if source_file.is_file():
|
|
448
|
+
relative_path = source_file.relative_to(source_dir)
|
|
449
|
+
copy_asset_file(
|
|
450
|
+
source_file,
|
|
451
|
+
vscode_dir / relative_path,
|
|
452
|
+
overwrite=False,
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
def _check_dependencies(self, profile: SetupProfile) -> str:
|
|
456
|
+
"""Check if required dependencies are available.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
profile: Resolved setup profile with its project language.
|
|
460
|
+
|
|
461
|
+
Returns:
|
|
462
|
+
Empty string if dependencies are satisfied, otherwise an error message.
|
|
463
|
+
"""
|
|
464
|
+
try:
|
|
465
|
+
if profile.language == "python":
|
|
466
|
+
result = probe("python")
|
|
467
|
+
if not result.success:
|
|
468
|
+
return "Python runtime not found. Python runtime is required for Python projects"
|
|
469
|
+
else:
|
|
470
|
+
result = probe("node")
|
|
471
|
+
if not result.success:
|
|
472
|
+
return "Node.js runtime not found. Node.js runtime is required for JavaScript projects"
|
|
473
|
+
|
|
474
|
+
return ""
|
|
475
|
+
|
|
476
|
+
except Exception as e:
|
|
477
|
+
return f"Error checking dependencies: {e}"
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# TEMPLATE STORE INTERFACE - Template Catalog Interface
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Template store interface for WOMM CLI.
|
|
9
|
+
|
|
10
|
+
Orchestrates catalog operations (list, show, add, remove, update) against
|
|
11
|
+
``TemplateStoreService`` and template scaffolding against
|
|
12
|
+
``CopierProjectCreationService``. This interface never raises: service
|
|
13
|
+
exceptions are converted into a typed Result.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# IMPORTS
|
|
20
|
+
# ///////////////////////////////////////////////////////////////
|
|
21
|
+
# Standard library imports
|
|
22
|
+
from collections.abc import Mapping
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
# Local imports
|
|
26
|
+
from ...exceptions.project import ProjectServiceError
|
|
27
|
+
from ...services.project.copier_project_creation_service import (
|
|
28
|
+
CopierProjectCreationService,
|
|
29
|
+
ProjectCreationRequest,
|
|
30
|
+
)
|
|
31
|
+
from ...services.project.template_store_service import TemplateStoreService
|
|
32
|
+
from ...shared.paths import packaged_copier_meta
|
|
33
|
+
from ...shared.results.project_results import ProjectCreationResult
|
|
34
|
+
from ...shared.results.template_results import TemplateListResult, TemplateStoreResult
|
|
35
|
+
|
|
36
|
+
# ///////////////////////////////////////////////////////////////
|
|
37
|
+
# MAIN CLASS
|
|
38
|
+
# ///////////////////////////////////////////////////////////////
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TemplateStoreInterface:
|
|
42
|
+
"""Orchestrate catalog operations and template scaffolding."""
|
|
43
|
+
|
|
44
|
+
def __init__(self) -> None:
|
|
45
|
+
"""Initialize the template store interface."""
|
|
46
|
+
self._store = TemplateStoreService()
|
|
47
|
+
self._creator = CopierProjectCreationService()
|
|
48
|
+
|
|
49
|
+
# ///////////////////////////////////////////////////////////////
|
|
50
|
+
# PUBLIC METHODS
|
|
51
|
+
# ///////////////////////////////////////////////////////////////
|
|
52
|
+
|
|
53
|
+
def list_templates(self) -> TemplateListResult:
|
|
54
|
+
"""List every known template.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
TemplateListResult: Typed outcome, never raises.
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
entries = self._store.list_templates()
|
|
61
|
+
except ProjectServiceError as exc:
|
|
62
|
+
return TemplateListResult(success=False, error=str(exc))
|
|
63
|
+
return TemplateListResult(
|
|
64
|
+
success=True,
|
|
65
|
+
message=f"{len(entries)} template(s) available",
|
|
66
|
+
entries=entries,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def show_template(self, identifier: str) -> TemplateStoreResult:
|
|
70
|
+
"""Show a single catalog entry.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
identifier: Qualified or short template identifier.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
TemplateStoreResult: Typed outcome, never raises.
|
|
77
|
+
"""
|
|
78
|
+
try:
|
|
79
|
+
entry = self._store.resolve(identifier)
|
|
80
|
+
except ProjectServiceError as exc:
|
|
81
|
+
return TemplateStoreResult(success=False, error=str(exc))
|
|
82
|
+
return TemplateStoreResult(
|
|
83
|
+
success=True,
|
|
84
|
+
message=f"Template found: {entry.qualified_id}",
|
|
85
|
+
entry=entry,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def add_template(self, identifier: str, source: Path) -> TemplateStoreResult:
|
|
89
|
+
"""Register a local template under the user namespace.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
identifier: Short identifier, without any separator.
|
|
93
|
+
source: Directory holding ``copier.yml``.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
TemplateStoreResult: Typed outcome, never raises.
|
|
97
|
+
"""
|
|
98
|
+
try:
|
|
99
|
+
entry = self._store.add(identifier, source)
|
|
100
|
+
except ProjectServiceError as exc:
|
|
101
|
+
return TemplateStoreResult(success=False, error=str(exc))
|
|
102
|
+
return TemplateStoreResult(
|
|
103
|
+
success=True,
|
|
104
|
+
message=f"Template registered: {entry.qualified_id}",
|
|
105
|
+
entry=entry,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def remove_template(self, identifier: str) -> TemplateStoreResult:
|
|
109
|
+
"""Unregister a user template.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
identifier: Qualified or short identifier.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
TemplateStoreResult: Typed outcome, never raises.
|
|
116
|
+
"""
|
|
117
|
+
try:
|
|
118
|
+
entry = self._store.remove(identifier)
|
|
119
|
+
except ProjectServiceError as exc:
|
|
120
|
+
return TemplateStoreResult(success=False, error=str(exc))
|
|
121
|
+
return TemplateStoreResult(
|
|
122
|
+
success=True,
|
|
123
|
+
message=f"Template removed: {entry.qualified_id}",
|
|
124
|
+
entry=entry,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def update_template(self, identifier: str, source: Path) -> TemplateStoreResult:
|
|
128
|
+
"""Point an existing user template at a new source.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
identifier: Qualified or short identifier.
|
|
132
|
+
source: New directory holding ``copier.yml``.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
TemplateStoreResult: Typed outcome, never raises.
|
|
136
|
+
"""
|
|
137
|
+
try:
|
|
138
|
+
entry = self._store.update(identifier, source)
|
|
139
|
+
except ProjectServiceError as exc:
|
|
140
|
+
return TemplateStoreResult(success=False, error=str(exc))
|
|
141
|
+
return TemplateStoreResult(
|
|
142
|
+
success=True,
|
|
143
|
+
message=f"Template updated: {entry.qualified_id}",
|
|
144
|
+
entry=entry,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def init_template(
|
|
148
|
+
self,
|
|
149
|
+
destination: Path,
|
|
150
|
+
*,
|
|
151
|
+
answers: Mapping[str, str],
|
|
152
|
+
force: bool = False,
|
|
153
|
+
defaults: bool = False,
|
|
154
|
+
) -> ProjectCreationResult:
|
|
155
|
+
"""Scaffold a new Copier template skeleton.
|
|
156
|
+
|
|
157
|
+
The skeleton is rendered by the same service as projects: WOMM has no
|
|
158
|
+
second rendering engine. It carries no inference — questions, conditions
|
|
159
|
+
and structure are the template author's responsibility.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
destination: Directory to scaffold into.
|
|
163
|
+
answers: Pre-filled meta-template answers.
|
|
164
|
+
force: Allow a non-empty destination.
|
|
165
|
+
defaults: Use defaults instead of prompting.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
ProjectCreationResult: Typed outcome, never raises.
|
|
169
|
+
"""
|
|
170
|
+
try:
|
|
171
|
+
self._creator.create(
|
|
172
|
+
ProjectCreationRequest(
|
|
173
|
+
template_source=Path(str(packaged_copier_meta())),
|
|
174
|
+
destination=destination,
|
|
175
|
+
answers=dict(answers),
|
|
176
|
+
force=force,
|
|
177
|
+
defaults=defaults,
|
|
178
|
+
)
|
|
179
|
+
)
|
|
180
|
+
except ProjectServiceError as exc:
|
|
181
|
+
return ProjectCreationResult(
|
|
182
|
+
success=False, error=str(exc), project_path=destination
|
|
183
|
+
)
|
|
184
|
+
return ProjectCreationResult(
|
|
185
|
+
success=True,
|
|
186
|
+
message=f"Template skeleton created at {destination}",
|
|
187
|
+
project_path=destination,
|
|
188
|
+
project_name=destination.name,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ///////////////////////////////////////////////////////////////
|
|
193
|
+
# PUBLIC API
|
|
194
|
+
# ///////////////////////////////////////////////////////////////
|
|
195
|
+
|
|
196
|
+
__all__ = ["TemplateStoreInterface"]
|