Skip to content

Commit

Permalink
Print reason when 'isInVirtualEnv' fails (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Oct 15, 2020
1 parent cd06798 commit b44ce5e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/utils/pypiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class PypiUtils {
vscode.window.showErrorMessage('Could not scan Pypi project dependencies, because python interpreter is not set.');
return [];
}
if (!PypiUtils.isInVirtualEnv(pythonPath, workspaceFolder.uri.fsPath)) {
if (!PypiUtils.isInVirtualEnv(pythonPath, workspaceFolder.uri.fsPath, treesManager.logManager)) {
vscode.window.showErrorMessage(
'Please install and activate a virtual environment before running Xray scan. Then, install your Python project in that environment.'
);
Expand Down Expand Up @@ -151,12 +151,14 @@ export class PypiUtils {
* @param pythonPath - Path to python interpreter
* @param workspaceFolder - Base workspace folder
*/
public static isInVirtualEnv(pythonPath: string, workspaceFolder: string): boolean {
public static isInVirtualEnv(pythonPath: string, workspaceFolder: string, logManager: LogManager): boolean {
try {
exec.execSync(pythonPath + ' ' + PypiUtils.CHECK_VENV_SCRIPT, { cwd: workspaceFolder } as exec.ExecSyncOptionsWithStringEncoding);
return true;
} catch (error) {}
return false;
} catch (error) {
logManager.logError(error, false);
return false;
}
}

/**
Expand Down

0 comments on commit b44ce5e

Please sign in to comment.