Skip to content

Commit 12672ab

Browse files
committed
updated debugging, added linting, formatting and sorting of imports
1 parent d99d0c4 commit 12672ab

25 files changed

+2787
-408
lines changed

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,57 @@
11
# Python
2-
3-
Intellisense, auto-completion, rename references, view references, go to definition, and the like,
2+
Linting, Debugging, Intellisense, auto-completion, code formatting, rename references, view references, go to definition, and the like
43

54
##Features
5+
* Linting (using PyLint)
66
* Intellisense and auto completion
7+
* Code formatting (using AutoPep8)
78
* Renaming
89
* Viewing references
910
* Going to definitins
1011
* View signature and similar by hovering over a function or method
1112
* Debugging using PDB (work in progress, please remove any and all issues)
1213
* Debugging with support for local variables, expressions, watch window, stack information, break points
1314
* (currently you cannot removed any added breakpoints, this will be fixed in a future release)
15+
* Sorting imports
1416

15-
Open the python file and start using it.
17+
## Issues, Feedback and Suggestions
18+
[Gitbub Issues](https://github.com/DonJayamanne/pythonVSCode/issues)
1619

1720
## Requirements
1821
* Python is installed on the current system
1922
* Path to Python is assumed to be in the current environment path.
20-
23+
* Pylint is installed for linting
24+
* - Install Pylint as follows:
25+
* - pip install pylint
26+
* AutoPep8 is installed for code formatting
27+
* - Install AutoPep8 as follows (ensure pep8 is installed):
28+
* - pip install pep8
29+
* - pip install --upgrade autopep8
30+
2131
![Image of Generate Features](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/general.gif)
2232

2333
![Image of Go To Definition](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/goToDef.gif)
2434

2535
![Image of Renaming and Find all References](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/rename.gif)
2636

2737

38+
## Chang Log
39+
### Version 0.0.4
40+
* Added support for linting using Pylint (configuring pylint is coming soon)
41+
* Added support for sorting Imports
42+
* Added support for code formatting using Autopep8 (configuring autopep8 is coming soon)
43+
### Version 0.0.3
44+
* Added support for debugging using PDB (currently you cannot delete a breakpoint, this will be fixed soon)
45+
46+
2847
## Debugging Instructions
2948
* Use the Python debugger, set the name of the startup program
3049

50+
3151
## Source
3252

3353
[Github](https://github.com/DonJayamanne/pythonVSCode)
3454

35-
## Issues/Feedback
36-
[Gitbub Issues](https://github.com/DonJayamanne/pythonVSCode/issues)
3755
3856
## License
3957

package.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "python",
33
"displayName": "Python",
4-
"description": "Python debugging, auto complete, go to definition, peek definition, signature view, rename symbol, etc",
5-
"version": "0.0.3",
4+
"description": "Python debugging, linting, auto complete, code formatting, sorting imports, go to definition, peek definition, signature view, rename symbol, etc",
5+
"version": "0.0.4",
66
"publisher": "donjayamanne",
77
"license": "SEE LICENSE IN LICENSE or README.MD",
88
"homepage": "https://github.com/DonJayamanne/pythonVSCode/blob/master/README.md",
@@ -23,13 +23,22 @@
2323
},
2424
"categories": [
2525
"Languages",
26-
"Debuggers"
26+
"Debuggers",
27+
"Linters",
28+
"Other"
2729
],
2830
"activationEvents": [
29-
"onLanguage:python"
31+
"onLanguage:python",
32+
"onCommand:python.sortImports"
3033
],
3134
"main": "./out/client/extension",
3235
"contributes": {
36+
"commands": [
37+
{
38+
"command": "python.sortImports",
39+
"title": "Python: Sort Imports"
40+
}
41+
],
3342
"debuggers": [
3443
{
3544
"type": "python",
@@ -70,13 +79,25 @@
7079
}
7180
]
7281
}
73-
]
82+
],
83+
"configuration": {
84+
"type": "object",
85+
"title": "Python Configuration",
86+
"properties": {
87+
"python.maxNumberOfProblems": {
88+
"type": "number",
89+
"default": 100,
90+
"description": "Controls the maximum number of problems produced by the server."
91+
}
92+
}
93+
}
7494
},
7595
"scripts": {
7696
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
7797
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./ && installServerIntoExtension ./out ./src/server/package.json ./src/server/tsconfig.json"
7898
},
7999
"dependencies": {
100+
"tmp": "0.0.28",
80101
"vscode-debugadapter": "^1.0.1",
81102
"vscode-debugprotocol": "^1.0.1",
82103
"vscode-languageserver": "^1.1.0",

pythonFiles/isort/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""__init__.py.
2+
3+
Defines the isort module to include the SortImports utility class as well as any defined settings.
4+
5+
Copyright (C) 2013 Timothy Edmund Crosley
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
10+
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or
13+
substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
16+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19+
OTHER DEALINGS IN THE SOFTWARE.
20+
21+
"""
22+
23+
from __future__ import absolute_import, division, print_function, unicode_literals
24+
25+
from . import settings
26+
from .isort import SortImports
27+
28+
__version__ = "4.2.2"

pythonFiles/isort/hooks.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""isort.py.
2+
3+
Defines a git hook to allow pre-commit warnings and errors about import order.
4+
5+
usage:
6+
exit_code = git_hook(strict=True)
7+
8+
Copyright (C) 2015 Helen Sherwood-Taylor
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
12+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
13+
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all copies or
16+
substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
"""
25+
import subprocess
26+
27+
from isort import SortImports
28+
29+
30+
def get_output(command):
31+
"""
32+
Run a command and return raw output
33+
34+
:param str command: the command to run
35+
:returns: the stdout output of the command
36+
"""
37+
return subprocess.check_output(command.split())
38+
39+
40+
def get_lines(command):
41+
"""
42+
Run a command and return lines of output
43+
44+
:param str command: the command to run
45+
:returns: list of whitespace-stripped lines output by command
46+
"""
47+
stdout = get_output(command)
48+
return [line.strip().decode('utf-8') for line in stdout.splitlines()]
49+
50+
51+
def git_hook(strict=False):
52+
"""
53+
Git pre-commit hook to check staged files for isort errors
54+
55+
:param bool strict - if True, return number of errors on exit,
56+
causing the hook to fail. If False, return zero so it will
57+
just act as a warning.
58+
59+
:return number of errors if in strict mode, 0 otherwise.
60+
"""
61+
62+
# Get list of files modified and staged
63+
diff_cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"
64+
files_modified = get_lines(diff_cmd)
65+
66+
errors = 0
67+
for filename in files_modified:
68+
if filename.endswith('.py'):
69+
# Get the staged contents of the file
70+
staged_cmd = "git show :%s" % filename
71+
staged_contents = get_output(staged_cmd)
72+
73+
sort = SortImports(
74+
file_path=filename,
75+
file_contents=staged_contents.decode(),
76+
check=True
77+
)
78+
79+
if sort.incorrectly_sorted:
80+
errors += 1
81+
82+
return errors if strict else 0

0 commit comments

Comments
 (0)