Skip to content

Commit ed61369

Browse files
committed
using "Python -m" to launch linters #716, #923, #1059
1 parent f2a6d85 commit ed61369

9 files changed

Lines changed: 51 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Version 0.6.8 (xxxx)
22
# Add new editor menu 'Run Current Unit Test File' [#1061](https://github.com/DonJayamanne/pythonVSCode/issues/1061)
3+
# Changed 'mypy-lang' to mypy [#930](https://github.com/DonJayamanne/pythonVSCode/issues/930), [#998](https://github.com/DonJayamanne/pythonVSCode/issues/998)
34

45
### Version 0.6.7 (02 July 2017)
56
* Updated icon from jpg to png (transparent background)

src/client/common/installer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ ProductInstallScripts.set(Product.pylint, ['-m', 'pip', 'install', 'pylint']);
3434
ProductInstallScripts.set(Product.pytest, ['-m', 'pip', 'install', '-U', 'pytest']);
3535
ProductInstallScripts.set(Product.yapf, ['-m', 'pip', 'install', 'yapf']);
3636

37-
const ProductExecutableAndArgs = new Map<Product, {executable: string, args: string[]}>();
37+
export const ProductExecutableAndArgs = new Map<Product, {executable: string, args: string[]}>();
3838
ProductExecutableAndArgs.set(Product.mypy, {executable: 'python', args:['-m', 'mypy']});
3939
ProductExecutableAndArgs.set(Product.nosetest, {executable: 'python', args:['-m', 'nose']});
40-
ProductExecutableAndArgs.set(Product.pep8, {executable: 'python', args:['-m', 'pep8']});
4140
ProductExecutableAndArgs.set(Product.pylama, {executable: 'python', args:['-m', 'pylama']});
4241
ProductExecutableAndArgs.set(Product.prospector, {executable: 'python', args:['-m', 'prospector']});
4342
ProductExecutableAndArgs.set(Product.pylint, {executable: 'python', args:['-m', 'pylint']});

src/client/linters/flake8.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
5-
import { Product } from '../common/installer';
5+
import { Product, ProductExecutableAndArgs } from '../common/installer';
66
import { TextDocument, CancellationToken } from 'vscode';
77

88
export class Linter extends baseLinter.BaseLinter {
@@ -22,6 +22,12 @@ export class Linter extends baseLinter.BaseLinter {
2222

2323
let flake8Path = this.pythonSettings.linting.flake8Path;
2424
let flake8Args = Array.isArray(this.pythonSettings.linting.flake8Args) ? this.pythonSettings.linting.flake8Args : [];
25+
26+
if (flake8Args.length === 0 && ProductExecutableAndArgs.has(Product.flake8)){
27+
flake8Path = ProductExecutableAndArgs.get(Product.flake8).executable;
28+
flake8Args = ProductExecutableAndArgs.get(Product.flake8).args;
29+
}
30+
2531
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
2632
this.run(flake8Path, flake8Args.concat(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => {
2733
messages.forEach(msg => {

src/client/linters/mypy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
5-
import { Product } from '../common/installer';
5+
import { Product, ProductExecutableAndArgs } from '../common/installer';
66
import { TextDocument, CancellationToken } from 'vscode';
77

88
const REGEX = '(?<file>.py):(?<line>\\d+): (?<type>\\w+): (?<message>.*)\\r?(\\n|$)';
@@ -22,6 +22,12 @@ export class Linter extends baseLinter.BaseLinter {
2222

2323
let mypyPath = this.pythonSettings.linting.mypyPath;
2424
let mypyArgs = Array.isArray(this.pythonSettings.linting.mypyArgs) ? this.pythonSettings.linting.mypyArgs : [];
25+
26+
if (mypyArgs.length === 0 && ProductExecutableAndArgs.has(Product.mypy)){
27+
mypyPath = ProductExecutableAndArgs.get(Product.mypy).executable;
28+
mypyArgs = ProductExecutableAndArgs.get(Product.mypy).args;
29+
}
30+
2531
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
2632
this.run(mypyPath, mypyArgs.concat([document.uri.fsPath]), document, this.workspaceRootPath, cancellation, REGEX).then(messages => {
2733
messages.forEach(msg => {

src/client/linters/pep8Linter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
5-
import { Product } from '../common/installer';
5+
import { Product, ProductExecutableAndArgs } from '../common/installer';
66
import { TextDocument, CancellationToken } from 'vscode';
77

88
export class Linter extends baseLinter.BaseLinter {
@@ -22,6 +22,12 @@ export class Linter extends baseLinter.BaseLinter {
2222

2323
let pep8Path = this.pythonSettings.linting.pep8Path;
2424
let pep8Args = Array.isArray(this.pythonSettings.linting.pep8Args) ? this.pythonSettings.linting.pep8Args : [];
25+
26+
if (pep8Args.length === 0 && ProductExecutableAndArgs.has(Product.pep8)){
27+
pep8Path = ProductExecutableAndArgs.get(Product.pep8).executable;
28+
pep8Args = ProductExecutableAndArgs.get(Product.pep8).args;
29+
}
30+
2531
return new Promise<baseLinter.ILintMessage[]>(resolve => {
2632
this.run(pep8Path, pep8Args.concat(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => {
2733
messages.forEach(msg => {

src/client/linters/prospector.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
55
import { execPythonFile } from './../common/utils';
6-
import { Product } from '../common/installer';
6+
import { Product, ProductExecutableAndArgs } from '../common/installer';
77
import { TextDocument, CancellationToken } from 'vscode';
88

99
interface IProspectorResponse {
@@ -39,6 +39,12 @@ export class Linter extends baseLinter.BaseLinter {
3939
let prospectorPath = this.pythonSettings.linting.prospectorPath;
4040
let outputChannel = this.outputChannel;
4141
let prospectorArgs = Array.isArray(this.pythonSettings.linting.prospectorArgs) ? this.pythonSettings.linting.prospectorArgs : [];
42+
43+
if (prospectorArgs.length === 0 && ProductExecutableAndArgs.has(Product.prospector)){
44+
prospectorPath = ProductExecutableAndArgs.get(Product.prospector).executable;
45+
prospectorArgs = ProductExecutableAndArgs.get(Product.prospector).args;
46+
}
47+
4248
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
4349
execPythonFile(prospectorPath, prospectorArgs.concat(['--absolute-paths', '--output-format=json', document.uri.fsPath]), this.workspaceRootPath, false, null, cancellation).then(data => {
4450
let parsedData: IProspectorResponse;

src/client/linters/pydocstyle.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as baseLinter from './baseLinter';
55
import { ILintMessage } from './baseLinter';
66
import { OutputChannel } from 'vscode';
77
import { execPythonFile, IS_WINDOWS } from './../common/utils';
8-
import { Product } from '../common/installer';
8+
import { Product, ProductExecutableAndArgs } from '../common/installer';
99
import { TextDocument, CancellationToken } from 'vscode';
1010

1111
export class Linter extends baseLinter.BaseLinter {
@@ -23,6 +23,12 @@ export class Linter extends baseLinter.BaseLinter {
2323

2424
let pydocstylePath = this.pythonSettings.linting.pydocstylePath;
2525
let pydocstyleArgs = Array.isArray(this.pythonSettings.linting.pydocstyleArgs) ? this.pythonSettings.linting.pydocstyleArgs : [];
26+
27+
if (pydocstyleArgs.length === 0 && ProductExecutableAndArgs.has(Product.pydocstyle)){
28+
pydocstylePath = ProductExecutableAndArgs.get(Product.pydocstyle).executable;
29+
pydocstyleArgs = ProductExecutableAndArgs.get(Product.pydocstyle).args;
30+
}
31+
2632
return new Promise<baseLinter.ILintMessage[]>(resolve => {
2733
this.run(pydocstylePath, pydocstyleArgs.concat([document.uri.fsPath]), document, null, cancellation).then(messages => {
2834
// All messages in pep8 are treated as warnings for now

src/client/linters/pylama.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
5-
import { Product } from '../common/installer';
5+
import { Product, ProductExecutableAndArgs } from '../common/installer';
66
import { TextDocument, CancellationToken } from 'vscode';
77

88
const REGEX = '(?<file>.py):(?<line>\\d+):(?<column>\\d+): \\[(?<type>\\w+)\\] (?<code>\\w\\d+):? (?<message>.*)\\r?(\\n|$)';
@@ -24,6 +24,12 @@ export class Linter extends baseLinter.BaseLinter {
2424

2525
let pylamaPath = this.pythonSettings.linting.pylamaPath;
2626
let pylamaArgs = Array.isArray(this.pythonSettings.linting.pylamaArgs) ? this.pythonSettings.linting.pylamaArgs : [];
27+
28+
if (pylamaArgs.length === 0 && ProductExecutableAndArgs.has(Product.pylama)){
29+
pylamaPath = ProductExecutableAndArgs.get(Product.pylama).executable;
30+
pylamaArgs = ProductExecutableAndArgs.get(Product.pylama).args;
31+
}
32+
2733
return new Promise<baseLinter.ILintMessage[]>(resolve => {
2834
this.run(pylamaPath, pylamaArgs.concat(['--format=parsable', document.uri.fsPath]), document, this.workspaceRootPath, cancellation, REGEX).then(messages => {
2935
// All messages in pylama are treated as warnings for now

src/client/linters/pylint.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as baseLinter from './baseLinter';
44
import { OutputChannel } from 'vscode';
5-
import { Product } from '../common/installer';
5+
import { Product, ProductExecutableAndArgs } from '../common/installer';
66
import { TextDocument, CancellationToken } from 'vscode';
77

88
export class Linter extends baseLinter.BaseLinter {
@@ -20,6 +20,12 @@ export class Linter extends baseLinter.BaseLinter {
2020

2121
let pylintPath = this.pythonSettings.linting.pylintPath;
2222
let pylintArgs = Array.isArray(this.pythonSettings.linting.pylintArgs) ? this.pythonSettings.linting.pylintArgs : [];
23+
24+
if (pep8Args.length === 0 && ProductExecutableAndArgs.has(Product.pep8)){
25+
pep8Path = ProductExecutableAndArgs.get(Product.pep8).executable;
26+
pep8Args = ProductExecutableAndArgs.get(Product.pep8).args;
27+
}
28+
2329
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
2430
this.run(pylintPath, pylintArgs.concat(['--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'', '--reports=n', '--output-format=text', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => {
2531
messages.forEach(msg => {

0 commit comments

Comments
 (0)