Skip to content

Commit 503ffb5

Browse files
authored
Execute prospector as a module (using -m)
* 🔨 run prospector as a module (with -m) * 🔥 remove unwanted settings * 🔥 remove redundant class and fix tests * 🔨 remove versions * 📝 news entry
1 parent fc24166 commit 503ffb5

File tree

11 files changed

+22
-268
lines changed

11 files changed

+22
-268
lines changed

news/3 Code Health/982.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Execute prospector as a module (using -m).

requirements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
autopep8==1.2.1
2-
yapf==0.6.2
3-
pylint==1.8.2
4-
pep8==1.7.0
5-
prospector==0.11.7
6-
flake8==2.6.0
7-
pydocstyle==1.0.0
1+
autopep8
2+
yapf
3+
pylint
4+
pep8
5+
prospector
6+
flake8
7+
pydocstyle
88
nose
99
pytest
1010
fabric

src/client/common/installer/installer.ts

Lines changed: 0 additions & 236 deletions
This file was deleted.

src/client/common/installer/productInstaller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ abstract class BaseInstaller {
6161
}
6262

6363
public async isInstalled(product: Product, resource?: Uri): Promise<boolean | undefined> {
64+
if (product === Product.unittest) {
65+
return true;
66+
}
6467
let moduleName: string | undefined;
6568
try {
6669
moduleName = translateProductToModule(product, ModuleNamePurpose.run);
@@ -71,14 +74,12 @@ abstract class BaseInstaller {
7174
const executableName = this.getExecutableNameFromSettings(product, resource);
7275

7376
const isModule = typeof moduleName === 'string' && moduleName.length > 0 && path.basename(executableName) === executableName;
74-
// Prospector is an exception, it can be installed as a module, but not run as one.
75-
if (product !== Product.prospector && isModule) {
77+
if (isModule) {
7678
const pythonProcess = await this.serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory).create(resource);
7779
return pythonProcess.isModuleInstalled(executableName);
7880
} else {
7981
const process = this.serviceContainer.get<IProcessService>(IProcessService);
80-
const prospectorPath = this.configService.getSettings(resource).linting.prospectorPath;
81-
return process.exec(prospectorPath, ['--version'], { mergeStdOutErr: true })
82+
return process.exec(executableName, ['--version'], { mergeStdOutErr: true })
8283
.then(() => true)
8384
.catch(() => false);
8485
}

src/client/formatters/helper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class FormatterHelper implements IFormatterHelper {
3939
let moduleName: string | undefined;
4040

4141
// If path information is not available, then treat it as a module,
42-
// except for prospector as that needs to be run as an executable (it's a Python package).
4342
if (path.basename(execPath) === execPath) {
4443
moduleName = execPath;
4544
}

src/client/linters/linterInfo.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export class LinterInfo implements ILinterInfo {
6060
let moduleName: string | undefined;
6161

6262
// If path information is not available, then treat it as a module,
63-
// Except for prospector as that needs to be run as an executable (its a python package).
6463
if (path.basename(execPath) === execPath) {
6564
moduleName = execPath;
6665
}

src/test/.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
"-p",
1212
"*test*.py"
1313
],
14-
"python.formatting.formatOnSave": false,
1514
"python.sortImports.args": [],
1615
"python.linting.lintOnSave": false,
17-
"python.linting.lintOnTextChange": false,
1816
"python.linting.enabled": true,
1917
"python.linting.pep8Enabled": false,
2018
"python.linting.prospectorEnabled": false,
@@ -23,4 +21,4 @@
2321
"python.linting.mypyEnabled": false,
2422
"python.formatting.provider": "yapf",
2523
"python.linting.pylintUseMinimalCheckers": false
26-
}
24+
}

src/test/common/installer.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ suite('Installer', () => {
7575
if (args.length > 1 && args[0] === '-c' && args[1] === `import ${moduleName}`) {
7676
checkInstalledDef.resolve(true);
7777
}
78-
if (product === Product.prospector && args.length > 0 && args[0] === '--version') {
79-
checkInstalledDef.resolve(true);
80-
}
8178
callback({ stdout: '' });
8279
});
8380
await installer.isInstalled(product, resource);

src/test/common/installer/installer.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as chaiAsPromised from 'chai-as-promised';
66
import * as TypeMoq from 'typemoq';
77
import { Disposable, OutputChannel, Uri } from 'vscode';
88
import { EnumEx } from '../../../client/common/enumUtils';
9-
import { Installer } from '../../../client/common/installer/installer';
109
import { ProductInstaller } from '../../../client/common/installer/productInstaller';
1110
import { IInstallationChannelManager, IModuleInstaller } from '../../../client/common/installer/types';
1211
import { IDisposableRegistry, ILogger, InstallerResponse, ModuleNamePurpose, Product } from '../../../client/common/types';
@@ -19,16 +18,15 @@ suite('Module Installerx', () => {
1918
[undefined, Uri.file('resource')].forEach(resource => {
2019
EnumEx.getNamesAndValues<Product>(Product).forEach(product => {
2120
let disposables: Disposable[] = [];
22-
let installer: Installer;
21+
let installer: ProductInstaller;
2322
let installationChannel: TypeMoq.IMock<IInstallationChannelManager>;
2423
let moduleInstaller: TypeMoq.IMock<IModuleInstaller>;
2524
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
26-
let productInstallerFactory: ProductInstaller;
2725
setup(() => {
2826
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
2927
const outputChannel = TypeMoq.Mock.ofType<OutputChannel>();
3028

31-
installer = new Installer(serviceContainer.object, outputChannel.object);
29+
installer = new ProductInstaller(serviceContainer.object, outputChannel.object);
3230

3331
disposables = [];
3432
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IDisposableRegistry), TypeMoq.It.isAny())).returns(() => disposables);
@@ -41,8 +39,6 @@ suite('Module Installerx', () => {
4139
moduleInstaller.setup((x: any) => x.then).returns(() => undefined);
4240
installationChannel.setup(i => i.getInstallationChannel(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(moduleInstaller.object));
4341
installationChannel.setup(i => i.getInstallationChannel(TypeMoq.It.isAny())).returns(() => Promise.resolve(moduleInstaller.object));
44-
45-
productInstallerFactory = new ProductInstaller(serviceContainer.object, outputChannel.object);
4642
});
4743
teardown(() => {
4844
disposables.forEach(disposable => {
@@ -91,7 +87,7 @@ suite('Module Installerx', () => {
9187
moduleInstaller.setup(m => m.installModule(TypeMoq.It.isValue(moduleName), TypeMoq.It.isValue(resource))).returns(() => Promise.reject(new Error('UnitTesting')));
9288

9389
try {
94-
await productInstallerFactory.install(product.value, resource);
90+
await installer.install(product.value, resource);
9591
} catch (ex) {
9692
moduleInstaller.verify(m => m.installModule(TypeMoq.It.isValue(moduleName), TypeMoq.It.isValue(resource)), TypeMoq.Times.once());
9793
}

src/test/common/moduleInstaller.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { ConfigurationTarget, Uri } from 'vscode';
55
import { PythonSettings } from '../../client/common/configSettings';
66
import { ConfigurationService } from '../../client/common/configuration/service';
77
import { CondaInstaller } from '../../client/common/installer/condaInstaller';
8-
import { Installer } from '../../client/common/installer/installer';
98
import { PipEnvInstaller } from '../../client/common/installer/pipEnvInstaller';
109
import { PipInstaller } from '../../client/common/installer/pipInstaller';
10+
import { ProductInstaller } from '../../client/common/installer/productInstaller';
1111
import { IModuleInstaller } from '../../client/common/installer/types';
1212
import { Logger } from '../../client/common/logger';
1313
import { PersistentStateFactory } from '../../client/common/persistentState';
@@ -59,7 +59,7 @@ suite('Module Installer', () => {
5959

6060
ioc.serviceManager.addSingleton<IPersistentStateFactory>(IPersistentStateFactory, PersistentStateFactory);
6161
ioc.serviceManager.addSingleton<ILogger>(ILogger, Logger);
62-
ioc.serviceManager.addSingleton<IInstaller>(IInstaller, Installer);
62+
ioc.serviceManager.addSingleton<IInstaller>(IInstaller, ProductInstaller);
6363

6464
mockTerminalService = TypeMoq.Mock.ofType<ITerminalService>();
6565
const mockTerminalFactory = TypeMoq.Mock.ofType<ITerminalServiceFactory>();

0 commit comments

Comments
 (0)