womm-cli 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. womm/__init__.py +53 -0
  2. womm/__main__.py +48 -0
  3. womm/_version.py +10 -0
  4. womm/assets/copier/meta/copier.yml +15 -0
  5. womm/assets/copier/meta/template/README.md.jinja +32 -0
  6. womm/assets/copier/meta/template/copier.yml.jinja +13 -0
  7. womm/assets/copier/meta/template/template/.gitkeep +0 -0
  8. womm/assets/copier/official/javascript/copier.yml +104 -0
  9. womm/assets/copier/official/javascript/template/.gitignore.jinja +35 -0
  10. womm/assets/copier/official/javascript/template/.nvmrc.jinja +1 -0
  11. womm/assets/copier/official/javascript/template/.prettierignore.jinja +10 -0
  12. womm/assets/copier/official/javascript/template/README.md.jinja +81 -0
  13. womm/assets/copier/official/javascript/template/biome.json.jinja +54 -0
  14. womm/assets/copier/official/javascript/template/eslint.config.mjs.jinja +51 -0
  15. womm/assets/copier/official/javascript/template/index.html.jinja +12 -0
  16. womm/assets/copier/official/javascript/template/package.json.jinja +88 -0
  17. womm/assets/copier/official/javascript/template/prettier.config.mjs.jinja +8 -0
  18. womm/assets/copier/official/javascript/template/src/App.jsx.jinja +10 -0
  19. womm/assets/copier/official/javascript/template/src/App.tsx.jinja +10 -0
  20. womm/assets/copier/official/javascript/template/src/App.vue.jinja +18 -0
  21. womm/assets/copier/official/javascript/template/src/index.jsx.jinja +10 -0
  22. womm/assets/copier/official/javascript/template/src/index.tsx.jinja +11 -0
  23. womm/assets/copier/official/javascript/template/src/main.js.jinja +21 -0
  24. womm/assets/copier/official/javascript/template/src/main.ts.jinja +21 -0
  25. womm/assets/copier/official/javascript/template/tsconfig.json.jinja +35 -0
  26. womm/assets/copier/official/javascript/template/vite.config.mjs.jinja +10 -0
  27. womm/assets/copier/official/javascript/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +63 -0
  28. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.js.jinja +12 -0
  29. womm/assets/copier/official/javascript/template/{% if with_tests %}tests{% endif %}/smoke.test.ts.jinja +12 -0
  30. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +4 -0
  31. womm/assets/copier/official/javascript/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +27 -0
  32. womm/assets/copier/official/python/copier.yml +107 -0
  33. womm/assets/copier/official/python/template/.gitignore.jinja +40 -0
  34. womm/assets/copier/official/python/template/.pre-commit-config.yaml.jinja +19 -0
  35. womm/assets/copier/official/python/template/.python-version.jinja +1 -0
  36. womm/assets/copier/official/python/template/README.md.jinja +83 -0
  37. womm/assets/copier/official/python/template/pyproject.toml.jinja +114 -0
  38. womm/assets/copier/official/python/template/{% if framework == 'django' %}manage.py{% endif %}.jinja +23 -0
  39. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/__init__.py.jinja +3 -0
  40. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/asgi.py.jinja +9 -0
  41. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/__init__.py.jinja +0 -0
  42. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/apps.py.jinja +10 -0
  43. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/models.py.jinja +1 -0
  44. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/core/views.py.jinja +8 -0
  45. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/py.typed +0 -0
  46. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/settings.py.jinja +81 -0
  47. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/urls.py.jinja +11 -0
  48. womm/assets/copier/official/python/template/{% if not use_src_layout %}{{ package_name }}{% endif %}/wsgi.py.jinja +9 -0
  49. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/__init__.py.jinja +3 -0
  50. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/asgi.py.jinja +9 -0
  51. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/__init__.py.jinja +0 -0
  52. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/apps.py.jinja +10 -0
  53. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/models.py.jinja +1 -0
  54. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/core/views.py.jinja +8 -0
  55. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/py.typed +0 -0
  56. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/settings.py.jinja +81 -0
  57. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/urls.py.jinja +11 -0
  58. womm/assets/copier/official/python/template/{% if use_src_layout %}src{% endif %}/{{ package_name }}/wsgi.py.jinja +9 -0
  59. womm/assets/copier/official/python/template/{% if with_ci %}.github{% endif %}/workflows/ci.yml.jinja +78 -0
  60. womm/assets/copier/official/python/template/{% if with_tests %}tests{% endif %}/test_smoke.py.jinja +16 -0
  61. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/extensions.json.jinja +8 -0
  62. womm/assets/copier/official/python/template/{% if with_vscode %}.vscode{% endif %}/settings.json.jinja +28 -0
  63. womm/bin/refresh_env.cmd +130 -0
  64. womm/cli.py +111 -0
  65. womm/commands/__init__.py +30 -0
  66. womm/commands/core/__init__.py +29 -0
  67. womm/commands/core/doctor.py +52 -0
  68. womm/commands/core/path.py +337 -0
  69. womm/commands/project/__init__.py +31 -0
  70. womm/commands/project/create.py +128 -0
  71. womm/commands/project/setup.py +438 -0
  72. womm/commands/project/template.py +160 -0
  73. womm/commands/system/__init__.py +31 -0
  74. womm/commands/system/context/__init__.py +82 -0
  75. womm/commands/system/context/backup.py +344 -0
  76. womm/commands/system/context/inventory.py +111 -0
  77. womm/commands/system/context/registration.py +290 -0
  78. womm/commands/system/deps.py +165 -0
  79. womm/commands/system/system.py +130 -0
  80. womm/exceptions/__init__.py +69 -0
  81. womm/exceptions/common/__init__.py +55 -0
  82. womm/exceptions/common/command_service.py +91 -0
  83. womm/exceptions/common/file_service.py +60 -0
  84. womm/exceptions/common/security_service.py +44 -0
  85. womm/exceptions/common/validation_service.py +70 -0
  86. womm/exceptions/context/__init__.py +27 -0
  87. womm/exceptions/context/context_service.py +55 -0
  88. womm/exceptions/project/__init__.py +29 -0
  89. womm/exceptions/project/project_service.py +59 -0
  90. womm/exceptions/system/__init__.py +25 -0
  91. womm/exceptions/system/system_service.py +53 -0
  92. womm/interfaces/__init__.py +71 -0
  93. womm/interfaces/context/__init__.py +34 -0
  94. womm/interfaces/context/menu_interface.py +686 -0
  95. womm/interfaces/context/registry_interface.py +562 -0
  96. womm/interfaces/context/script_detector_interface.py +208 -0
  97. womm/interfaces/context/script_registrar.py +264 -0
  98. womm/interfaces/core/__init__.py +26 -0
  99. womm/interfaces/core/doctor_interface.py +102 -0
  100. womm/interfaces/dependencies/__init__.py +28 -0
  101. womm/interfaces/dependencies/deps_interface.py +160 -0
  102. womm/interfaces/project/__init__.py +36 -0
  103. womm/interfaces/project/create_interface.py +162 -0
  104. womm/interfaces/project/detection_interface.py +181 -0
  105. womm/interfaces/project/manager_interface.py +99 -0
  106. womm/interfaces/project/setup_interface.py +477 -0
  107. womm/interfaces/project/template_store_interface.py +196 -0
  108. womm/interfaces/system/__init__.py +32 -0
  109. womm/interfaces/system/detector_interface.py +84 -0
  110. womm/interfaces/system/environment_interface.py +110 -0
  111. womm/interfaces/system/path_interface.py +570 -0
  112. womm/services/__init__.py +70 -0
  113. womm/services/common/__init__.py +33 -0
  114. womm/services/common/base_validation_service.py +450 -0
  115. womm/services/common/command_runner_service.py +647 -0
  116. womm/services/common/file_scanner_service.py +483 -0
  117. womm/services/common/security_validator_service.py +348 -0
  118. womm/services/context/__init__.py +37 -0
  119. womm/services/context/backup_entries.py +148 -0
  120. womm/services/context/parameters.py +515 -0
  121. womm/services/context/registry_paths.py +56 -0
  122. womm/services/context/registry_service.py +573 -0
  123. womm/services/context/validation_service.py +691 -0
  124. womm/services/dependencies/__init__.py +29 -0
  125. womm/services/dependencies/probe.py +102 -0
  126. womm/services/project/__init__.py +48 -0
  127. womm/services/project/copier_project_creation_service.py +111 -0
  128. womm/services/project/destination_guard.py +96 -0
  129. womm/services/project/detection_service.py +354 -0
  130. womm/services/project/env_utils.py +333 -0
  131. womm/services/project/javascript_environment_service.py +348 -0
  132. womm/services/project/python_environment_service.py +245 -0
  133. womm/services/project/setup_profile_resolver.py +146 -0
  134. womm/services/project/template_store_service.py +344 -0
  135. womm/services/project/validation_service.py +418 -0
  136. womm/services/system/__init__.py +32 -0
  137. womm/services/system/detector_service.py +704 -0
  138. womm/services/system/environment_service.py +494 -0
  139. womm/services/system/path_service.py +642 -0
  140. womm/shared/__init__.py +30 -0
  141. womm/shared/configs/__init__.py +51 -0
  142. womm/shared/configs/context/__init__.py +43 -0
  143. womm/shared/configs/context/context_config.py +125 -0
  144. womm/shared/configs/context/context_file_types_config.py +159 -0
  145. womm/shared/configs/context/context_limits_config.py +187 -0
  146. womm/shared/configs/context/context_paths_config.py +115 -0
  147. womm/shared/configs/context/context_types_config.py +65 -0
  148. womm/shared/configs/context/script_config.py +219 -0
  149. womm/shared/configs/dependencies/__init__.py +32 -0
  150. womm/shared/configs/dependencies/runtime_config.py +46 -0
  151. womm/shared/configs/dependencies/runtime_package_manager_config.py +48 -0
  152. womm/shared/configs/logging_config.py +89 -0
  153. womm/shared/configs/project/__init__.py +33 -0
  154. womm/shared/configs/project/project_config.py +109 -0
  155. womm/shared/configs/project/project_structure_config.py +88 -0
  156. womm/shared/configs/project/python_project_config.py +165 -0
  157. womm/shared/configs/security/__init__.py +26 -0
  158. womm/shared/configs/security/security_patterns_config.py +242 -0
  159. womm/shared/configs/system/__init__.py +28 -0
  160. womm/shared/configs/system/system_detector_config.py +210 -0
  161. womm/shared/configs/system/system_environment_config.py +101 -0
  162. womm/shared/models/__init__.py +13 -0
  163. womm/shared/models/template_source.py +65 -0
  164. womm/shared/paths.py +192 -0
  165. womm/shared/results/__init__.py +138 -0
  166. womm/shared/results/base.py +85 -0
  167. womm/shared/results/command_results.py +61 -0
  168. womm/shared/results/context_results.py +345 -0
  169. womm/shared/results/dependency_results.py +110 -0
  170. womm/shared/results/doctor_results.py +41 -0
  171. womm/shared/results/file_results.py +97 -0
  172. womm/shared/results/project_results.py +163 -0
  173. womm/shared/results/security_results.py +128 -0
  174. womm/shared/results/system_results.py +268 -0
  175. womm/shared/results/template_results.py +43 -0
  176. womm/shared/runtime.py +36 -0
  177. womm/ui/__init__.py +31 -0
  178. womm/ui/common/__init__.py +39 -0
  179. womm/ui/common/interactive_menu.py +246 -0
  180. womm/ui/common/logging.py +184 -0
  181. womm/ui/common/prompts.py +93 -0
  182. womm/ui/context/__init__.py +31 -0
  183. womm/ui/context/display.py +485 -0
  184. womm/ui/context/menu_display.py +189 -0
  185. womm/ui/context/wizard.py +557 -0
  186. womm/ui/project/__init__.py +42 -0
  187. womm/ui/project/create/create_completion_summaries.py +55 -0
  188. womm/ui/project/project_wizard.py +174 -0
  189. womm/ui/project/setup/setup_completion_summaries.py +111 -0
  190. womm/ui/project/templates/template_store_display.py +128 -0
  191. womm/ui/system/__init__.py +60 -0
  192. womm/ui/system/display.py +531 -0
  193. womm/ui/system/path_display.py +387 -0
  194. womm/utils/__init__.py +23 -0
  195. womm/utils/common/__init__.py +49 -0
  196. womm/utils/common/file_scanner_utils.py +110 -0
  197. womm/utils/common/path_resolver_utils.py +127 -0
  198. womm/utils/common/safe_fs_utils.py +135 -0
  199. womm/utils/context/__init__.py +54 -0
  200. womm/utils/context/core_utils.py +345 -0
  201. womm/utils/context/icon_utils.py +259 -0
  202. womm/utils/project/__init__.py +106 -0
  203. womm/utils/project/asset_utils.py +154 -0
  204. womm/utils/project/core_utils.py +391 -0
  205. womm/utils/project/file_utils.py +494 -0
  206. womm/utils/project/platform_utils.py +170 -0
  207. womm/utils/project/validation_utils.py +273 -0
  208. womm/utils/security/__init__.py +46 -0
  209. womm/utils/security/security_validation_utils.py +258 -0
  210. womm/utils/system/__init__.py +69 -0
  211. womm/utils/system/detector_utils.py +299 -0
  212. womm/utils/system/environment_utils.py +172 -0
  213. womm/utils/system/path_utils.py +101 -0
  214. womm_cli-4.0.0.dist-info/METADATA +203 -0
  215. womm_cli-4.0.0.dist-info/RECORD +218 -0
  216. womm_cli-4.0.0.dist-info/WHEEL +4 -0
  217. womm_cli-4.0.0.dist-info/entry_points.txt +2 -0
  218. womm_cli-4.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # DEPENDENCIES SERVICES - Dependency detection
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Dependency-related services for Works On My Machine.
9
+
10
+ This package exposes the lightweight read-only probe used to detect whether an
11
+ executable (system package manager, runtime, or dev tool) is available.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ # ///////////////////////////////////////////////////////////////
17
+ # IMPORTS
18
+ # ///////////////////////////////////////////////////////////////
19
+ # Local imports
20
+ from .probe import ProbeResult, probe
21
+
22
+ # ///////////////////////////////////////////////////////////////
23
+ # PUBLIC API
24
+ # ///////////////////////////////////////////////////////////////
25
+
26
+ __all__ = [
27
+ "ProbeResult",
28
+ "probe",
29
+ ]
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # DEPENDENCY PROBE - Lightweight Executable Detection
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Lightweight dependency probing for Works On My Machine.
9
+
10
+ Provides a single, read-only primitive to detect whether an executable
11
+ (system package manager, runtime, or dev tool) is available on the current
12
+ machine and, optionally, its version. Backed by the hardened
13
+ :class:`CommandRunnerService` (PATH lookup + security validation), it replaces
14
+ the former multi-strata interface/service machinery for diagnostic use.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ # ///////////////////////////////////////////////////////////////
20
+ # IMPORTS
21
+ # ///////////////////////////////////////////////////////////////
22
+ # Standard library imports
23
+ import shutil
24
+ from dataclasses import dataclass
25
+
26
+ # Local imports
27
+ from ..common.command_runner_service import CommandRunnerService
28
+
29
+ # ///////////////////////////////////////////////////////////////
30
+ # RESULT TYPE
31
+ # ///////////////////////////////////////////////////////////////
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class ProbeResult:
36
+ """Outcome of probing a single executable (read-only)."""
37
+
38
+ name: str
39
+ available: bool
40
+ path: str | None = None
41
+ version: str | None = None
42
+
43
+ @property
44
+ def success(self) -> bool:
45
+ """Alias for ``available`` (compat with the old *Result contract)."""
46
+ return self.available
47
+
48
+
49
+ # ///////////////////////////////////////////////////////////////
50
+ # PUBLIC API
51
+ # ///////////////////////////////////////////////////////////////
52
+
53
+
54
+ def probe(
55
+ executable: str,
56
+ *,
57
+ version_flag: str = "--version",
58
+ detect_version: bool = True,
59
+ ) -> ProbeResult:
60
+ """Detect whether an executable is installed and optionally its version.
61
+
62
+ Args:
63
+ executable: Name of the executable to look up on ``PATH``.
64
+ version_flag: Flag used to query the version (default ``--version``).
65
+ detect_version: Whether to attempt version detection when available.
66
+
67
+ Returns:
68
+ ProbeResult: Availability, resolved path, and version (best effort).
69
+ """
70
+ runner = CommandRunnerService()
71
+
72
+ availability = runner.check_command_available(executable)
73
+ if not availability.is_available:
74
+ return ProbeResult(name=executable, available=False)
75
+
76
+ resolved = shutil.which(executable)
77
+
78
+ version: str | None = None
79
+ if detect_version:
80
+ # The version call goes through the resolved path: on Windows, npm and
81
+ # yarn are ``.CMD`` shims that a bare-name, shell-less subprocess cannot
82
+ # launch at all (WinError 2), which would report every one of them as an
83
+ # unknown version.
84
+ version_result = runner.get_command_version(
85
+ resolved or executable, version_flag
86
+ )
87
+ if version_result.success and version_result.version:
88
+ version = version_result.version
89
+
90
+ return ProbeResult(
91
+ name=executable,
92
+ available=True,
93
+ path=resolved,
94
+ version=version,
95
+ )
96
+
97
+
98
+ # ///////////////////////////////////////////////////////////////
99
+ # EXPORTS
100
+ # ///////////////////////////////////////////////////////////////
101
+
102
+ __all__ = ["ProbeResult", "probe"]
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # SERVICES PROJECT - Project Services
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """
8
+ Project services for Works On My Machine.
9
+
10
+ This package contains services for project management operations including
11
+ detection, validation, and configuration.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ # ///////////////////////////////////////////////////////////////
17
+ # IMPORTS
18
+ # ///////////////////////////////////////////////////////////////
19
+ # Local imports
20
+ from .detection_service import ProjectDetectionService
21
+ from .env_utils import (
22
+ check_npm_available,
23
+ create_virtual_environment,
24
+ find_pip_executable,
25
+ install_npm_dependencies,
26
+ install_npm_dev_dependencies,
27
+ install_python_dependencies,
28
+ )
29
+ from .javascript_environment_service import JavaScriptEnvironmentService
30
+ from .python_environment_service import PythonEnvironmentService
31
+ from .validation_service import ProjectValidationService
32
+
33
+ # ///////////////////////////////////////////////////////////////
34
+ # PUBLIC API
35
+ # ///////////////////////////////////////////////////////////////
36
+
37
+ __all__ = [
38
+ "JavaScriptEnvironmentService",
39
+ "ProjectDetectionService",
40
+ "ProjectValidationService",
41
+ "PythonEnvironmentService",
42
+ "check_npm_available",
43
+ "create_virtual_environment",
44
+ "find_pip_executable",
45
+ "install_npm_dependencies",
46
+ "install_npm_dev_dependencies",
47
+ "install_python_dependencies",
48
+ ]
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # COPIER PROJECT CREATION SERVICE - Copier-backed rendering
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """Project rendering, delegated to Copier.
8
+
9
+ Copier owns the questionnaire and the rendering. WOMM owns the destination
10
+ contract, the security posture (no tasks, no unsafe features) and the
11
+ translation of Copier failures into ``ProjectServiceError``.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ # ///////////////////////////////////////////////////////////////
17
+ # IMPORTS
18
+ # ///////////////////////////////////////////////////////////////
19
+ from collections.abc import Mapping
20
+ from dataclasses import dataclass, field
21
+ from pathlib import Path
22
+
23
+ import copier
24
+
25
+ from womm.exceptions.project import ProjectServiceError
26
+
27
+ from .destination_guard import check_destination
28
+
29
+ # ///////////////////////////////////////////////////////////////
30
+ # REQUEST
31
+ # ///////////////////////////////////////////////////////////////
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class ProjectCreationRequest:
36
+ """Everything needed to render one project.
37
+
38
+ Attributes:
39
+ template_source: Path to the template root holding ``copier.yml``.
40
+ destination: Directory to render into.
41
+ answers: Pre-filled answers, keyed by Copier question name.
42
+ force: Allow rendering into a non-empty destination.
43
+ pretend: Simulate the rendering without writing anything.
44
+ defaults: Use declared defaults instead of prompting.
45
+ """
46
+
47
+ template_source: Path
48
+ destination: Path
49
+ answers: Mapping[str, object] = field(default_factory=dict)
50
+ force: bool = False
51
+ pretend: bool = False
52
+ defaults: bool = False
53
+
54
+
55
+ # ///////////////////////////////////////////////////////////////
56
+ # SERVICE
57
+ # ///////////////////////////////////////////////////////////////
58
+
59
+
60
+ class CopierProjectCreationService:
61
+ """Render a project from a Copier template."""
62
+
63
+ def create(self, request: ProjectCreationRequest) -> Path:
64
+ """Render a template into its destination.
65
+
66
+ A simulation never touches the filesystem, so it bypasses the
67
+ destination guard: simulating against an existing project must stay
68
+ possible.
69
+
70
+ Args:
71
+ request: Immutable rendering request.
72
+
73
+ Returns:
74
+ Path: The destination directory.
75
+
76
+ Raises:
77
+ ProjectServiceError: If the destination is refused or Copier fails.
78
+ """
79
+ if not request.pretend:
80
+ check_destination(request.destination, force=request.force)
81
+
82
+ try:
83
+ copier.run_copy(
84
+ src_path=str(request.template_source),
85
+ dst_path=str(request.destination),
86
+ data=dict(request.answers),
87
+ overwrite=request.force,
88
+ pretend=request.pretend,
89
+ defaults=request.defaults,
90
+ cleanup_on_error=True,
91
+ unsafe=False,
92
+ skip_tasks=True,
93
+ quiet=True,
94
+ )
95
+ except ProjectServiceError:
96
+ raise
97
+ except Exception as exc: # noqa: BLE001 - Copier raises many types
98
+ raise ProjectServiceError(
99
+ operation="create_project",
100
+ reason=f"Template rendering failed: {request.template_source}",
101
+ details=str(exc),
102
+ ) from exc
103
+
104
+ return request.destination
105
+
106
+
107
+ # ///////////////////////////////////////////////////////////////
108
+ # PUBLIC API
109
+ # ///////////////////////////////////////////////////////////////
110
+
111
+ __all__ = ["CopierProjectCreationService", "ProjectCreationRequest"]
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env python3
2
+ # ///////////////////////////////////////////////////////////////
3
+ # DESTINATION GUARD - Pre-flight checks before rendering
4
+ # Project: works-on-my-machine
5
+ # ///////////////////////////////////////////////////////////////
6
+
7
+ """Destination pre-flight checks run before any Copier invocation.
8
+
9
+ Copier's ``overwrite`` flag governs conflicting-file overwrites, not the
10
+ refusal of a non-empty directory: Copier happily renders into an existing
11
+ tree. The "non-empty destination fails without --force" contract is
12
+ therefore enforced here, before Copier is ever called.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ # ///////////////////////////////////////////////////////////////
18
+ # IMPORTS
19
+ # ///////////////////////////////////////////////////////////////
20
+ from pathlib import Path
21
+
22
+ from womm.exceptions.project import ProjectServiceError
23
+
24
+ # ///////////////////////////////////////////////////////////////
25
+ # CONSTANTS
26
+ # ///////////////////////////////////////////////////////////////
27
+
28
+ # Entries that do not make a destination "occupied": a freshly cloned but
29
+ # empty repository is a legitimate target.
30
+ IGNORED_ENTRIES = frozenset({".git"})
31
+
32
+ # Maximum number of occupants listed in the refusal message.
33
+ DEFAULT_OCCUPANT_LIMIT = 4
34
+
35
+ # ///////////////////////////////////////////////////////////////
36
+ # PUBLIC FUNCTIONS
37
+ # ///////////////////////////////////////////////////////////////
38
+
39
+
40
+ def describe_occupants(
41
+ destination: Path,
42
+ limit: int = DEFAULT_OCCUPANT_LIMIT,
43
+ ) -> list[str]:
44
+ """List the entries that make a destination non-empty.
45
+
46
+ Args:
47
+ destination: Directory to inspect.
48
+ limit: Maximum number of names returned.
49
+
50
+ Returns:
51
+ list[str]: Sorted entry names, ignoring tolerated entries.
52
+ """
53
+ if not destination.is_dir():
54
+ return []
55
+ names = sorted(
56
+ entry.name
57
+ for entry in destination.iterdir()
58
+ if entry.name not in IGNORED_ENTRIES
59
+ )
60
+ return names[:limit]
61
+
62
+
63
+ def check_destination(destination: Path, *, force: bool) -> None:
64
+ """Verify that a destination may receive a rendered project.
65
+
66
+ Args:
67
+ destination: Target directory, existing or not.
68
+ force: Whether the user explicitly allowed a non-empty destination.
69
+
70
+ Raises:
71
+ ProjectServiceError: If the destination is a file, or is a non-empty
72
+ directory and ``force`` is not set.
73
+ """
74
+ if destination.exists() and not destination.is_dir():
75
+ raise ProjectServiceError(
76
+ operation="check_destination",
77
+ reason=f"Destination is not a directory: {destination}",
78
+ )
79
+
80
+ occupants = describe_occupants(destination)
81
+ if not occupants or force:
82
+ return
83
+
84
+ listed = ", ".join(occupants)
85
+ raise ProjectServiceError(
86
+ operation="check_destination",
87
+ reason=f"Destination is not empty: {destination}",
88
+ details=f"Found: {listed}. Use --force to render anyway.",
89
+ )
90
+
91
+
92
+ # ///////////////////////////////////////////////////////////////
93
+ # PUBLIC API
94
+ # ///////////////////////////////////////////////////////////////
95
+
96
+ __all__ = ["check_destination", "describe_occupants"]