Skip to content

Commit 1b737c3

Browse files
committed
tools: Add isort linter & wrapper script.
* Add dependency upon isort for development installs * Add centralized settings for isort to setup.cfg * Add tools/run-isort-check script for linting * Add note about new script to README.md The sorting settings are set to be approximately compatible with how the tool 'black' formats code, which at least provides a good starting point, and would require only a small change for compatibility were we to adopt it. Exceptions are that black: * would need to have a specific line-length set (not the default) * splits long lines (multi_line_output=3), vs being compact (5)
1 parent 6ae33e1 commit 1b737c3

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ zipp = "==1.0.0" # To support Python 3.5
2121
pudb = "==2017.1.4"
2222
snakeviz = "==0.4.2"
2323
gitlint = "==0.10.0"
24+
isort = "==4.3.21"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Once you have a development environment set up, you might find the following use
292292
| Run all tests (including linter) | `pytest` | `pipenv run pytest` |
293293
| Build test coverage report | `pytest --cov-report html:cov_html --cov=./` | `pipenv run pytest --cov-report html:cov_html --cov=./` |
294294
| Check type annotations | `./tools/run-mypy` | `pipenv run ./tools/run-mypy` |
295+
| Check isort compliance | `./tools/run-isort-check` | `pipenv run ./tools/run-isort-check` |
295296

296297
#### GitLint (optional)
297298

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pudb==2017.1.4
88
snakeviz==0.4.2
99
gitlint==0.10.0
1010
mypy==0.740
11+
isort==4.3.21
1112
emoji==0.5.0
1213
urwid_readline==0.10
1314
beautifulsoup4==4.6.0

setup.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ markers =
1414
pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/
1515
addopts = --pep8 -rxXs --cov=zulipterminal
1616

17+
[tool:isort]
18+
# For compatibility with 'black', we'd want this to be 3
19+
multi_line_output=5
20+
include_trailing_comma=True
21+
force_grid_wrap=0
22+
use_parentheses=True
23+
# For compatibility with 'black' we'd want to set this consistently
24+
line_length=79
25+
# We run this in Travis on the lowest python version, and this should keep valid syntax
26+
atomic=True
27+
# This ensures compatibility with pytest-pep8
28+
lines_after_imports=2
29+
1730
[mypy]
1831
python_version = 3.6
1932
mypy_path = mypy_stubs

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def long_description():
4141
'pudb==2017.1.4',
4242
'snakeviz==0.4.2',
4343
'gitlint>=0.10',
44+
'isort==4.3.21',
4445
]
4546

4647
setup(

tools/run-isort-check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import sys
5+
6+
cmds = ["isort"]
7+
8+
result = subprocess.call(cmds + ["--check-only", "--diff"])
9+
10+
if result == 0:
11+
print("All files have imports sorted according to rules.")
12+
else:
13+
print("Some files are not sorted according to rules.")
14+
print("You might try '{}' to automatically fix all files.".format(" ".join(cmds)))
15+
print("Alternatively try 'isort <somefiles>' to just fix specific files.")
16+
17+
sys.exit(result)

0 commit comments

Comments
 (0)