Skip to content

Commit fc1ab42

Browse files
committed
feat: add Python support with feature parity to JavaScript/TypeScript
- Add Python tool detector with 25+ tools detection - Add Python config wizard with interactive and quick setup - Add Python command runner following JavaScript pattern - Update python-setup command to use new config wizard - Fix tool detection method names and display logic - Test Python implementation with working setup wizard
1 parent 456ca42 commit fc1ab42

6 files changed

Lines changed: 1342 additions & 749 deletions

File tree

languages/python/config-wizard.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PythonConfigWizard {
7676
}
7777

7878
this.prompts.success(
79-
`Detected Python project with ${Math.round(pythonResult.confidence * 100)}% confidence`,
79+
`Detected Python project with ${Math.round(pythonResult.confidence * 100)}% confidence`
8080
);
8181

8282
if (pythonResult.indicators.length > 0) {
@@ -129,35 +129,49 @@ class PythonConfigWizard {
129129
this.prompts.info('Detecting Python tools...');
130130

131131
// Use the Python tool detector for consistent detection
132-
const detectedTools = await this.toolDetector.detectAll();
132+
const detectedTools = await this.toolDetector.detectTools();
133133

134134
// Generate environment report
135135
const report = this.toolDetector.generateEnvironmentReport(detectedTools);
136136

137137
// Show detection results
138-
this.prompts.info(
139-
`Detected ${report.summary.toolsDetected}/${report.summary.totalTools} Python tools`,
140-
);
138+
let installedCount = 0;
139+
const installedTools = [];
140+
141+
for (const [toolName, toolInfo] of Object.entries(detectedTools)) {
142+
if (toolInfo && toolInfo.installed) {
143+
installedCount++;
144+
installedTools.push({ name: toolName, info: toolInfo });
145+
}
146+
}
147+
148+
this.prompts.info(`Detected ${installedCount} Python tools`);
141149

142150
// Show installed tools
143-
if (report.summary.toolsDetected > 0) {
151+
if (installedCount > 0) {
144152
this.prompts.info('Installed tools:');
145-
for (const [toolName, toolInfo] of Object.entries(detectedTools)) {
146-
if (toolInfo.installed) {
147-
const versionText = toolInfo.version ? `v${toolInfo.version}` : 'unknown version';
148-
// Check if tool is recommended (some tools may not have this property)
149-
const recommended = toolInfo.recommended ? ' ⭐' : '';
150-
this.prompts.item(`${toolName}: ${versionText}${recommended}`);
151-
}
153+
for (const { name, info } of installedTools) {
154+
const versionText = info.version ? `v${info.version}` : 'unknown version';
155+
console.log(` • ${name}: ${versionText}`);
152156
}
153157
}
154158

155-
// Show recommendations if any
156-
if (report.recommendations.length > 0) {
159+
// Show recommendations based on what's missing
160+
const recommendations = [];
161+
162+
if (!detectedTools.python?.installed && !detectedTools.python3?.installed) {
163+
recommendations.push({ type: 'critical', message: 'Python is not installed' });
164+
}
165+
166+
if (!detectedTools.pip?.installed && !detectedTools.pip3?.installed) {
167+
recommendations.push({ type: 'high', message: 'pip is not installed' });
168+
}
169+
170+
if (recommendations.length > 0) {
157171
this.prompts.info('Recommendations:');
158-
report.recommendations.forEach((rec) => {
172+
recommendations.forEach((rec) => {
159173
const icon = rec.type === 'critical' ? '❌' : rec.type === 'high' ? '⚠️' : '🔵';
160-
this.prompts.item(`${icon} ${rec.message}`);
174+
console.log(` ${icon} ${rec.message}`);
161175
});
162176
}
163177

@@ -216,7 +230,7 @@ class PythonConfigWizard {
216230

217231
config.dependencyManager = await this.prompts.selectWithDescriptions(
218232
'Select dependency manager:',
219-
depManagerChoices,
233+
depManagerChoices
220234
);
221235

222236
// 2. Test runner selection
@@ -242,7 +256,7 @@ class PythonConfigWizard {
242256

243257
config.testRunner = await this.prompts.selectWithDescriptions(
244258
'Select testing framework:',
245-
testRunnerChoices,
259+
testRunnerChoices
246260
);
247261

248262
// 3. Linter selection
@@ -303,7 +317,7 @@ class PythonConfigWizard {
303317

304318
config.formatter = await this.prompts.selectWithDescriptions(
305319
'Select code formatter:',
306-
formatterChoices,
320+
formatterChoices
307321
);
308322

309323
// 5. Type checker selection (for typed projects)
@@ -329,22 +343,22 @@ class PythonConfigWizard {
329343

330344
config.typeChecker = await this.prompts.selectWithDescriptions(
331345
'Select type checker:',
332-
typeCheckerChoices,
346+
typeCheckerChoices
333347
);
334348

335349
// 6. Project-specific options based on type
336350
if (projectType === 'fastapi') {
337351
const includeDocs = await this.prompts.confirm(
338352
'Include automatic API documentation (Swagger/ReDoc)?',
339-
true,
353+
true
340354
);
341355
config.fastapiOptions = { includeDocs };
342356
}
343357

344358
if (projectType === 'data-science' || projectType === 'machine-learning') {
345359
const includeNotebooks = await this.prompts.confirm(
346360
'Include Jupyter notebook support?',
347-
true,
361+
true
348362
);
349363
config.dataScienceOptions = { includeNotebooks };
350364
}
@@ -353,7 +367,7 @@ class PythonConfigWizard {
353367
const cliFramework = await this.prompts.select(
354368
'Select CLI framework:',
355369
['click', 'typer', 'argparse', 'none'],
356-
0,
370+
0
357371
);
358372
config.cliOptions = {
359373
framework: ['click', 'typer', 'argparse', 'none'][cliFramework],
@@ -419,7 +433,7 @@ class PythonConfigWizard {
419433
!detectedTools[config.dependencyManager]?.installed
420434
) {
421435
recommendations.push(
422-
`Install ${config.dependencyManager}: Recommended for dependency management`,
436+
`Install ${config.dependencyManager}: Recommended for dependency management`
423437
);
424438
}
425439

@@ -462,7 +476,7 @@ class PythonConfigWizard {
462476
// General recommendations
463477
recommendations.push('Create virtual environment: `python -m venv .venv`');
464478
recommendations.push(
465-
'Activate virtual environment: `source .venv/bin/activate` (Linux/Mac) or `.venv\\Scripts\\activate` (Windows)',
479+
'Activate virtual environment: `source .venv/bin/activate` (Linux/Mac) or `.venv\\Scripts\\activate` (Windows)'
466480
);
467481
recommendations.push('Initialize git: `git init` (if not already a git repository)');
468482

0 commit comments

Comments
 (0)