Skip to content

Commit b684563

Browse files
committed
check if product is isntalled
1 parent 493bbf4 commit b684563

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/client/common/installer.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as settings from './configSettings';
3+
import { createDeferred, isNotInstalledError } from './helpers';
4+
import { execPythonFile } from './utils';
35

46
export enum Product {
57
pytest,
@@ -133,10 +135,36 @@ export class Installer {
133135
Installer.terminal.sendText(installScript);
134136
Installer.terminal.show(false);
135137
}
138+
139+
isProductInstalled(product: Product): Promise<boolean> {
140+
return isProductInstalled(product);
141+
}
136142
}
137143

138144
export function disableLinter(product: Product) {
139145
const pythonConfig = vscode.workspace.getConfiguration('python');
140146
const settingToDisable = SettingToDisableProduct.get(product);
141147
pythonConfig.update(settingToDisable, false);
148+
}
149+
150+
function isPyTestInstalled(): Promise<boolean> {
151+
const def = createDeferred<boolean>();
152+
execPythonFile('py.test', ['--version'], vscode.workspace.rootPath, false)
153+
.then(() => {
154+
def.resolve(true);
155+
}).catch(reason => {
156+
if (isNotInstalledError(reason)) {
157+
def.resolve(false);
158+
}
159+
else {
160+
def.resolve(true);
161+
}
162+
});
163+
return def.promise;
164+
}
165+
function isProductInstalled(product: Product): Promise<boolean> {
166+
if (product === Product.pytest) {
167+
return isPyTestInstalled();
168+
}
169+
throw new Error('Not supported');
142170
}

0 commit comments

Comments
 (0)