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,354 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PROJECT DETECTION SERVICE - Project Detection Service
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Project Detection Service - Singleton service for project detection.
|
|
9
|
+
|
|
10
|
+
Handles project type detection, configuration file analysis, and project structure validation.
|
|
11
|
+
Provides comprehensive project analysis capabilities for various development environments.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
import logging
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from threading import Lock
|
|
23
|
+
from typing import ClassVar
|
|
24
|
+
|
|
25
|
+
# Local imports
|
|
26
|
+
from ...exceptions.project import ProjectServiceError
|
|
27
|
+
from ...shared.configs.project import ProjectConfig
|
|
28
|
+
from ...shared.results import ProjectDetectionResult
|
|
29
|
+
from ...utils.project import (
|
|
30
|
+
analyze_csharp_config,
|
|
31
|
+
analyze_go_config,
|
|
32
|
+
analyze_java_config,
|
|
33
|
+
analyze_javascript_config,
|
|
34
|
+
analyze_python_config,
|
|
35
|
+
analyze_rust_config,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# ///////////////////////////////////////////////////////////////
|
|
39
|
+
# LOGGER SETUP
|
|
40
|
+
# ///////////////////////////////////////////////////////////////
|
|
41
|
+
|
|
42
|
+
logger = logging.getLogger(__name__)
|
|
43
|
+
|
|
44
|
+
# ///////////////////////////////////////////////////////////////
|
|
45
|
+
# PROJECT DETECTION SERVICE CLASS
|
|
46
|
+
# ///////////////////////////////////////////////////////////////
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ProjectDetectionService:
|
|
50
|
+
"""Singleton service for detecting project types and configurations."""
|
|
51
|
+
|
|
52
|
+
_instance: ClassVar[ProjectDetectionService | None] = None
|
|
53
|
+
_initialized: ClassVar[bool] = False
|
|
54
|
+
_lock: ClassVar[Lock] = Lock()
|
|
55
|
+
|
|
56
|
+
def __new__(cls) -> ProjectDetectionService:
|
|
57
|
+
"""Create or return the singleton instance.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
ProjectDetectionService: The singleton instance
|
|
61
|
+
"""
|
|
62
|
+
with cls._lock:
|
|
63
|
+
if cls._instance is None:
|
|
64
|
+
cls._instance = super().__new__(cls)
|
|
65
|
+
return cls._instance
|
|
66
|
+
|
|
67
|
+
def __init__(self) -> None:
|
|
68
|
+
"""Initialize project detection service (only once)."""
|
|
69
|
+
if ProjectDetectionService._initialized:
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
self.logger = logging.getLogger(__name__)
|
|
73
|
+
ProjectDetectionService._initialized = True
|
|
74
|
+
|
|
75
|
+
# ///////////////////////////////////////////////////////////////
|
|
76
|
+
# PUBLIC METHODS
|
|
77
|
+
# ///////////////////////////////////////////////////////////////
|
|
78
|
+
|
|
79
|
+
def detect_project_type(self, project_path: Path) -> ProjectDetectionResult:
|
|
80
|
+
"""Detect the type of project at the given path.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
project_path: Path to the project directory
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
ProjectDetectionResult: Result with detected project type and metadata
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
ProjectServiceError: If validation fails or project detection fails
|
|
90
|
+
"""
|
|
91
|
+
try:
|
|
92
|
+
# Input validation
|
|
93
|
+
if not project_path:
|
|
94
|
+
raise ProjectServiceError(
|
|
95
|
+
operation="detect_project_type",
|
|
96
|
+
reason="Project path cannot be None",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if not project_path.exists():
|
|
100
|
+
raise ProjectServiceError(
|
|
101
|
+
operation="detect_project_type",
|
|
102
|
+
reason="Project path does not exist",
|
|
103
|
+
details=f"Path {project_path} was not found",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if not project_path.is_dir():
|
|
107
|
+
raise ProjectServiceError(
|
|
108
|
+
operation="detect_project_type",
|
|
109
|
+
reason="Project path is not a directory",
|
|
110
|
+
details=f"Path {project_path} is not a directory",
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Analyze project structure
|
|
114
|
+
project_files = list(project_path.iterdir())
|
|
115
|
+
project_dirs = [item for item in project_files if item.is_dir()]
|
|
116
|
+
project_files = [item for item in project_files if item.is_file()]
|
|
117
|
+
|
|
118
|
+
# Check each project type
|
|
119
|
+
detected_type = None
|
|
120
|
+
detected_files_by_type: dict[str, list[str]] = {}
|
|
121
|
+
dir_names = [item.name for item in project_dirs]
|
|
122
|
+
|
|
123
|
+
for project_type, indicators in ProjectConfig.PROJECT_INDICATORS.items():
|
|
124
|
+
matches: list[str] = []
|
|
125
|
+
|
|
126
|
+
for marker in indicators.get("files", []):
|
|
127
|
+
matches.extend(
|
|
128
|
+
item.name for item in project_files if item.match(marker)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
for marker in indicators.get("dirs", []):
|
|
132
|
+
if marker in dir_names:
|
|
133
|
+
matches.append(marker)
|
|
134
|
+
|
|
135
|
+
for ext in indicators.get("extensions", []):
|
|
136
|
+
if any(f.suffix == ext for f in project_files):
|
|
137
|
+
matches.append(ext)
|
|
138
|
+
|
|
139
|
+
if matches:
|
|
140
|
+
detected_files_by_type[project_type] = matches
|
|
141
|
+
if detected_type is None:
|
|
142
|
+
detected_type = project_type
|
|
143
|
+
|
|
144
|
+
# Build result
|
|
145
|
+
return ProjectDetectionResult(
|
|
146
|
+
success=True,
|
|
147
|
+
message="Project type detection completed",
|
|
148
|
+
project_type=detected_type or "unknown",
|
|
149
|
+
confidence=100.0 if detected_type else 0.0,
|
|
150
|
+
detected_files=detected_files_by_type.get(detected_type or "", []),
|
|
151
|
+
configuration_files={},
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
except ProjectServiceError:
|
|
155
|
+
# Re-raise as-is
|
|
156
|
+
raise
|
|
157
|
+
except (OSError, TypeError, ValueError) as e:
|
|
158
|
+
# Wrap unexpected external exceptions
|
|
159
|
+
logger.exception("Unexpected error in detect_project_type")
|
|
160
|
+
raise ProjectServiceError(
|
|
161
|
+
operation="detect_project_type",
|
|
162
|
+
reason=str(e),
|
|
163
|
+
details=f"Exception type: {type(e).__name__}, Project: {project_path}",
|
|
164
|
+
) from e
|
|
165
|
+
|
|
166
|
+
def detect_project_config(self, project_path: Path) -> ProjectDetectionResult:
|
|
167
|
+
"""Detect project configuration files and settings.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
project_path: Path to the project directory
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
ProjectDetectionResult: Result with project configuration information
|
|
174
|
+
|
|
175
|
+
Raises:
|
|
176
|
+
ProjectServiceError: If validation fails or project configuration detection fails
|
|
177
|
+
"""
|
|
178
|
+
try:
|
|
179
|
+
# Input validation
|
|
180
|
+
if not project_path:
|
|
181
|
+
raise ProjectServiceError(
|
|
182
|
+
operation="detect_project_config",
|
|
183
|
+
reason="Project path cannot be None",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
if not project_path.exists():
|
|
187
|
+
raise ProjectServiceError(
|
|
188
|
+
operation="detect_project_config",
|
|
189
|
+
reason="Project path does not exist",
|
|
190
|
+
details=f"Path {project_path} was not found",
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
if not project_path.is_dir():
|
|
194
|
+
raise ProjectServiceError(
|
|
195
|
+
operation="detect_project_config",
|
|
196
|
+
reason="Project path is not a directory",
|
|
197
|
+
details=f"Path {project_path} is not a directory",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
config_files: dict[str, str] = {}
|
|
201
|
+
|
|
202
|
+
# Detect project type first
|
|
203
|
+
type_result = self.detect_project_type(project_path)
|
|
204
|
+
if not type_result.success:
|
|
205
|
+
raise ProjectServiceError(
|
|
206
|
+
operation="detect_project_config",
|
|
207
|
+
reason="Unable to determine project type",
|
|
208
|
+
details="Project type detection failed",
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
project_type = type_result.project_type
|
|
212
|
+
|
|
213
|
+
# Analyze configuration files based on project type
|
|
214
|
+
try:
|
|
215
|
+
config: dict[str, dict[str, str]] = {}
|
|
216
|
+
if project_type == "python":
|
|
217
|
+
config = analyze_python_config(project_path)
|
|
218
|
+
elif project_type == "javascript":
|
|
219
|
+
config = analyze_javascript_config(project_path)
|
|
220
|
+
elif project_type == "java":
|
|
221
|
+
config = analyze_java_config(project_path)
|
|
222
|
+
elif project_type == "go":
|
|
223
|
+
config = analyze_go_config(project_path)
|
|
224
|
+
elif project_type == "rust":
|
|
225
|
+
config = analyze_rust_config(project_path)
|
|
226
|
+
elif project_type == "csharp":
|
|
227
|
+
config = analyze_csharp_config(project_path)
|
|
228
|
+
|
|
229
|
+
for section in ("markers", "details"):
|
|
230
|
+
values = config.get(section, {})
|
|
231
|
+
if isinstance(values, dict):
|
|
232
|
+
config_files.update(values)
|
|
233
|
+
except (OSError, TypeError, ValueError) as e:
|
|
234
|
+
logger.warning(
|
|
235
|
+
f"Failed to analyze configuration for {project_type}: {e}"
|
|
236
|
+
)
|
|
237
|
+
# Continue with partial results
|
|
238
|
+
|
|
239
|
+
return ProjectDetectionResult(
|
|
240
|
+
success=True,
|
|
241
|
+
message="Project configuration detection completed",
|
|
242
|
+
project_type=project_type,
|
|
243
|
+
confidence=100.0 if project_type != "unknown" else 0.0,
|
|
244
|
+
detected_files=[],
|
|
245
|
+
configuration_files=config_files,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
except ProjectServiceError:
|
|
249
|
+
# Re-raise as-is
|
|
250
|
+
raise
|
|
251
|
+
except (OSError, TypeError, ValueError) as e:
|
|
252
|
+
# Wrap unexpected external exceptions
|
|
253
|
+
logger.exception("Unexpected error in detect_project_config")
|
|
254
|
+
raise ProjectServiceError(
|
|
255
|
+
operation="detect_project_config",
|
|
256
|
+
reason=str(e),
|
|
257
|
+
details=f"Exception type: {type(e).__name__}, Project: {project_path}",
|
|
258
|
+
) from e
|
|
259
|
+
|
|
260
|
+
def detect_project_structure(self, project_path: Path) -> ProjectDetectionResult:
|
|
261
|
+
"""Detect project structure and organization.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
project_path: Path to the project directory
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
ProjectDetectionResult: Result with project structure information
|
|
268
|
+
|
|
269
|
+
Raises:
|
|
270
|
+
ProjectServiceError: If validation fails or project structure detection fails
|
|
271
|
+
"""
|
|
272
|
+
try:
|
|
273
|
+
# Input validation
|
|
274
|
+
if not project_path:
|
|
275
|
+
raise ProjectServiceError(
|
|
276
|
+
operation="detect_project_structure",
|
|
277
|
+
reason="Project path cannot be None",
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
if not project_path.exists():
|
|
281
|
+
raise ProjectServiceError(
|
|
282
|
+
operation="detect_project_structure",
|
|
283
|
+
reason="Project path does not exist",
|
|
284
|
+
details=f"Path {project_path} was not found",
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
if not project_path.is_dir():
|
|
288
|
+
raise ProjectServiceError(
|
|
289
|
+
operation="detect_project_structure",
|
|
290
|
+
reason="Project path is not a directory",
|
|
291
|
+
details=f"Path {project_path} is not a directory",
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
source_dirs: list[str] = []
|
|
295
|
+
test_dirs: list[str] = []
|
|
296
|
+
config_dirs: list[str] = []
|
|
297
|
+
build_dirs: list[str] = []
|
|
298
|
+
documentation_dirs: list[str] = []
|
|
299
|
+
total_files = 0
|
|
300
|
+
total_dirs = 0
|
|
301
|
+
|
|
302
|
+
try:
|
|
303
|
+
# Walk through project structure
|
|
304
|
+
for item in project_path.rglob("*"):
|
|
305
|
+
if item.is_file():
|
|
306
|
+
total_files += 1
|
|
307
|
+
elif item.is_dir():
|
|
308
|
+
total_dirs += 1
|
|
309
|
+
name = item.name.lower()
|
|
310
|
+
if name in {"src", "lib", "app", "source"}:
|
|
311
|
+
source_dirs.append(str(item))
|
|
312
|
+
elif name in {"tests", "test", "__tests__"}:
|
|
313
|
+
test_dirs.append(str(item))
|
|
314
|
+
elif name in {"config", ".config", "configs"}:
|
|
315
|
+
config_dirs.append(str(item))
|
|
316
|
+
elif name in {"build", "dist", "target", "out"}:
|
|
317
|
+
build_dirs.append(str(item))
|
|
318
|
+
elif name in {"docs", "doc", "documentation"}:
|
|
319
|
+
documentation_dirs.append(str(item))
|
|
320
|
+
|
|
321
|
+
except (PermissionError, OSError) as e:
|
|
322
|
+
logger.warning(f"Permission or OS error during structure analysis: {e}")
|
|
323
|
+
# Continue with partial results
|
|
324
|
+
|
|
325
|
+
structure = {
|
|
326
|
+
"source_dirs": ", ".join(source_dirs),
|
|
327
|
+
"test_dirs": ", ".join(test_dirs),
|
|
328
|
+
"config_dirs": ", ".join(config_dirs),
|
|
329
|
+
"build_dirs": ", ".join(build_dirs),
|
|
330
|
+
"documentation_dirs": ", ".join(documentation_dirs),
|
|
331
|
+
"total_files": str(total_files),
|
|
332
|
+
"total_dirs": str(total_dirs),
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return ProjectDetectionResult(
|
|
336
|
+
success=True,
|
|
337
|
+
message="Project structure detection completed",
|
|
338
|
+
project_type="",
|
|
339
|
+
confidence=100.0,
|
|
340
|
+
detected_files=[],
|
|
341
|
+
configuration_files=structure,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
except ProjectServiceError:
|
|
345
|
+
# Re-raise as-is
|
|
346
|
+
raise
|
|
347
|
+
except (OSError, TypeError, ValueError) as e:
|
|
348
|
+
# Wrap unexpected external exceptions
|
|
349
|
+
logger.exception("Unexpected error in detect_project_structure")
|
|
350
|
+
raise ProjectServiceError(
|
|
351
|
+
operation="detect_project_structure",
|
|
352
|
+
reason=str(e),
|
|
353
|
+
details=f"Exception type: {type(e).__name__}, Project: {project_path}",
|
|
354
|
+
) from e
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PROJECT ENV UTILS - Environment Setup Utilities
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure utility functions for setting up project environments.
|
|
9
|
+
|
|
10
|
+
This module provides stateless functions for:
|
|
11
|
+
- Python virtual environment creation and management
|
|
12
|
+
- npm project initialization
|
|
13
|
+
- Dependency installation (pip, npm)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# IMPORTS
|
|
20
|
+
# ///////////////////////////////////////////////////////////////
|
|
21
|
+
# Standard library imports
|
|
22
|
+
import logging
|
|
23
|
+
import shutil
|
|
24
|
+
import tomllib
|
|
25
|
+
import venv
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
# Local imports
|
|
29
|
+
from ...shared.configs.project import PythonProjectConfig
|
|
30
|
+
from ...utils.project.validation_utils import validate_project_path
|
|
31
|
+
from ..common.command_runner_service import CommandRunnerService
|
|
32
|
+
|
|
33
|
+
# ///////////////////////////////////////////////////////////////
|
|
34
|
+
# LOGGER SETUP
|
|
35
|
+
# ///////////////////////////////////////////////////////////////
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
# ///////////////////////////////////////////////////////////////
|
|
40
|
+
# PYTHON ENVIRONMENT FUNCTIONS
|
|
41
|
+
# ///////////////////////////////////////////////////////////////
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_virtual_environment_path(project_path: Path) -> Path:
|
|
45
|
+
"""Use the default environment, reusing a legacy environment when present."""
|
|
46
|
+
default = project_path / PythonProjectConfig.VENV_DIR
|
|
47
|
+
legacy = project_path / PythonProjectConfig.ALT_VENV_DIR
|
|
48
|
+
return legacy if not default.exists() and legacy.is_dir() else default
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def create_virtual_environment(
|
|
52
|
+
project_path: Path, venv_name: str | None = None
|
|
53
|
+
) -> dict[str, str | bool]:
|
|
54
|
+
"""Create a Python virtual environment.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
project_path: Path to the project
|
|
58
|
+
venv_name: Venv directory name; defaults to .venv, reusing legacy venv.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
dict: Metadata with 'success', 'venv_path', and 'existing' keys
|
|
62
|
+
|
|
63
|
+
Raises:
|
|
64
|
+
ValueError: If validation fails
|
|
65
|
+
OSError: If venv creation fails
|
|
66
|
+
"""
|
|
67
|
+
validate_project_path(project_path, must_exist=True, require_empty=False)
|
|
68
|
+
|
|
69
|
+
venv_path = (
|
|
70
|
+
project_path / venv_name
|
|
71
|
+
if venv_name
|
|
72
|
+
else get_virtual_environment_path(project_path)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if venv_path.exists():
|
|
76
|
+
logger.info(f"Virtual environment already exists at {venv_path}")
|
|
77
|
+
return {
|
|
78
|
+
"success": True,
|
|
79
|
+
"venv_path": str(venv_path),
|
|
80
|
+
"existing": True,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# Create virtual environment
|
|
84
|
+
venv.create(venv_path, with_pip=True)
|
|
85
|
+
logger.info(f"Created virtual environment at {venv_path}")
|
|
86
|
+
|
|
87
|
+
# Upgrade pip
|
|
88
|
+
_upgrade_pip(project_path, venv_path)
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
"success": True,
|
|
92
|
+
"venv_path": str(venv_path),
|
|
93
|
+
"existing": False,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _upgrade_pip(project_path: Path, venv_path: Path) -> None:
|
|
98
|
+
"""Upgrade pip in the virtual environment.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
project_path: Path to the project
|
|
102
|
+
venv_path: Path to the virtual environment
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
# Find Python and pip executables
|
|
106
|
+
python_exe = _find_venv_executable(venv_path, "python")
|
|
107
|
+
pip_exe = _find_venv_executable(venv_path, "pip")
|
|
108
|
+
|
|
109
|
+
if python_exe and pip_exe:
|
|
110
|
+
command_runner = CommandRunnerService()
|
|
111
|
+
result = command_runner.run(
|
|
112
|
+
[str(python_exe), "-m", "pip", "install", "--upgrade", "pip"],
|
|
113
|
+
cwd=str(project_path),
|
|
114
|
+
)
|
|
115
|
+
if not result: # Uses __bool__() which checks returncode == 0
|
|
116
|
+
logger.warning(f"Failed to upgrade pip: {result.stderr}")
|
|
117
|
+
else:
|
|
118
|
+
logger.debug("Successfully upgraded pip")
|
|
119
|
+
except Exception as e:
|
|
120
|
+
logger.warning(f"Error upgrading pip: {e}")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _find_venv_executable(venv_path: Path, name: str) -> Path | None:
|
|
124
|
+
"""Find an executable in the virtual environment.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
venv_path: Path to the virtual environment
|
|
128
|
+
name: Name of the executable (python, pip, etc.)
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Path | None: Path to the executable or None if not found
|
|
132
|
+
"""
|
|
133
|
+
# Windows paths
|
|
134
|
+
windows_paths = [
|
|
135
|
+
venv_path / "Scripts" / f"{name}.exe",
|
|
136
|
+
venv_path / "Scripts" / f"{name}3.exe",
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
# Unix paths
|
|
140
|
+
unix_paths = [
|
|
141
|
+
venv_path / "bin" / name,
|
|
142
|
+
venv_path / "bin" / f"{name}3",
|
|
143
|
+
]
|
|
144
|
+
|
|
145
|
+
# Try Windows paths first (if drive exists, it's Windows)
|
|
146
|
+
if venv_path.drive:
|
|
147
|
+
for path in windows_paths:
|
|
148
|
+
if path.exists():
|
|
149
|
+
return path
|
|
150
|
+
|
|
151
|
+
# Try Unix paths
|
|
152
|
+
for path in unix_paths:
|
|
153
|
+
if path.exists():
|
|
154
|
+
return path
|
|
155
|
+
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def find_pip_executable(venv_path: Path) -> Path:
|
|
160
|
+
"""Find pip executable in virtual environment.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
venv_path: Path to the virtual environment
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Path: Path to pip executable
|
|
167
|
+
|
|
168
|
+
Raises:
|
|
169
|
+
FileNotFoundError: If pip executable not found
|
|
170
|
+
"""
|
|
171
|
+
pip_exe = _find_venv_executable(venv_path, "pip")
|
|
172
|
+
if not pip_exe:
|
|
173
|
+
raise FileNotFoundError("pip not found in virtual environment")
|
|
174
|
+
return pip_exe
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def install_python_dependencies(
|
|
178
|
+
project_path: Path, requirements_file: str = "requirements-dev.txt"
|
|
179
|
+
) -> bool:
|
|
180
|
+
"""Install Python dependencies from requirements file or pyproject.toml.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
project_path: Path to the project
|
|
184
|
+
requirements_file: Name of the requirements file
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
bool: True if installation succeeded
|
|
188
|
+
|
|
189
|
+
Raises:
|
|
190
|
+
ValueError: If validation fails
|
|
191
|
+
FileNotFoundError: If the virtual environment is missing
|
|
192
|
+
RuntimeError: If the pip install command fails
|
|
193
|
+
"""
|
|
194
|
+
validate_project_path(project_path, must_exist=True, require_empty=False)
|
|
195
|
+
|
|
196
|
+
venv_path = get_virtual_environment_path(project_path)
|
|
197
|
+
if not venv_path.exists():
|
|
198
|
+
raise FileNotFoundError("Virtual environment not found")
|
|
199
|
+
|
|
200
|
+
# Find pip executable
|
|
201
|
+
pip_exe = find_pip_executable(venv_path)
|
|
202
|
+
|
|
203
|
+
command_runner = CommandRunnerService()
|
|
204
|
+
|
|
205
|
+
# Install dependencies from the legacy requirements file when available.
|
|
206
|
+
req_file = project_path / requirements_file
|
|
207
|
+
if req_file.exists():
|
|
208
|
+
commands = [[str(pip_exe), "install", "-r", requirements_file]]
|
|
209
|
+
else:
|
|
210
|
+
pyproject_file = project_path / PythonProjectConfig.PYPROJECT_FILE
|
|
211
|
+
if not pyproject_file.exists():
|
|
212
|
+
logger.warning(f"Requirements file {requirements_file} not found, skipping")
|
|
213
|
+
return True
|
|
214
|
+
|
|
215
|
+
with pyproject_file.open("rb") as file:
|
|
216
|
+
pyproject = tomllib.load(file)
|
|
217
|
+
|
|
218
|
+
commands = []
|
|
219
|
+
if "project" in pyproject:
|
|
220
|
+
commands.append([str(pip_exe), "install", "."])
|
|
221
|
+
if "dev" in pyproject.get("dependency-groups", {}):
|
|
222
|
+
commands.append([str(pip_exe), "install", "--group", "dev"])
|
|
223
|
+
|
|
224
|
+
for command in commands:
|
|
225
|
+
result = command_runner.run(command, cwd=str(project_path))
|
|
226
|
+
if not result:
|
|
227
|
+
raise RuntimeError(f"Failed to install dependencies: {result.stderr}")
|
|
228
|
+
|
|
229
|
+
if req_file.exists():
|
|
230
|
+
logger.info(f"Successfully installed dependencies from {requirements_file}")
|
|
231
|
+
else:
|
|
232
|
+
logger.info("Successfully installed dependencies from pyproject.toml")
|
|
233
|
+
return True
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
# ///////////////////////////////////////////////////////////////
|
|
237
|
+
# JAVASCRIPT ENVIRONMENT FUNCTIONS
|
|
238
|
+
# ///////////////////////////////////////////////////////////////
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def check_npm_available() -> bool:
|
|
242
|
+
"""Check if npm is available in PATH.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
bool: True if npm is available
|
|
246
|
+
"""
|
|
247
|
+
return shutil.which("npm") is not None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def install_npm_dependencies(project_path: Path) -> bool:
|
|
251
|
+
"""Install npm dependencies.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
project_path: Path to the project
|
|
255
|
+
|
|
256
|
+
Returns:
|
|
257
|
+
bool: True if installation succeeded
|
|
258
|
+
|
|
259
|
+
Raises:
|
|
260
|
+
ValueError: If validation fails
|
|
261
|
+
FileNotFoundError: If npm is not installed or not in PATH
|
|
262
|
+
RuntimeError: If the npm install command fails
|
|
263
|
+
"""
|
|
264
|
+
validate_project_path(project_path, must_exist=True, require_empty=False)
|
|
265
|
+
|
|
266
|
+
if not check_npm_available():
|
|
267
|
+
raise FileNotFoundError("npm is not installed or not in PATH")
|
|
268
|
+
|
|
269
|
+
# Install dependencies
|
|
270
|
+
command_runner = CommandRunnerService()
|
|
271
|
+
result = command_runner.run(
|
|
272
|
+
["npm", "install"],
|
|
273
|
+
cwd=str(project_path),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
if not result:
|
|
277
|
+
raise RuntimeError(f"Failed to install dependencies: {result.stderr}")
|
|
278
|
+
|
|
279
|
+
logger.info("Successfully installed npm dependencies")
|
|
280
|
+
return True
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def install_npm_dev_dependencies(project_path: Path, dependencies: list[str]) -> bool:
|
|
284
|
+
"""Install npm development dependencies.
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
project_path: Path to the project
|
|
288
|
+
dependencies: List of package names to install
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
bool: True if installation succeeded
|
|
292
|
+
|
|
293
|
+
Raises:
|
|
294
|
+
ValueError: If validation fails
|
|
295
|
+
FileNotFoundError: If npm is not installed or not in PATH
|
|
296
|
+
RuntimeError: If the npm install command fails
|
|
297
|
+
"""
|
|
298
|
+
validate_project_path(project_path, must_exist=True, require_empty=False)
|
|
299
|
+
|
|
300
|
+
if not check_npm_available():
|
|
301
|
+
raise FileNotFoundError("npm is not installed or not in PATH")
|
|
302
|
+
|
|
303
|
+
if not dependencies:
|
|
304
|
+
logger.info("No dev dependencies to install")
|
|
305
|
+
return True
|
|
306
|
+
|
|
307
|
+
# Install dev dependencies
|
|
308
|
+
command_runner = CommandRunnerService()
|
|
309
|
+
result = command_runner.run(
|
|
310
|
+
["npm", "install", "--save-dev", *dependencies],
|
|
311
|
+
cwd=str(project_path),
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
if not result:
|
|
315
|
+
raise RuntimeError(f"Failed to install development tools: {result.stderr}")
|
|
316
|
+
|
|
317
|
+
logger.info(f"Successfully installed {len(dependencies)} dev dependencies")
|
|
318
|
+
return True
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
# ///////////////////////////////////////////////////////////////
|
|
322
|
+
# PUBLIC API
|
|
323
|
+
# ///////////////////////////////////////////////////////////////
|
|
324
|
+
|
|
325
|
+
__all__ = [
|
|
326
|
+
"check_npm_available",
|
|
327
|
+
"create_virtual_environment",
|
|
328
|
+
"find_pip_executable",
|
|
329
|
+
"get_virtual_environment_path",
|
|
330
|
+
"install_npm_dependencies",
|
|
331
|
+
"install_npm_dev_dependencies",
|
|
332
|
+
"install_python_dependencies",
|
|
333
|
+
]
|