-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·228 lines (193 loc) · 8.34 KB
/
setup.py
File metadata and controls
executable file
·228 lines (193 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python3
"""
Code Conductor Interactive Setup Script
Configures the repository for your specific project needs
"""
import sys
import argparse
import logging
from pathlib import Path
# Ensure the .conductor/setup package is in the Python path
conductor_path = Path(__file__).parent / ".conductor"
if conductor_path.exists():
sys.path.insert(0, str(conductor_path))
try:
# Import from the conductor setup package
from conductor_setup.detector import TechnologyDetector # noqa: E402
from conductor_setup.config_manager import ConfigurationManager # noqa: E402
from conductor_setup.ui_manager import UIManager # noqa: E402
from conductor_setup.file_generators.config_files import (
ConfigFileGenerator,
) # noqa: E402
from conductor_setup.file_generators.role_files import (
RoleFileGenerator,
) # noqa: E402
from conductor_setup.file_generators.workflow_files import (
WorkflowFileGenerator,
) # noqa: E402
from conductor_setup.file_generators.script_files import (
ScriptFileGenerator,
) # noqa: E402
from conductor_setup.github_integration import GitHubIntegration # noqa: E402
from conductor_setup.discovery_task import DiscoveryTaskCreator # noqa: E402
from conductor_setup.validator import SetupValidator # noqa: E402
except ImportError as e:
# This might happen in test environments
if __name__ == "__main__":
print(f"Error: Could not import setup modules: {e}")
print("Please ensure the .conductor/setup package is properly configured.")
sys.exit(1)
else:
# Re-raise for tests to handle
raise
else:
# For testing or when .conductor doesn't exist yet
if __name__ == "__main__":
print("Error: .conductor/setup package not found")
print("This script requires the Code Conductor setup modules.")
sys.exit(1)
class ConductorSetup:
"""Main setup orchestrator that coordinates all setup modules"""
def __init__(self, auto_mode=False, debug=False):
self.project_root = Path.cwd()
self.conductor_dir = self.project_root / ".conductor"
self.config = {}
self.detected_stack = []
self.enhanced_stack = {}
self.auto_mode = auto_mode
self.debug = debug
# Setup logging
log_level = logging.DEBUG if debug else logging.INFO
logging.basicConfig(level=log_level, format="%(message)s")
self.logger = logging.getLogger(__name__)
# Initialize UI Manager
self.ui = UIManager()
def run(self):
"""Main setup workflow"""
self.print_header()
# Check if already configured
if self.check_existing_config():
if not self.confirm_reconfigure():
print("Setup cancelled.")
return
# Run setup steps using modular components
self._detect_project_info()
self._gather_configuration()
self._create_configuration_files()
self._create_role_definitions()
self._create_github_workflows()
self._ensure_github_labels()
self._create_bootstrap_scripts()
self._validate_setup()
discovery_task_number = self._create_discovery_task()
self._display_completion_message(discovery_task_number)
def print_header(self):
"""Display setup header"""
self.ui.show_welcome()
def check_existing_config(self):
"""Check if already configured"""
config_file = self.conductor_dir / "config.yaml"
return config_file.exists()
def confirm_reconfigure(self):
"""Ask user if they want to reconfigure"""
print("⚠️ Existing configuration detected.")
if self.auto_mode:
print("Auto mode: reconfiguring existing setup...")
return True
# Use the same safe input logic as ConfigurationManager
config_mgr = ConfigurationManager(self.project_root, self.auto_mode, self.debug)
response = config_mgr._safe_input("Do you want to reconfigure? [y/N]: ", "n")
return response.lower() == "y"
def _detect_project_info(self):
"""Use TechnologyDetector to detect project characteristics"""
detector = TechnologyDetector(self.project_root, self.debug)
# Run enhanced detection with UI progress
self.enhanced_stack = detector.detect_technology_stack(self.ui)
# Also run legacy detection for compatibility
detection_result = detector.detect_project_info()
self.detected_stack = detection_result["detected_stack"]
self.config.update(detection_result["config"])
# Show detection results
if self.enhanced_stack.get("summary"):
self.ui.show_detection_results(self.enhanced_stack)
def _gather_configuration(self):
"""Use ConfigurationManager to gather configuration"""
config_mgr = ConfigurationManager(self.project_root, self.auto_mode, self.debug)
# Pass enhanced stack info and UI for express setup
self.config.update(
config_mgr.gather_configuration(
self.detected_stack, enhanced_stack=self.enhanced_stack, ui=self.ui
)
)
def _create_configuration_files(self):
"""Use ConfigFileGenerator to create configuration files"""
generator = ConfigFileGenerator(self.project_root, self.config, self.debug)
generator.create_configuration_files()
def _create_role_definitions(self):
"""Use RoleFileGenerator to create role definitions"""
generator = RoleFileGenerator(self.project_root, self.config)
generator.create_role_definitions()
def _create_github_workflows(self):
"""Use WorkflowFileGenerator to create GitHub workflows"""
generator = WorkflowFileGenerator(self.project_root, self.config)
generator.create_github_workflows()
def _ensure_github_labels(self):
"""Use GitHubIntegration to ensure labels exist"""
github = GitHubIntegration(self.project_root)
github.ensure_github_labels()
def _create_bootstrap_scripts(self):
"""Use ScriptFileGenerator to create bootstrap scripts"""
generator = ScriptFileGenerator(self.project_root, self.config)
generator.create_bootstrap_scripts()
def _validate_setup(self):
"""Use SetupValidator to validate the setup"""
validator = SetupValidator(self.project_root)
return validator.validate_setup()
def _create_discovery_task(self):
"""Use DiscoveryTaskCreator to create discovery task if needed"""
creator = DiscoveryTaskCreator(self.project_root)
return creator.create_discovery_task_if_needed()
def _display_completion_message(self, discovery_task_number=None):
"""Display completion message with UI manager"""
# Use new UI manager for express setup success
if self.config.get("setup_mode") == "express":
self.ui.show_success(self.config)
else:
# Fall back to validator for legacy mode
validator = SetupValidator(self.project_root)
validator.display_completion_message(discovery_task_number)
def main():
"""Main entry point"""
parser = argparse.ArgumentParser(
description="Code Conductor Interactive Setup",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python setup.py # Interactive setup
python setup.py --auto # Auto-configuration
python setup.py --debug # Enable debug logging
""",
)
parser.add_argument(
"--auto",
action="store_true",
help="Run in auto-configuration mode (minimal prompts)",
)
parser.add_argument("--debug", action="store_true", help="Enable debug logging")
args = parser.parse_args()
try:
setup = ConductorSetup(auto_mode=args.auto, debug=args.debug)
setup.run()
except KeyboardInterrupt:
print("\n\n❌ Setup cancelled by user.")
sys.exit(1)
except Exception as e:
if args.debug:
import traceback
traceback.print_exc()
else:
print(f"\n❌ Setup failed: {e}")
print("💡 Run with --debug for detailed error information")
sys.exit(1)
if __name__ == "__main__":
main()