Skip to content

Commit

Permalink
fix:correcting python command
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya-eddy <[email protected]>
  • Loading branch information
Aditya-eddy committed Oct 15, 2024
1 parent 52f6637 commit 11297de
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Utg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { exec } from 'child_process';
import axios, { AxiosResponse } from 'axios';


Expand Down Expand Up @@ -76,6 +77,8 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string
coverageReportPath = "./coverage/cobertura-coverage.xml";

} else if (extension === '.py') {
const pythonCommand = await getPythonVersion(); // Get python version (python or python3)

if (testFilesPath && testFilesPath.length > 0) {
// Use only the first path from testFilesPath
testFilePaths = [testFilesPath[0].fsPath];
Expand Down Expand Up @@ -104,7 +107,7 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string
fs.writeFileSync(defaultTestFilePath, testContent);
}
}
command = `pytest --cov=${path.basename(sourceFilePath, '.py')} --cov-report=xml:coverage.xml ${testFilePaths[0]}`;
command = `${pythonCommand} -m pytest --cov=${path.basename(sourceFilePath, '.py')} --cov-report=xml:coverage.xml ${testFilePaths[0]}`;
coverageReportPath = "./coverage.xml";

} else if (extension === '.java') {
Expand Down Expand Up @@ -331,4 +334,23 @@ async function ensureTestFileExists(sourceFilePath: string , DirectoryPath:strin
}
}

async function getPythonVersion(): Promise<string> {
return new Promise((resolve, reject) => {
exec('python --version', (error, stdout, stderr) => {
if (error) {
exec('python3 --version', (error3, stdout3, stderr3) => {
if (error3) {
vscode.window.showErrorMessage('Python is not installed.');
reject('Python not found');
} else {
resolve('python3');
}
});
} else {
resolve('python');
}
});
});
}

export default Utg;

0 comments on commit 11297de

Please sign in to comment.