Skip to content

Commit

Permalink
updated debugging, added linting, formatting and sorting of imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jan 22, 2016
1 parent d99d0c4 commit 12672ab
Show file tree
Hide file tree
Showing 25 changed files with 2,787 additions and 408 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
# Python

Intellisense, auto-completion, rename references, view references, go to definition, and the like,
Linting, Debugging, Intellisense, auto-completion, code formatting, rename references, view references, go to definition, and the like

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

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

## Requirements
* Python is installed on the current system
* Path to Python is assumed to be in the current environment path.

* Pylint is installed for linting
* - Install Pylint as follows:
* - pip install pylint
* AutoPep8 is installed for code formatting
* - Install AutoPep8 as follows (ensure pep8 is installed):
* - pip install pep8
* - pip install --upgrade autopep8

![Image of Generate Features](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/general.gif)

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

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


## Chang Log
### Version 0.0.4
* Added support for linting using Pylint (configuring pylint is coming soon)
* Added support for sorting Imports
* Added support for code formatting using Autopep8 (configuring autopep8 is coming soon)
### Version 0.0.3
* Added support for debugging using PDB (currently you cannot delete a breakpoint, this will be fixed soon)


## Debugging Instructions
* Use the Python debugger, set the name of the startup program


## Source

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

## Issues/Feedback
[Gitbub Issues](https://github.com/DonJayamanne/pythonVSCode/issues)
## License

Expand Down
31 changes: 26 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "python",
"displayName": "Python",
"description": "Python debugging, auto complete, go to definition, peek definition, signature view, rename symbol, etc",
"version": "0.0.3",
"description": "Python debugging, linting, auto complete, code formatting, sorting imports, go to definition, peek definition, signature view, rename symbol, etc",
"version": "0.0.4",
"publisher": "donjayamanne",
"license": "SEE LICENSE IN LICENSE or README.MD",
"homepage": "https://github.com/DonJayamanne/pythonVSCode/blob/master/README.md",
Expand All @@ -23,13 +23,22 @@
},
"categories": [
"Languages",
"Debuggers"
"Debuggers",
"Linters",
"Other"
],
"activationEvents": [
"onLanguage:python"
"onLanguage:python",
"onCommand:python.sortImports"
],
"main": "./out/client/extension",
"contributes": {
"commands": [
{
"command": "python.sortImports",
"title": "Python: Sort Imports"
}
],
"debuggers": [
{
"type": "python",
Expand Down Expand Up @@ -70,13 +79,25 @@
}
]
}
]
],
"configuration": {
"type": "object",
"title": "Python Configuration",
"properties": {
"python.maxNumberOfProblems": {
"type": "number",
"default": 100,
"description": "Controls the maximum number of problems produced by the server."
}
}
}
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./ && installServerIntoExtension ./out ./src/server/package.json ./src/server/tsconfig.json"
},
"dependencies": {
"tmp": "0.0.28",
"vscode-debugadapter": "^1.0.1",
"vscode-debugprotocol": "^1.0.1",
"vscode-languageserver": "^1.1.0",
Expand Down
28 changes: 28 additions & 0 deletions pythonFiles/isort/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""__init__.py.
Defines the isort module to include the SortImports utility class as well as any defined settings.
Copyright (C) 2013 Timothy Edmund Crosley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

from . import settings
from .isort import SortImports

__version__ = "4.2.2"
82 changes: 82 additions & 0 deletions pythonFiles/isort/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""isort.py.
Defines a git hook to allow pre-commit warnings and errors about import order.
usage:
exit_code = git_hook(strict=True)
Copyright (C) 2015 Helen Sherwood-Taylor
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""
import subprocess

from isort import SortImports


def get_output(command):
"""
Run a command and return raw output
:param str command: the command to run
:returns: the stdout output of the command
"""
return subprocess.check_output(command.split())


def get_lines(command):
"""
Run a command and return lines of output
:param str command: the command to run
:returns: list of whitespace-stripped lines output by command
"""
stdout = get_output(command)
return [line.strip().decode('utf-8') for line in stdout.splitlines()]


def git_hook(strict=False):
"""
Git pre-commit hook to check staged files for isort errors
:param bool strict - if True, return number of errors on exit,
causing the hook to fail. If False, return zero so it will
just act as a warning.
:return number of errors if in strict mode, 0 otherwise.
"""

# Get list of files modified and staged
diff_cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"
files_modified = get_lines(diff_cmd)

errors = 0
for filename in files_modified:
if filename.endswith('.py'):
# Get the staged contents of the file
staged_cmd = "git show :%s" % filename
staged_contents = get_output(staged_cmd)

sort = SortImports(
file_path=filename,
file_contents=staged_contents.decode(),
check=True
)

if sort.incorrectly_sorted:
errors += 1

return errors if strict else 0
Loading

0 comments on commit 12672ab

Please sign in to comment.