Skip to content

Commit 9535c91

Browse files
committed
Unit testing, debugger fix and flake8
1 parent 522e2d6 commit 9535c91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2593
-1122
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
"request": "attach",
2222
"sourceMaps": true,
2323
"port": 6004
24+
},
25+
{
26+
"name": "Attach to python debug server",
27+
"type": "node",
28+
"request": "launch",
29+
"runtimeArgs": [
30+
"--harmony"
31+
],
32+
"program": "./out/client/debugger/main.js",
33+
"stopOnEntry": false,
34+
"args": [
35+
"--server=4711"
36+
],
37+
"sourceMaps": true,
38+
"outDir": "./out/client"
2439
}
2540
]
2641
}

README.md

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# Python
2-
Linting, Debugging, Intellisense, auto-completion, code formatting, snippets, and more.
2+
Linting, Debugging, Intellisense, auto-completion, code formatting, snippets, unit testing, and more.
33
Works on both Windows and Mac.
44

55
##Features
6-
* Linting (PyLint, Pep8 with support for config files)
6+
* Linting (PyLint, Pep8, Flake8 with config files)
77
* Intellisense and autocompletion
8-
* Code formatting (autopep8, yapf, with support for config files)
8+
* Code formatting (autopep8, yapf, with config files)
99
* Renaming, Viewing references, Going to definitions, Go to Symbols
1010
* View signature and similar by hovering over a function or method
1111
* Debugging with support for local & global variables, arguments, expressions, watch window, stack information, break points
12+
* Unit testing (unittests and nosetests, with config files)
1213
* Sorting imports
1314
* Snippets
1415

15-
## Issues, Feedback and Suggestions
16-
[Gitbub Issues](https://github.com/DonJayamanne/pythonVSCode/issues)
16+
## Issues and Feature Requests
17+
[Github Issues](https://github.com/DonJayamanne/pythonVSCode/issues)
1718

1819
## Feature Details (with confiuration)
1920
* IDE Features
@@ -25,26 +26,30 @@ Works on both Windows and Mac.
2526
* Intellisense and Autocomplete
2627
* - Full intellisense
2728
* - Support for docstring
29+
* - Ability to include custom module paths (e.g. include paths for libraries like Google App Engine, etc)
30+
* - - Use the setting python.autoComplete.extraPaths = []
2831
* Code formatting
2932
* - Use either yapf or autopep8 for code formatting (defaults to autopep8)
3033
* - auutopep8 configuration files supported
3134
* - yapf configuration files supported
3235
* Linting
3336
* - It can be turned off (default is turn it on and use pylint)
34-
* - pylint can be turned off
35-
* - pyliny configuaration files supported
36-
* - pep8 can be turned off
37-
* - pep8 configuaration files supported
37+
* - pylint can be turned on/off (default is on), supports standard configuaration files
38+
* - pep8 can be turned on/off (default is off), supports standard configuaration files
39+
* - flake8 can be turned on/off (default is on), supports standard configuaration files
3840
* - Different categories of errors reported by pylint can be configured as warnings, errors, information or hits
39-
* - Path to pylint and pep8 can be configured
40-
* - Path to pep8 can be configured through config
41+
* - Path to pylint, pep8 and flake8 and pep8 can be configured
4142
* Debuggging
42-
* - Local and Global variables
43-
* - Arguments
4443
* - Watch window
4544
* - Evaluate Expressions
4645
* - Step through code (Step in, Step out, Continue)
4746
* - Add/remove break points
47+
* - Local variables, Global variables and arguments (experimental, still needs some polishing)
48+
* Unit Testing
49+
* - unittests (default is on)
50+
* - nosetests (default is off)
51+
* - Test resutls are displayed in the "Python" output window
52+
* - Future release will display results in a more structured manner integrated into the IDE
4853
* Snippets
4954

5055

@@ -56,19 +61,30 @@ Works on both Windows and Mac.
5661

5762
## Requirements
5863
* Python is installed on the current system
59-
* Pylint is installed for linting (optional, this can be turned off)
60-
* - Install Pylint as follows:
64+
* - Path to python can be configured
65+
* Pylint is installed for linting (optional)
6166
* - pip install pylint
62-
* Pep8 is installed for linting (optional, this can be turned off)
67+
* Pep8 is installed for linting (optional)
6368
* - pip install pep8
64-
* Autopep8 is installed for code formatting
65-
* - Install AutoPep8 as follows (ensure pep8 is installed):
69+
* Flake8 is installed for linting (optional)
70+
* - pip install flake8
71+
* Autopep8 is installed for code formatting (optional)
6672
* - pip install pep8
6773
* - pip install --upgrade autopep8
68-
74+
* Yapf is installed for code formatting (optional)
75+
* - pip install yapf
76+
* nosetests for unit testing (optional)
77+
* - pip install nose
6978

7079
## Change Log
7180

81+
### Version 0.1.1
82+
* Added support for linting using flake8
83+
* Added support for unit testing using unittest and nosetest
84+
* Added support for custom module paths for improved intellisense and autocomplete
85+
* Modifications to debugger to display console output (generated using 'print' and the like)
86+
* Modifications to debugger to accept arguments
87+
7288
### Version 0.1.0
7389
* Fixed linting of files on Mac
7490
* Added support for linting using pep8

package.json

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
],
3131
"activationEvents": [
3232
"onLanguage:python",
33-
"onCommand:python.sortImports"
33+
"onCommand:python.sortImports",
34+
"onCommand:python.runtests"
3435
],
3536
"main": "./out/client/extension",
3637
"contributes": {
@@ -44,6 +45,10 @@
4445
{
4546
"command": "python.sortImports",
4647
"title": "Python: Sort Imports"
48+
},
49+
{
50+
"command": "python.runtests",
51+
"title": "Python: Run Unit Tests"
4752
}
4853
],
4954
"debuggers": [
@@ -91,6 +96,11 @@
9196
"type": "object",
9297
"title": "Python Configuration",
9398
"properties": {
99+
"python.pythonPath": {
100+
"type": "string",
101+
"default": "python",
102+
"description": "Path to Python, you can use a custom version of Python by modifying this setting to include the full path."
103+
},
94104
"python.linting.enabled": {
95105
"type": "boolean",
96106
"default": true,
@@ -106,6 +116,11 @@
106116
"default": false,
107117
"description": "Whether to lint Python files using pep8"
108118
},
119+
"python.linting.flake8Enabled": {
120+
"type": "boolean",
121+
"default": false,
122+
"description": "Whether to lint Python files using flake8"
123+
},
109124
"python.linting.lintOnTextChange": {
110125
"type": "boolean",
111126
"default": true,
@@ -124,27 +139,57 @@
124139
"python.linting.pylintCategorySeverity.convention": {
125140
"type": "string",
126141
"default": "Hint",
127-
"description": "Severity of Pylint message type 'Convention/C'. Possible values include Error, Hint, Warning and Information."
142+
"description": "Severity of Pylint message type 'Convention/C'.",
143+
"enum": [
144+
"Hint",
145+
"Error",
146+
"Information",
147+
"Warning"
148+
]
128149
},
129150
"python.linting.pylintCategorySeverity.refactor": {
130151
"type": "string",
131152
"default": "Hint",
132-
"description": "Severity of Pylint message type 'Refactor/R'. Possible values include Error, Hint, Warning and Information."
153+
"description": "Severity of Pylint message type 'Refactor/R'.",
154+
"enum": [
155+
"Hint",
156+
"Error",
157+
"Information",
158+
"Warning"
159+
]
133160
},
134161
"python.linting.pylintCategorySeverity.warning": {
135162
"type": "string",
136163
"default": "Warning",
137-
"description": "Severity of Pylint message type 'Warning/W'. Possible values include Error, Hint, Warning and Information."
164+
"description": "Severity of Pylint message type 'Warning/W'.",
165+
"enum": [
166+
"Hint",
167+
"Error",
168+
"Information",
169+
"Warning"
170+
]
138171
},
139172
"python.linting.pylintCategorySeverity.error": {
140173
"type": "string",
141174
"default": "Error",
142-
"description": "Severity of Pylint message type 'Error/E'. Possible values include Error, Hint, Warning and Information."
175+
"description": "Severity of Pylint message type 'Error/E'.",
176+
"enum": [
177+
"Hint",
178+
"Error",
179+
"Information",
180+
"Warning"
181+
]
143182
},
144183
"python.linting.pylintCategorySeverity.fatal": {
145184
"type": "string",
146185
"default": "Error",
147-
"description": "Severity of Pylint message type 'Fatal/F'. Possible values include Error, Hint, Warning and Information."
186+
"description": "Severity of Pylint message type 'Fatal/F'.",
187+
"enum": [
188+
"Hint",
189+
"Error",
190+
"Information",
191+
"Warning"
192+
]
148193
},
149194
"python.linting.pylintPath": {
150195
"type": "string",
@@ -156,10 +201,19 @@
156201
"default": "pep8",
157202
"description": "Path to pep8, you can use a custom version of pep8 by modifying this setting to include the full path."
158203
},
204+
"python.linting.flake8Path": {
205+
"type": "string",
206+
"default": "flake8",
207+
"description": "Path to flake8, you can use a custom version of flake8 by modifying this setting to include the full path."
208+
},
159209
"python.formatting.provider": {
160210
"type": "string",
161211
"default": "autopep8",
162-
"description": "Provider for formatting. Possible options include 'autopep8' and 'yapf'."
212+
"description": "Provider for formatting. Possible options include 'autopep8' and 'yapf'.",
213+
"enum": [
214+
"autopep8",
215+
"yapf"
216+
]
163217
},
164218
"python.formatting.autopep8Path": {
165219
"type": "string",
@@ -170,6 +224,26 @@
170224
"type": "string",
171225
"default": "",
172226
"description": "Path to yapf, you can use a custom version of yapf by modifying this setting to include the full path."
227+
},
228+
"python.autoComplete.extraPaths": {
229+
"type": "array",
230+
"default": [],
231+
"description": "List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list."
232+
},
233+
"python.unitTest.nosetestsEnabled": {
234+
"type": "boolean",
235+
"default": false,
236+
"description": "Whether to enable or disable unit testing using nosetests."
237+
},
238+
"python.unitTest.nosetestPath": {
239+
"type": "string",
240+
"default": "nosetests",
241+
"description": "Path to nosetests, you can use a custom version of nosetests by modifying this setting to include the full path."
242+
},
243+
"python.unitTest.unittestEnabled": {
244+
"type": "boolean",
245+
"default": true,
246+
"description": "Whether to enable or disable unit testing using standard unittest (built into Python)."
173247
}
174248
}
175249
}

pythonFiles/unittest.py

Whitespace-only changes.

src/client/common/childProc.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
import * as path from 'path';
4+
import * as fs from 'fs';
5+
import * as child_process from 'child_process';
6+
7+
export function sendCommand(commandLine: string, cwd: string): Promise<string> {
8+
return new Promise<string>((resolve, reject) => {
9+
10+
child_process.exec(commandLine, { cwd: cwd }, (error, stdout, stderr) => {
11+
var hasErrors = (error && error.message.length > 0) || (stderr && stderr.length > 0);
12+
if (hasErrors && (typeof stdout !== "string" || stdout.length === 0)) {
13+
var errorMsg = (error && error.message) ? error.message : (stderr && stderr.length > 0 ? stderr.toString("utf-8") : "");
14+
return reject(errorMsg);
15+
}
16+
17+
resolve(stdout.toString('utf-8'));
18+
});
19+
});
20+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
5+
export interface IPythonSettings {
6+
pythonPath: string;
7+
linting: ILintingSettings;
8+
formatting: IFormattingSettings;
9+
unitTest: IUnitTestSettings;
10+
}
11+
export interface IUnitTestSettings {
12+
nosetestsEnabled: boolean;
13+
nosetestPath:string;
14+
unittestEnabled: boolean;
15+
}
16+
export interface IPylintCategorySeverity {
17+
convention: vscode.DiagnosticSeverity;
18+
refactor: vscode.DiagnosticSeverity;
19+
warning: vscode.DiagnosticSeverity;
20+
error: vscode.DiagnosticSeverity;
21+
fatal: vscode.DiagnosticSeverity;
22+
}
23+
export interface ILintingSettings {
24+
enabled: boolean;
25+
pylintEnabled: boolean;
26+
pep8Enabled: boolean;
27+
flake8Enabled: boolean;
28+
lintOnTextChange: boolean;
29+
lintOnSave: boolean;
30+
maxNumberOfProblems: number;
31+
pylintCategorySeverity: IPylintCategorySeverity;
32+
pylintPath: string;
33+
pep8Path: string;
34+
flake8Path: string;
35+
}
36+
export interface IFormattingSettings {
37+
provider: string;
38+
autopep8Path: string;
39+
yapfPath: string;
40+
}
41+
export interface IAutoCompeteSettings {
42+
extraPaths: string[];
43+
}
44+
export class PythonSettings implements IPythonSettings {
45+
constructor() {
46+
vscode.workspace.onDidChangeConfiguration(() => {
47+
this.initializeSettings();
48+
});
49+
50+
this.initializeSettings();
51+
}
52+
53+
private initializeSettings() {
54+
var pythonSettings = vscode.workspace.getConfiguration("python");
55+
56+
this.pythonPath = pythonSettings.get<string>("pythonPath");
57+
58+
var lintingSettings = pythonSettings.get<ILintingSettings>("linting");
59+
if (this.linting) {
60+
Object.assign<ILintingSettings, ILintingSettings>(this.linting, lintingSettings);
61+
}
62+
else {
63+
this.linting = lintingSettings;
64+
}
65+
66+
var formattingSettings = pythonSettings.get<IFormattingSettings>("linting");
67+
if (this.formatting) {
68+
Object.assign<IFormattingSettings, IFormattingSettings>(this.formatting, formattingSettings);
69+
}
70+
else {
71+
this.formatting = formattingSettings;
72+
}
73+
74+
var autoCompleteSettings = pythonSettings.get<IAutoCompeteSettings>("autoComplete");
75+
if (this.autoComplete) {
76+
Object.assign<IAutoCompeteSettings, IAutoCompeteSettings>(this.autoComplete, autoCompleteSettings);
77+
}
78+
else {
79+
this.autoComplete = autoCompleteSettings;
80+
}
81+
82+
var unitTestSettings = pythonSettings.get<IUnitTestSettings>("unitTest");
83+
if (this.unitTest) {
84+
Object.assign<IUnitTestSettings, IUnitTestSettings>(this.unitTest, unitTestSettings);
85+
}
86+
else {
87+
this.unitTest = unitTestSettings;
88+
}
89+
}
90+
91+
public pythonPath: string;
92+
public linting: ILintingSettings;
93+
public formatting: IFormattingSettings;
94+
public autoComplete: IAutoCompeteSettings;
95+
public unitTest: IUnitTestSettings;
96+
}

0 commit comments

Comments
 (0)