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,418 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# PROJECT VALIDATION SERVICE - Project Validation Service
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Project Validation Service - Singleton service for project validation.
|
|
9
|
+
|
|
10
|
+
Validates project names, paths, and configurations.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
# ///////////////////////////////////////////////////////////////
|
|
16
|
+
# IMPORTS
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# Standard library imports
|
|
19
|
+
import logging
|
|
20
|
+
import re
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from threading import Lock
|
|
23
|
+
from typing import ClassVar
|
|
24
|
+
|
|
25
|
+
# Local imports
|
|
26
|
+
from ...exceptions.common import ValidationServiceError
|
|
27
|
+
from ...exceptions.project import ProjectServiceError
|
|
28
|
+
from ...shared.configs.project import ProjectConfig
|
|
29
|
+
from ...utils.project import suggest_project_name
|
|
30
|
+
from .setup_profile_resolver import resolve_setup_profile
|
|
31
|
+
|
|
32
|
+
# ///////////////////////////////////////////////////////////////
|
|
33
|
+
# LOGGER SETUP
|
|
34
|
+
# ///////////////////////////////////////////////////////////////
|
|
35
|
+
|
|
36
|
+
logger = logging.getLogger(__name__)
|
|
37
|
+
|
|
38
|
+
# ///////////////////////////////////////////////////////////////
|
|
39
|
+
# PROJECT VALIDATION SERVICE CLASS
|
|
40
|
+
# ///////////////////////////////////////////////////////////////
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ProjectValidationService:
|
|
44
|
+
"""Singleton service for project validation utilities."""
|
|
45
|
+
|
|
46
|
+
_instance: ClassVar[ProjectValidationService | None] = None
|
|
47
|
+
_initialized: ClassVar[bool] = False
|
|
48
|
+
_lock: ClassVar[Lock] = Lock()
|
|
49
|
+
|
|
50
|
+
def __new__(cls) -> ProjectValidationService:
|
|
51
|
+
"""Create or return the singleton instance.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
ProjectValidationService: The singleton instance
|
|
55
|
+
"""
|
|
56
|
+
with cls._lock:
|
|
57
|
+
if cls._instance is None:
|
|
58
|
+
cls._instance = super().__new__(cls)
|
|
59
|
+
return cls._instance
|
|
60
|
+
|
|
61
|
+
def __init__(self) -> None:
|
|
62
|
+
"""Initialize project validation service (only once)."""
|
|
63
|
+
if ProjectValidationService._initialized:
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
self.logger = logging.getLogger(__name__)
|
|
67
|
+
ProjectValidationService._initialized = True
|
|
68
|
+
|
|
69
|
+
# ///////////////////////////////////////////////////////////////
|
|
70
|
+
# PUBLIC METHODS
|
|
71
|
+
# ///////////////////////////////////////////////////////////////
|
|
72
|
+
|
|
73
|
+
def validate_project_name(self, project_name: str) -> None:
|
|
74
|
+
"""Validate a project name.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
project_name: Name to validate
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ProjectValidationError: If project name is invalid
|
|
81
|
+
"""
|
|
82
|
+
try:
|
|
83
|
+
if not project_name:
|
|
84
|
+
raise ValidationServiceError(
|
|
85
|
+
operation="validate_project_name",
|
|
86
|
+
field="project_name",
|
|
87
|
+
reason="Project name cannot be empty",
|
|
88
|
+
details="Empty or None project name provided",
|
|
89
|
+
value=project_name or "None",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if len(project_name) > ProjectConfig.MAX_PROJECT_NAME_LENGTH:
|
|
93
|
+
raise ValidationServiceError(
|
|
94
|
+
operation="validate_project_name",
|
|
95
|
+
field="project_name",
|
|
96
|
+
reason=(
|
|
97
|
+
f"Project name is too long (max {ProjectConfig.MAX_PROJECT_NAME_LENGTH} characters)"
|
|
98
|
+
),
|
|
99
|
+
details=(
|
|
100
|
+
f"Length: {len(project_name)}, Max: {ProjectConfig.MAX_PROJECT_NAME_LENGTH}"
|
|
101
|
+
),
|
|
102
|
+
value=project_name,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if project_name.startswith(".") or project_name.endswith("."):
|
|
106
|
+
raise ValidationServiceError(
|
|
107
|
+
operation="validate_project_name",
|
|
108
|
+
field="project_name",
|
|
109
|
+
reason="Project name cannot start or end with a dot",
|
|
110
|
+
details="Project names must not begin or end with '.'",
|
|
111
|
+
value=project_name,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
if re.search(ProjectConfig.INVALID_CHARS, project_name):
|
|
115
|
+
raise ValidationServiceError(
|
|
116
|
+
operation="validate_project_name",
|
|
117
|
+
field="project_name",
|
|
118
|
+
reason=(
|
|
119
|
+
f"Project name contains invalid characters: {ProjectConfig.INVALID_CHARS}"
|
|
120
|
+
),
|
|
121
|
+
details="Invalid characters detected in project name",
|
|
122
|
+
value=project_name,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
if project_name.upper() in ProjectConfig.RESERVED_NAMES:
|
|
126
|
+
raise ValidationServiceError(
|
|
127
|
+
operation="validate_project_name",
|
|
128
|
+
field="project_name",
|
|
129
|
+
reason=f"Project name '{project_name}' is reserved on Windows",
|
|
130
|
+
details=f"Reserved name: {project_name.upper()}",
|
|
131
|
+
value=project_name,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if not re.match(r"^[a-zA-Z0-9._-]+$", project_name):
|
|
135
|
+
raise ValidationServiceError(
|
|
136
|
+
operation="validate_project_name",
|
|
137
|
+
field="project_name",
|
|
138
|
+
reason=(
|
|
139
|
+
"Project name can only contain letters, numbers, dots, underscores, and hyphens"
|
|
140
|
+
),
|
|
141
|
+
details="Invalid character pattern detected",
|
|
142
|
+
value=project_name,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
except ValidationServiceError:
|
|
146
|
+
# Re-raise specialized exceptions as-is
|
|
147
|
+
raise
|
|
148
|
+
except Exception as e:
|
|
149
|
+
# Wrap unexpected external exceptions
|
|
150
|
+
raise ProjectServiceError(
|
|
151
|
+
operation="validate_project_name",
|
|
152
|
+
reason=str(e),
|
|
153
|
+
details=f"Exception type: {type(e).__name__}, Project name: {project_name}",
|
|
154
|
+
) from e
|
|
155
|
+
|
|
156
|
+
def validate_project_path(self, project_path: Path) -> None:
|
|
157
|
+
"""Validate a project path.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
project_path: Path to validate
|
|
161
|
+
|
|
162
|
+
Raises:
|
|
163
|
+
ProjectValidationError: If project path is invalid
|
|
164
|
+
"""
|
|
165
|
+
try:
|
|
166
|
+
if not project_path:
|
|
167
|
+
raise ValidationServiceError(
|
|
168
|
+
operation="validate_project_path",
|
|
169
|
+
field="project_path",
|
|
170
|
+
reason="Project path cannot be None",
|
|
171
|
+
details="Empty or None project path provided",
|
|
172
|
+
value="None",
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Check if path is absolute
|
|
176
|
+
if not project_path.is_absolute():
|
|
177
|
+
project_path = project_path.resolve()
|
|
178
|
+
|
|
179
|
+
# Check if parent directory exists and is writable
|
|
180
|
+
parent_dir = project_path.parent
|
|
181
|
+
if not parent_dir.exists():
|
|
182
|
+
raise ValidationServiceError(
|
|
183
|
+
operation="validate_project_path",
|
|
184
|
+
field="project_path",
|
|
185
|
+
reason="Parent directory does not exist",
|
|
186
|
+
details=f"Parent directory: {parent_dir}",
|
|
187
|
+
value=str(project_path),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if not parent_dir.is_dir():
|
|
191
|
+
raise ValidationServiceError(
|
|
192
|
+
operation="validate_project_path",
|
|
193
|
+
field="project_path",
|
|
194
|
+
reason="Parent path is not a directory",
|
|
195
|
+
details=f"Parent path: {parent_dir}",
|
|
196
|
+
value=str(project_path),
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Check if we can write to parent directory
|
|
200
|
+
try:
|
|
201
|
+
test_file = parent_dir / ".womm_test_write"
|
|
202
|
+
test_file.touch()
|
|
203
|
+
test_file.unlink()
|
|
204
|
+
except (PermissionError, OSError) as e:
|
|
205
|
+
raise ValidationServiceError(
|
|
206
|
+
operation="validate_project_path",
|
|
207
|
+
field="project_path",
|
|
208
|
+
reason="Cannot write to directory",
|
|
209
|
+
details=f"Parent directory: {parent_dir}, Error: {e}",
|
|
210
|
+
value=str(project_path),
|
|
211
|
+
) from e
|
|
212
|
+
|
|
213
|
+
# Check if project directory already exists
|
|
214
|
+
if project_path.exists():
|
|
215
|
+
if not project_path.is_dir():
|
|
216
|
+
raise ValidationServiceError(
|
|
217
|
+
operation="validate_project_path",
|
|
218
|
+
field="project_path",
|
|
219
|
+
reason="Path exists but is not a directory",
|
|
220
|
+
details=f"Path: {project_path}",
|
|
221
|
+
value=str(project_path),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
# Check if directory is empty
|
|
225
|
+
try:
|
|
226
|
+
if any(project_path.iterdir()):
|
|
227
|
+
raise ValidationServiceError(
|
|
228
|
+
operation="validate_project_path",
|
|
229
|
+
field="project_path",
|
|
230
|
+
reason="Directory is not empty",
|
|
231
|
+
details=f"Directory: {project_path}",
|
|
232
|
+
value=str(project_path),
|
|
233
|
+
)
|
|
234
|
+
except PermissionError as e:
|
|
235
|
+
raise ValidationServiceError(
|
|
236
|
+
operation="validate_project_path",
|
|
237
|
+
field="project_path",
|
|
238
|
+
reason="Cannot access directory",
|
|
239
|
+
details=f"Directory: {project_path}, Error: {e}",
|
|
240
|
+
value=str(project_path),
|
|
241
|
+
) from e
|
|
242
|
+
|
|
243
|
+
except (ValidationServiceError, ProjectServiceError):
|
|
244
|
+
# Re-raise specialized exceptions as-is
|
|
245
|
+
raise
|
|
246
|
+
except Exception as e:
|
|
247
|
+
# Wrap unexpected external exceptions
|
|
248
|
+
raise ProjectServiceError(
|
|
249
|
+
operation="validate_project_path",
|
|
250
|
+
reason=str(e),
|
|
251
|
+
details=f"Exception type: {type(e).__name__}, Project path: {project_path}",
|
|
252
|
+
) from e
|
|
253
|
+
|
|
254
|
+
def validate_project_type(self, project_type: str) -> None:
|
|
255
|
+
"""Validate a project type.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
project_type: Type to validate
|
|
259
|
+
|
|
260
|
+
Raises:
|
|
261
|
+
ProjectValidationError: If project type is invalid
|
|
262
|
+
"""
|
|
263
|
+
try:
|
|
264
|
+
if not project_type:
|
|
265
|
+
raise ValidationServiceError(
|
|
266
|
+
operation="validate_project_type",
|
|
267
|
+
field="project_type",
|
|
268
|
+
reason="Project type cannot be empty",
|
|
269
|
+
details="Empty or None project type provided",
|
|
270
|
+
value=project_type or "None",
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
if resolve_setup_profile(project_type) is None:
|
|
274
|
+
raise ValidationServiceError(
|
|
275
|
+
operation="validate_project_type",
|
|
276
|
+
field="project_type",
|
|
277
|
+
reason=f"Unsupported project type: {project_type}",
|
|
278
|
+
details="Run 'womm setup detect --help' to see known types.",
|
|
279
|
+
value=project_type,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
except ValidationServiceError:
|
|
283
|
+
# Re-raise specialized exceptions as-is
|
|
284
|
+
raise
|
|
285
|
+
except Exception as e:
|
|
286
|
+
# Wrap unexpected external exceptions
|
|
287
|
+
raise ProjectServiceError(
|
|
288
|
+
operation="validate_project_type",
|
|
289
|
+
reason=str(e),
|
|
290
|
+
details=f"Exception type: {type(e).__name__}, Project type: {project_type}",
|
|
291
|
+
) from e
|
|
292
|
+
|
|
293
|
+
def validate_project_config(self, config: dict[str, str]) -> None:
|
|
294
|
+
"""Validate a project configuration.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
config: Configuration dictionary to validate
|
|
298
|
+
|
|
299
|
+
Raises:
|
|
300
|
+
ProjectValidationError: If project configuration is invalid
|
|
301
|
+
"""
|
|
302
|
+
try:
|
|
303
|
+
if not config:
|
|
304
|
+
raise ValidationServiceError(
|
|
305
|
+
operation="validate_project_config",
|
|
306
|
+
field="project_config",
|
|
307
|
+
reason="Project configuration cannot be None",
|
|
308
|
+
details="Empty or None configuration provided",
|
|
309
|
+
value="None",
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
required_fields = ["project_name", "project_type"]
|
|
313
|
+
|
|
314
|
+
for field in required_fields:
|
|
315
|
+
if field not in config:
|
|
316
|
+
raise ValidationServiceError(
|
|
317
|
+
operation="validate_project_config",
|
|
318
|
+
field=field,
|
|
319
|
+
reason=f"Missing required field: {field}",
|
|
320
|
+
details=f"Required fields: {', '.join(required_fields)}",
|
|
321
|
+
value=str(config),
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
# Validate individual fields
|
|
325
|
+
self.validate_project_name(config["project_name"])
|
|
326
|
+
self.validate_project_type(config["project_type"])
|
|
327
|
+
|
|
328
|
+
except (ValidationServiceError, ProjectServiceError):
|
|
329
|
+
# Re-raise specialized exceptions as-is
|
|
330
|
+
raise
|
|
331
|
+
except Exception as e:
|
|
332
|
+
# Wrap unexpected external exceptions
|
|
333
|
+
raise ProjectServiceError(
|
|
334
|
+
operation="validate_project_config",
|
|
335
|
+
reason=str(e),
|
|
336
|
+
details=f"Exception type: {type(e).__name__}, Config: {config}",
|
|
337
|
+
) from e
|
|
338
|
+
|
|
339
|
+
def suggest_project_name(self, base_name: str) -> str:
|
|
340
|
+
"""Suggest a valid project name based on input.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
base_name: Base name to suggest from
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
str: Valid project name suggestion
|
|
347
|
+
|
|
348
|
+
Raises:
|
|
349
|
+
ProjectServiceError: If project name suggestion fails
|
|
350
|
+
"""
|
|
351
|
+
return suggest_project_name(base_name)
|
|
352
|
+
|
|
353
|
+
def check_project_name(self, project_name: str) -> tuple[bool, str | None]:
|
|
354
|
+
"""Check if a project name is valid (non-raising version for UI).
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
project_name: Name to check
|
|
358
|
+
|
|
359
|
+
Returns:
|
|
360
|
+
tuple[bool, str | None]: (is_valid, error_message)
|
|
361
|
+
"""
|
|
362
|
+
try:
|
|
363
|
+
self.validate_project_name(project_name)
|
|
364
|
+
return (True, None)
|
|
365
|
+
except ValidationServiceError as e:
|
|
366
|
+
return (False, str(e))
|
|
367
|
+
except Exception as e:
|
|
368
|
+
return (False, f"Unexpected error: {e}")
|
|
369
|
+
|
|
370
|
+
def get_validation_summary(
|
|
371
|
+
self, project_name: str, project_path: Path, project_type: str
|
|
372
|
+
) -> dict[str, bool]:
|
|
373
|
+
"""Get validation summary for all project components.
|
|
374
|
+
|
|
375
|
+
Args:
|
|
376
|
+
project_name: Project name to validate
|
|
377
|
+
project_path: Project path to validate
|
|
378
|
+
project_type: Project type to validate
|
|
379
|
+
|
|
380
|
+
Returns:
|
|
381
|
+
dict[str, bool]: Validation results for each component
|
|
382
|
+
|
|
383
|
+
Raises:
|
|
384
|
+
ProjectServiceError: If validation summary generation fails
|
|
385
|
+
"""
|
|
386
|
+
try:
|
|
387
|
+
summary = {
|
|
388
|
+
"project_name": True,
|
|
389
|
+
"project_path": True,
|
|
390
|
+
"project_type": True,
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
# Validate project name
|
|
394
|
+
try:
|
|
395
|
+
self.validate_project_name(project_name)
|
|
396
|
+
except ValidationServiceError:
|
|
397
|
+
summary["project_name"] = False
|
|
398
|
+
|
|
399
|
+
# Validate project path
|
|
400
|
+
try:
|
|
401
|
+
self.validate_project_path(project_path)
|
|
402
|
+
except ValidationServiceError:
|
|
403
|
+
summary["project_path"] = False
|
|
404
|
+
|
|
405
|
+
# Validate project type
|
|
406
|
+
try:
|
|
407
|
+
self.validate_project_type(project_type)
|
|
408
|
+
except ValidationServiceError:
|
|
409
|
+
summary["project_type"] = False
|
|
410
|
+
|
|
411
|
+
return summary
|
|
412
|
+
|
|
413
|
+
except Exception as e:
|
|
414
|
+
raise ProjectServiceError(
|
|
415
|
+
operation="get_validation_summary",
|
|
416
|
+
reason=str(e),
|
|
417
|
+
details=f"Exception type: {type(e).__name__}",
|
|
418
|
+
) from e
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SERVICES SYSTEM - System Services
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
System services for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This package contains services for system management operations including
|
|
11
|
+
system detection, PATH management, and environment operations.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Local imports
|
|
20
|
+
from .detector_service import SystemDetectorService
|
|
21
|
+
from .environment_service import SystemEnvironmentService
|
|
22
|
+
from .path_service import SystemPathService
|
|
23
|
+
|
|
24
|
+
# ///////////////////////////////////////////////////////////////
|
|
25
|
+
# PUBLIC API
|
|
26
|
+
# ///////////////////////////////////////////////////////////////
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"SystemDetectorService",
|
|
30
|
+
"SystemEnvironmentService",
|
|
31
|
+
"SystemPathService",
|
|
32
|
+
]
|