Skip to content

Move isort/lint commands out of test runner #5819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .isort.cfg

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ matrix:
- { python: "3.6", env: DJANGO=master }
- { python: "3.6", env: DJANGO=1.11 }
- { python: "3.6", env: DJANGO=2.0 }
- { python: "2.7", env: TOXENV=lint }
- { python: "3.6", env: "TOXENV=isort,lint" }
- { python: "2.7", env: TOXENV=docs }

- python: "3.6"
Expand Down
49 changes: 1 addition & 48 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python
from __future__ import print_function

import subprocess
import sys

import pytest
Expand All @@ -11,35 +10,12 @@
'fast': ['tests', '--tb=short', '-q', '-s', '-rw'],
}

FLAKE8_ARGS = ['rest_framework', 'tests']

ISORT_ARGS = ['--recursive', '--check-only', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests']


def exit_on_failure(ret, message=None):
if ret:
sys.exit(ret)


def flake8_main(args):
print('Running flake8 code linting')
ret = subprocess.call(['flake8'] + args)
print('flake8 failed' if ret else 'flake8 passed')
return ret


def isort_main(args):
print('Running isort code checking')
ret = subprocess.call(['isort'] + args)

if ret:
print('isort failed: Some modules have incorrectly ordered imports. Fix by running `isort --recursive .`')
else:
print('isort passed')

return ret


def split_class_and_function(string):
class_string, function_string = string.split('.', 1)
return "%s and %s" % (class_string, function_string)
Expand All @@ -56,22 +32,6 @@ def is_class(string):


if __name__ == "__main__":
try:
sys.argv.remove('--nolint')
except ValueError:
run_flake8 = True
run_isort = True
else:
run_flake8 = False
run_isort = False

try:
sys.argv.remove('--lintonly')
except ValueError:
run_tests = True
else:
run_tests = False

try:
sys.argv.remove('--fast')
except ValueError:
Expand Down Expand Up @@ -110,11 +70,4 @@ def is_class(string):
else:
pytest_args = PYTEST_ARGS[style]

if run_tests:
exit_on_failure(pytest.main(pytest_args))

if run_flake8:
exit_on_failure(flake8_main(FLAKE8_ARGS))

if run_isort:
exit_on_failure(isort_main(ISORT_ARGS))
exit_on_failure(pytest.main(pytest_args))
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ license_file = LICENSE.md
[flake8]
ignore = E501
banned-modules = json = use from rest_framework.utils import json!

[isort]
skip = .tox
atomic = true
multi_line_output = 5
known_standard_library = types
known_third_party = pytest,_pytest,django
known_first_party = rest_framework
11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ deps =
-rrequirements/requirements-testing.txt
-rrequirements/requirements-optionals.txt

[testenv:isort]
commands = isort --recursive --check-only rest_framework tests {posargs}
deps =
-rrequirements/requirements-codestyle.txt

[testenv:lint]
basepython = python2.7
commands = ./runtests.py --lintonly
commands = flake8 rest_framework tests {posargs}
deps =
-rrequirements/requirements-codestyle.txt
-rrequirements/requirements-testing.txt
-rrequirements/requirements-codestyle.txt

[testenv:docs]
basepython = python2.7
Expand Down