mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Setup isort for code style linting
This commit is contained in:
parent
7351a3f6ca
commit
b4ba8ef4d7
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ MANIFEST
|
||||||
|
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!.travis.yml
|
!.travis.yml
|
||||||
|
!.isort.cfg
|
||||||
|
|
6
.isort.cfg
Normal file
6
.isort.cfg
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[settings]
|
||||||
|
skip=.tox
|
||||||
|
atomic=true
|
||||||
|
multi_line_output=5
|
||||||
|
known_third_party=pytest,django
|
||||||
|
known_first_party=rest_framework
|
|
@ -3,7 +3,7 @@ language: python
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- TOX_ENV=py27-flake8
|
- TOX_ENV=py27-lint
|
||||||
- TOX_ENV=py27-docs
|
- TOX_ENV=py27-docs
|
||||||
- TOX_ENV=py34-django18
|
- TOX_ENV=py34-django18
|
||||||
- TOX_ENV=py33-django18
|
- TOX_ENV=py33-django18
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
# PEP8 code linting, which we run on all commits.
|
# PEP8 code linting, which we run on all commits.
|
||||||
flake8==2.4.0
|
flake8==2.4.0
|
||||||
pep8==1.5.7
|
pep8==1.5.7
|
||||||
|
|
||||||
|
# Sort and lint imports
|
||||||
|
isort==3.9.6
|
||||||
|
|
21
runtests.py
21
runtests.py
|
@ -1,11 +1,11 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import pytest
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
PYTEST_ARGS = {
|
PYTEST_ARGS = {
|
||||||
'default': ['tests', '--tb=short'],
|
'default': ['tests', '--tb=short'],
|
||||||
|
@ -14,6 +14,7 @@ PYTEST_ARGS = {
|
||||||
|
|
||||||
FLAKE8_ARGS = ['rest_framework', 'tests', '--ignore=E501']
|
FLAKE8_ARGS = ['rest_framework', 'tests', '--ignore=E501']
|
||||||
|
|
||||||
|
ISORT_ARGS = ['--recursive', '--check-only', '.']
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
@ -30,6 +31,13 @@ def flake8_main(args):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def isort_main(args):
|
||||||
|
print('Running isort code checking')
|
||||||
|
ret = subprocess.call(['isort'] + args)
|
||||||
|
print('isort failed' if ret else 'isort passed')
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def split_class_and_function(string):
|
def split_class_and_function(string):
|
||||||
class_string, function_string = string.split('.', 1)
|
class_string, function_string = string.split('.', 1)
|
||||||
return "%s and %s" % (class_string, function_string)
|
return "%s and %s" % (class_string, function_string)
|
||||||
|
@ -50,8 +58,10 @@ if __name__ == "__main__":
|
||||||
sys.argv.remove('--nolint')
|
sys.argv.remove('--nolint')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
run_flake8 = True
|
run_flake8 = True
|
||||||
|
run_isort = True
|
||||||
else:
|
else:
|
||||||
run_flake8 = False
|
run_flake8 = False
|
||||||
|
run_isort = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sys.argv.remove('--lintonly')
|
sys.argv.remove('--lintonly')
|
||||||
|
@ -67,6 +77,7 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
style = 'fast'
|
style = 'fast'
|
||||||
run_flake8 = False
|
run_flake8 = False
|
||||||
|
run_isort = False
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
pytest_args = sys.argv[1:]
|
pytest_args = sys.argv[1:]
|
||||||
|
@ -79,7 +90,7 @@ if __name__ == "__main__":
|
||||||
expression = split_class_and_function(first_arg)
|
expression = split_class_and_function(first_arg)
|
||||||
pytest_args = ['tests', '-k', expression] + pytest_args[1:]
|
pytest_args = ['tests', '-k', expression] + pytest_args[1:]
|
||||||
elif is_class(first_arg) or is_function(first_arg):
|
elif is_class(first_arg) or is_function(first_arg):
|
||||||
# `runtests.py TestCase [flags]`
|
# `runtests.py TestCase [flags]`
|
||||||
# `runtests.py test_function [flags]`
|
# `runtests.py test_function [flags]`
|
||||||
pytest_args = ['tests', '-k', pytest_args[0]] + pytest_args[1:]
|
pytest_args = ['tests', '-k', pytest_args[0]] + pytest_args[1:]
|
||||||
else:
|
else:
|
||||||
|
@ -87,5 +98,9 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if run_tests:
|
if run_tests:
|
||||||
exit_on_failure(pytest.main(pytest_args))
|
exit_on_failure(pytest.main(pytest_args))
|
||||||
|
|
||||||
if run_flake8:
|
if run_flake8:
|
||||||
exit_on_failure(flake8_main(FLAKE8_ARGS))
|
exit_on_failure(flake8_main(FLAKE8_ARGS))
|
||||||
|
|
||||||
|
if run_isort:
|
||||||
|
exit_on_failure(isort_main(ISORT_ARGS))
|
||||||
|
|
8
tox.ini
8
tox.ini
|
@ -3,7 +3,7 @@ addopts=--tb=short
|
||||||
|
|
||||||
[tox]
|
[tox]
|
||||||
envlist =
|
envlist =
|
||||||
py27-{flake8,docs},
|
py27-{lint,docs},
|
||||||
{py26,py27}-django14,
|
{py26,py27}-django14,
|
||||||
{py26,py27,py32,py33,py34}-django{15,16},
|
{py26,py27,py32,py33,py34}-django{15,16},
|
||||||
{py27,py32,py33,py34}-django{17,18,master}
|
{py27,py32,py33,py34}-django{17,18,master}
|
||||||
|
@ -22,14 +22,14 @@ deps =
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
-rrequirements/requirements-optionals.txt
|
-rrequirements/requirements-optionals.txt
|
||||||
|
|
||||||
[testenv:py27-flake8]
|
[testenv:py27-lint]
|
||||||
|
commands = ./runtests.py --lintonly
|
||||||
deps =
|
deps =
|
||||||
-rrequirements/requirements-codestyle.txt
|
-rrequirements/requirements-codestyle.txt
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
commands = ./runtests.py --lintonly
|
|
||||||
|
|
||||||
[testenv:py27-docs]
|
[testenv:py27-docs]
|
||||||
|
commands = mkdocs build
|
||||||
deps =
|
deps =
|
||||||
-rrequirements/requirements-testing.txt
|
-rrequirements/requirements-testing.txt
|
||||||
-rrequirements/requirements-documentation.txt
|
-rrequirements/requirements-documentation.txt
|
||||||
commands = mkdocs build
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user