11# Python Coding Style 🐍
22
33We follow [ PEP8] ( http://www.python.org/dev/peps/pep-0008/ ) with an additional
4- standard for import ordering:
4+ standard for ordering imports :
55
66``` python
7- # Standard libraries ordered alphabetically.
7+ # First, standard libraries ordered alphabetically.
88import abc
99import urlparse
1010
11- # Third party libraries.
11+ # Second, third- party libraries.
1212import requests
1313
14- # Project libraries, using using relative paths where applicable.
14+ # Third, project libraries, using using relative paths where applicable.
1515from . import mymodule
1616```
1717
@@ -24,28 +24,25 @@ one or more directories or files:
2424
2525``` bash
2626pip install pep8
27+
2728pep8 portal/core/admin.py # Check a file
2829pep8 portal/mailers # Check a folder
2930```
3031
3132### PEP8 in Editors
3233
33- ** PyCharm**
34-
35- Enable ` PEP8 Coding Style violation ` and ` PEP8 Naming Convention violation `
36- inspection rules.
37-
38- ** Sublime Text**
39-
40- Install a PEP8 plugins: [ PEP8 Autoformat] ( https://packagecontrol.io/packages/Python%20PEP8%20Autoformat ) or
41- [ Sublime Linter PEP8] ( https://packagecontrol.io/packages/SublimeLinter-pep8 ) .
34+ * ** PyCharm** : Enable ` PEP8 Coding Style violation ` and ` PEP8 Naming Convention violation `
35+ inspection rules.
36+ * ** Sublime Text** : Install a PEP8 plugins: [ PEP8 Autoformat] ( https://packagecontrol.io/packages/Python%20PEP8%20Autoformat ) or
37+ [ Sublime Linter PEP8] ( https://packagecontrol.io/packages/SublimeLinter-pep8 ) .
4238
4339### Resolving PEP8 Errors 🛠
4440
45- Probably the best solution is [ ` autopep8 ` ] ( https://pypi.python.org/pypi/autopep8 ) :
41+ Use [ ` autopep8 ` ] ( https://pypi.python.org/pypi/autopep8 ) :
4642
4743``` bash
4844pip install autopep8
45+
4946autopep8 --diff portal/core/admin.py # Spot issues and generate a diff
5047autopep8 --in-place portal/core/admin.py # Fix issues in a file
5148autopep8 -i portal/core/* # Fix issues in a folder
@@ -54,17 +51,17 @@ autopep8 -i portal/core/* # Fix issues in a folder
5451find portal/core -name ' *.py' -print -exec autopep8 --in-place {} \;
5552```
5653
57- If fixing PEP8 issues obscures changes from reviewers, use
58- [ ` pep8radius ` ] ( https://pypi.python.org/pypi/pep8radius ) to apply ` autopep8 ` to
59- only modified areas:
54+ Use [ ` pep8radius ` ] ( https://pypi.python.org/pypi/pep8radius ) limit fixes to areas
55+ that were modified:
6056
6157``` bash
6258pip install pep8radius
59+
6360pep8radius -vv --in-place
6461```
6562
66- ` pep8radius ` uses ` git ` to check files which have been modified but not commited
67- so make sure to use it * before* you commit.
63+ ` pep8radius ` uses ` git ` to find changes in files that were modified but not
64+ commited. Use it * before* you commit.
6865
6966## Code Inspection 🕵
7067
@@ -99,7 +96,7 @@ and it will be used when `pylint` is run from there:
9996pylint --rcfile=pylint.rc mystuff/myapp/myfile.py
10097```
10198
102- ### Fixing PyLint Messages
99+ #### Fixing PyLint Messages
103100
104101Fix the message or disable:
105102
@@ -120,7 +117,7 @@ Message codes can be found [here](http://pylint-messages.wikidot.com/all-codes).
120117Disable works for the block in which they are found, so include it at the module
121118level to disable a message for a module or file.
122119
123- ## Pyflakes
120+ ### Pyflakes
124121
125122Pyflakes is another pip-installable code analysis tool that focuses on
126123identifying coding issues (and less on code layout and formatting). _ "Pyflakes
0 commit comments