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,299 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SYSTEM DETECTOR UTILS - Pure System Detection Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure system detector utility functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This module contains stateless utility functions for system detection
|
|
11
|
+
operations that can be used independently without class instantiation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
# Local imports
|
|
23
|
+
from ...shared.configs.system import PackageManagerConfig, SystemDetectorConfig
|
|
24
|
+
|
|
25
|
+
# ///////////////////////////////////////////////////////////////
|
|
26
|
+
# VERSION PARSING FUNCTIONS
|
|
27
|
+
# ///////////////////////////////////////////////////////////////
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def extract_version_from_stdout(stdout: str | None, fallback: str = "unknown") -> str:
|
|
31
|
+
"""
|
|
32
|
+
Extract version string from command stdout.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
stdout: Command stdout string (can be None)
|
|
36
|
+
fallback: Fallback value if stdout is empty or None
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
str: Extracted version string or fallback
|
|
40
|
+
"""
|
|
41
|
+
if not stdout:
|
|
42
|
+
return fallback
|
|
43
|
+
|
|
44
|
+
# Strip whitespace and get first line
|
|
45
|
+
version = stdout.strip()
|
|
46
|
+
if "\n" in version:
|
|
47
|
+
version = version.split("\n")[0]
|
|
48
|
+
|
|
49
|
+
return version if version else fallback
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def extract_version_first_line(stdout: str | None, fallback: str = "unknown") -> str:
|
|
53
|
+
"""
|
|
54
|
+
Extract first line from command stdout (for multi-line output).
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
stdout: Command stdout string (can be None)
|
|
58
|
+
fallback: Fallback value if stdout is empty or None
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
str: First line of stdout or fallback
|
|
62
|
+
"""
|
|
63
|
+
if not stdout:
|
|
64
|
+
return fallback
|
|
65
|
+
|
|
66
|
+
lines = stdout.strip().split("\n")
|
|
67
|
+
return lines[0] if lines else fallback
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ///////////////////////////////////////////////////////////////
|
|
71
|
+
# PACKAGE MANAGER STRUCTURE FUNCTIONS
|
|
72
|
+
# ///////////////////////////////////////////////////////////////
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def create_package_manager_entry(
|
|
76
|
+
_name: str,
|
|
77
|
+
version: str,
|
|
78
|
+
metadata: dict[str, str | int],
|
|
79
|
+
available: bool = True,
|
|
80
|
+
) -> dict[str, str | bool | int | None]:
|
|
81
|
+
"""
|
|
82
|
+
Create a standardized package manager entry dictionary.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
name: Package manager name (e.g., "chocolatey")
|
|
86
|
+
version: Package manager version string
|
|
87
|
+
metadata: Metadata dict from SystemDetectorConfig (command, description, etc.)
|
|
88
|
+
available: Whether the package manager is available
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Dict[str, str | bool | None]: Standardized package manager entry
|
|
92
|
+
"""
|
|
93
|
+
return {
|
|
94
|
+
"available": available,
|
|
95
|
+
"version": version if version else None,
|
|
96
|
+
"command": metadata.get("command", ""),
|
|
97
|
+
"description": metadata.get("description", ""),
|
|
98
|
+
"install_cmd": metadata.get("install_cmd", ""),
|
|
99
|
+
"priority": metadata.get("priority", 999),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def get_package_manager_metadata(
|
|
104
|
+
platform: str, manager_name: str
|
|
105
|
+
) -> dict[str, str | int] | None:
|
|
106
|
+
"""
|
|
107
|
+
Get package manager metadata from config based on platform.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
platform: Platform name ("Windows", "Darwin", "Linux")
|
|
111
|
+
manager_name: Package manager name (e.g., "chocolatey")
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Optional[Dict[str, str | int]]: Metadata dict or None if not found
|
|
115
|
+
"""
|
|
116
|
+
if platform == "Windows":
|
|
117
|
+
return PackageManagerConfig.get_windows_managers().get(manager_name)
|
|
118
|
+
elif platform == "Darwin":
|
|
119
|
+
return PackageManagerConfig.get_macos_managers().get(manager_name)
|
|
120
|
+
elif platform == "Linux":
|
|
121
|
+
return PackageManagerConfig.get_linux_managers().get(manager_name)
|
|
122
|
+
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# ///////////////////////////////////////////////////////////////
|
|
127
|
+
# DEVELOPMENT ENVIRONMENT STRUCTURE FUNCTIONS
|
|
128
|
+
# ///////////////////////////////////////////////////////////////
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def create_editor_entry(
|
|
132
|
+
command: str, name: str, version: str = "unknown"
|
|
133
|
+
) -> dict[str, str | bool]:
|
|
134
|
+
"""
|
|
135
|
+
Create a standardized editor entry dictionary.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
command: Editor command (e.g., "code")
|
|
139
|
+
name: Editor display name (e.g., "Visual Studio Code")
|
|
140
|
+
version: Editor version string
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Dict[str, str | bool]: Standardized editor entry
|
|
144
|
+
"""
|
|
145
|
+
return {
|
|
146
|
+
"available": True,
|
|
147
|
+
"name": name,
|
|
148
|
+
"version": version,
|
|
149
|
+
"command": command,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def create_shell_entry(command: str, name: str) -> dict[str, str | bool]:
|
|
154
|
+
"""
|
|
155
|
+
Create a standardized shell entry dictionary.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
command: Shell command (e.g., "bash")
|
|
159
|
+
name: Shell display name (e.g., "Bash")
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Dict[str, str | bool]: Standardized shell entry
|
|
163
|
+
"""
|
|
164
|
+
return {
|
|
165
|
+
"available": True,
|
|
166
|
+
"name": name,
|
|
167
|
+
"command": command,
|
|
168
|
+
"type": "shell",
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def get_editor_name(command: str) -> str | None:
|
|
173
|
+
"""
|
|
174
|
+
Get editor display name from command.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
command: Editor command (e.g., "code")
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
Optional[str]: Editor display name or None if not found
|
|
181
|
+
"""
|
|
182
|
+
return SystemDetectorConfig.EDITORS.get(command)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def get_shell_name(command: str) -> str | None:
|
|
186
|
+
"""
|
|
187
|
+
Get shell display name from command.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
command: Shell command (e.g., "bash")
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Optional[str]: Shell display name or None if not found
|
|
194
|
+
"""
|
|
195
|
+
return SystemDetectorConfig.SHELLS.get(command)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
# ///////////////////////////////////////////////////////////////
|
|
199
|
+
# PACKAGE MANAGER SELECTION FUNCTIONS
|
|
200
|
+
# ///////////////////////////////////////////////////////////////
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def get_best_package_manager(package_managers: dict[str, dict[str, Any]]) -> str | None:
|
|
204
|
+
"""
|
|
205
|
+
Get the best available package manager based on priority.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
package_managers: Dictionary of package managers with their info
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
Optional[str]: Name of the best package manager or None
|
|
212
|
+
"""
|
|
213
|
+
available = {
|
|
214
|
+
name: info
|
|
215
|
+
for name, info in package_managers.items()
|
|
216
|
+
if info.get("available", False)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if not available:
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
# Sort by priority (lower is better)
|
|
223
|
+
sorted_managers = sorted(available.items(), key=lambda x: x[1].get("priority", 999))
|
|
224
|
+
return sorted_managers[0][0]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
# ///////////////////////////////////////////////////////////////
|
|
228
|
+
# RECOMMENDATION GENERATION FUNCTIONS
|
|
229
|
+
# ///////////////////////////////////////////////////////////////
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def generate_package_manager_recommendation(
|
|
233
|
+
best_manager: str | None,
|
|
234
|
+
installable_manager: str | None,
|
|
235
|
+
) -> str:
|
|
236
|
+
"""
|
|
237
|
+
Generate package manager recommendation text.
|
|
238
|
+
|
|
239
|
+
Args:
|
|
240
|
+
best_manager: Best available package manager name or None
|
|
241
|
+
installable_manager: Installable package manager name or None
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
str: Recommendation text
|
|
245
|
+
"""
|
|
246
|
+
if best_manager:
|
|
247
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES[
|
|
248
|
+
"package_manager_use"
|
|
249
|
+
].format(manager=best_manager)
|
|
250
|
+
elif installable_manager:
|
|
251
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES[
|
|
252
|
+
"package_manager_install"
|
|
253
|
+
].format(manager=installable_manager)
|
|
254
|
+
else:
|
|
255
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES["package_manager_none"]
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def generate_editor_recommendation(dev_environments: dict[str, dict[str, Any]]) -> str:
|
|
259
|
+
"""
|
|
260
|
+
Generate editor recommendation text based on detected environments.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
dev_environments: Dictionary of detected development environments
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
str: Recommendation text
|
|
267
|
+
"""
|
|
268
|
+
if "code" in dev_environments:
|
|
269
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES["editor_vscode"]
|
|
270
|
+
elif any("vim" in env or "nvim" in env for env in dev_environments):
|
|
271
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES["editor_cli"]
|
|
272
|
+
else:
|
|
273
|
+
return SystemDetectorConfig.RECOMMENDATION_TEMPLATES["editor_install"]
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def generate_recommendations(
|
|
277
|
+
_package_managers: dict[str, dict[str, Any]],
|
|
278
|
+
dev_environments: dict[str, dict[str, Any]],
|
|
279
|
+
best_manager: str | None,
|
|
280
|
+
installable_manager: str | None,
|
|
281
|
+
) -> dict[str, str]:
|
|
282
|
+
"""
|
|
283
|
+
Generate all recommendations based on detection results.
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
package_managers: Dictionary of detected package managers
|
|
287
|
+
dev_environments: Dictionary of detected development environments
|
|
288
|
+
best_manager: Best available package manager name or None
|
|
289
|
+
installable_manager: Installable package manager name or None
|
|
290
|
+
|
|
291
|
+
Returns:
|
|
292
|
+
Dict[str, str]: Dictionary of recommendations
|
|
293
|
+
"""
|
|
294
|
+
return {
|
|
295
|
+
"package_manager": generate_package_manager_recommendation(
|
|
296
|
+
best_manager, installable_manager
|
|
297
|
+
),
|
|
298
|
+
"editor": generate_editor_recommendation(dev_environments),
|
|
299
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SYSTEM ENVIRONMENT UTILS - Environment Utilities
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Environment utilities for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
Provides utility functions for environment variable management and
|
|
11
|
+
refresh operations. Cross-platform environment utilities for system
|
|
12
|
+
operations.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
# ///////////////////////////////////////////////////////////////
|
|
18
|
+
# IMPORTS
|
|
19
|
+
# ///////////////////////////////////////////////////////////////
|
|
20
|
+
# Standard library imports
|
|
21
|
+
import os
|
|
22
|
+
import platform
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
# ///////////////////////////////////////////////////////////////
|
|
26
|
+
# WINDOWS REGISTRY FUNCTIONS
|
|
27
|
+
# ///////////////////////////////////////////////////////////////
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def read_windows_registry_path() -> tuple[str | None, str | None]:
|
|
31
|
+
"""
|
|
32
|
+
Read PATH from Windows registry (HKLM and HKCU).
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Tuple[Optional[str], Optional[str]]: (HKLM_PATH, HKCU_PATH)
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
OSError: If called on a non-Windows platform.
|
|
39
|
+
ImportError: If the stdlib ``winreg`` module is unavailable.
|
|
40
|
+
"""
|
|
41
|
+
if platform.system().lower() != "windows":
|
|
42
|
+
raise OSError("Registry access is only available on Windows")
|
|
43
|
+
|
|
44
|
+
# winreg ships with the stdlib on Windows; ImportError propagates elsewhere.
|
|
45
|
+
import winreg
|
|
46
|
+
|
|
47
|
+
hklm_path = None
|
|
48
|
+
hkcu_path = None
|
|
49
|
+
|
|
50
|
+
# Read HKLM PATH
|
|
51
|
+
try:
|
|
52
|
+
with winreg.OpenKey(
|
|
53
|
+
winreg.HKEY_LOCAL_MACHINE,
|
|
54
|
+
r"System\CurrentControlSet\Control\Session Manager\Environment",
|
|
55
|
+
) as key:
|
|
56
|
+
hklm_path = winreg.QueryValueEx(key, "Path")[0]
|
|
57
|
+
except OSError:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
# Read HKCU PATH
|
|
61
|
+
try:
|
|
62
|
+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment") as key:
|
|
63
|
+
hkcu_path = winreg.QueryValueEx(key, "Path")[0]
|
|
64
|
+
except OSError:
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
return hklm_path, hkcu_path
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def combine_paths(hklm_path: str | None, hkcu_path: str | None) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Combine HKLM and HKCU paths into a single PATH string.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
hklm_path: HKLM PATH value
|
|
76
|
+
hkcu_path: HKCU PATH value
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
str: Combined PATH value
|
|
80
|
+
"""
|
|
81
|
+
if hklm_path and hkcu_path:
|
|
82
|
+
return f"{hklm_path};{hkcu_path}"
|
|
83
|
+
if hklm_path:
|
|
84
|
+
return hklm_path
|
|
85
|
+
if hkcu_path:
|
|
86
|
+
return hkcu_path
|
|
87
|
+
return ""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# ///////////////////////////////////////////////////////////////
|
|
91
|
+
# PATH MANAGEMENT FUNCTIONS
|
|
92
|
+
# ///////////////////////////////////////////////////////////////
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def refresh_path_from_registry() -> bool:
|
|
96
|
+
"""
|
|
97
|
+
Refresh PATH from Windows registry.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
bool: True if successful, False otherwise
|
|
101
|
+
"""
|
|
102
|
+
try:
|
|
103
|
+
hklm_path, hkcu_path = read_windows_registry_path()
|
|
104
|
+
combined_path = combine_paths(hklm_path, hkcu_path)
|
|
105
|
+
|
|
106
|
+
if combined_path:
|
|
107
|
+
os.environ["PATH"] = combined_path
|
|
108
|
+
return True
|
|
109
|
+
return False
|
|
110
|
+
except (OSError, ImportError):
|
|
111
|
+
return False
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def get_shell_config_files() -> list[Path]:
|
|
115
|
+
"""
|
|
116
|
+
Get list of shell configuration files for Unix systems.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
List[Path]: List of shell configuration file paths
|
|
120
|
+
"""
|
|
121
|
+
home = Path.home()
|
|
122
|
+
config_files = [
|
|
123
|
+
home / ".bashrc",
|
|
124
|
+
home / ".zshrc",
|
|
125
|
+
home / ".profile",
|
|
126
|
+
home / ".bash_profile",
|
|
127
|
+
home / ".zprofile",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
return [f for f in config_files if f.exists()]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# ///////////////////////////////////////////////////////////////
|
|
134
|
+
# SYSTEM INFORMATION FUNCTIONS
|
|
135
|
+
# ///////////////////////////////////////////////////////////////
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def get_environment_info() -> dict[str, str]:
|
|
139
|
+
"""
|
|
140
|
+
Get comprehensive environment information.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Dict[str, str]: Dictionary of environment information
|
|
144
|
+
"""
|
|
145
|
+
return {
|
|
146
|
+
"platform": platform.system().lower(),
|
|
147
|
+
"path": os.environ.get("PATH", ""),
|
|
148
|
+
"home": os.environ.get("HOME", os.environ.get("USERPROFILE", "")),
|
|
149
|
+
"shell": os.environ.get("SHELL", os.environ.get("COMSPEC", "")),
|
|
150
|
+
"user": os.environ.get("USER", os.environ.get("USERNAME", "")),
|
|
151
|
+
"temp": os.environ.get("TEMP", os.environ.get("TMP", "")),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# ///////////////////////////////////////////////////////////////
|
|
156
|
+
# COMMAND ACCESSIBILITY FUNCTIONS
|
|
157
|
+
# ///////////////////////////////////////////////////////////////
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def is_command_accessible(command: str) -> bool:
|
|
161
|
+
"""
|
|
162
|
+
Check if a command is accessible in the current environment.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
command: Command to check
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
bool: True if command is accessible, False otherwise
|
|
169
|
+
"""
|
|
170
|
+
import shutil
|
|
171
|
+
|
|
172
|
+
return shutil.which(command) is not None
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ///////////////////////////////////////////////////////////////
|
|
3
|
+
# SYSTEM PATH UTILS - Pure System Path Utility Functions
|
|
4
|
+
# Project: works-on-my-machine
|
|
5
|
+
# ///////////////////////////////////////////////////////////////
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Pure system path utility functions for Works On My Machine.
|
|
9
|
+
|
|
10
|
+
This module contains stateless utility functions for PATH management
|
|
11
|
+
that can be used independently without class instantiation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
# ///////////////////////////////////////////////////////////////
|
|
17
|
+
# IMPORTS
|
|
18
|
+
# ///////////////////////////////////////////////////////////////
|
|
19
|
+
# Standard library imports
|
|
20
|
+
import logging
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
# ///////////////////////////////////////////////////////////////
|
|
24
|
+
# LOGGER SETUP
|
|
25
|
+
# ///////////////////////////////////////////////////////////////
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
# ///////////////////////////////////////////////////////////////
|
|
30
|
+
# PATH EXTRACTION FUNCTIONS
|
|
31
|
+
# ///////////////////////////////////////////////////////////////
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def extract_path_from_reg_output(output: str | bytes) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Extract PATH value from `reg query` output, supporting REG_SZ and REG_EXPAND_SZ.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
output: Registry query output (string or bytes)
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
str: Extracted PATH value or empty string if not found
|
|
43
|
+
"""
|
|
44
|
+
if not output:
|
|
45
|
+
return ""
|
|
46
|
+
|
|
47
|
+
if isinstance(output, (bytes, bytearray)):
|
|
48
|
+
output = output.decode("utf-8", errors="ignore")
|
|
49
|
+
|
|
50
|
+
for line in str(output).splitlines():
|
|
51
|
+
if "PATH" in line.upper() and ("REG_SZ" in line or "REG_EXPAND_SZ" in line):
|
|
52
|
+
if "REG_EXPAND_SZ" in line:
|
|
53
|
+
parts = line.split("REG_EXPAND_SZ")
|
|
54
|
+
else:
|
|
55
|
+
parts = line.split("REG_SZ")
|
|
56
|
+
if len(parts) > 1:
|
|
57
|
+
return parts[1].strip()
|
|
58
|
+
|
|
59
|
+
return ""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# ///////////////////////////////////////////////////////////////
|
|
63
|
+
# PATH DEDUPLICATION FUNCTIONS
|
|
64
|
+
# ///////////////////////////////////////////////////////////////
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def deduplicate_path_entries(path_value: str) -> str:
|
|
68
|
+
"""
|
|
69
|
+
Deduplicate PATH entries preserving first occurrence and order.
|
|
70
|
+
|
|
71
|
+
Comparison is done case-insensitively on expanded values with trailing
|
|
72
|
+
slashes/backslashes trimmed. The original first textual form is kept.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
path_value: Raw PATH string with semicolon-separated entries
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
str: Deduplicated PATH string
|
|
79
|
+
"""
|
|
80
|
+
if not path_value:
|
|
81
|
+
return path_value
|
|
82
|
+
|
|
83
|
+
seen: set[str] = set()
|
|
84
|
+
result_parts: list[str] = []
|
|
85
|
+
|
|
86
|
+
for raw_part in path_value.split(";"):
|
|
87
|
+
part = raw_part.strip()
|
|
88
|
+
if not part:
|
|
89
|
+
continue
|
|
90
|
+
try:
|
|
91
|
+
key = os.path.expandvars(part).rstrip("/\\").lower()
|
|
92
|
+
if key in seen:
|
|
93
|
+
continue
|
|
94
|
+
seen.add(key)
|
|
95
|
+
result_parts.append(part)
|
|
96
|
+
except Exception as e:
|
|
97
|
+
# Log but continue processing other entries
|
|
98
|
+
logger.warning(f"Failed to process PATH entry '{part}': {e}")
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
return ";".join(result_parts)
|