From 66ae47d1002edca10faa464105b40da5da0d17b9 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 7 Feb 2018 14:43:45 -0500 Subject: [PATCH 1/2] Move isort conf into setup.cfg --- .isort.cfg | 7 ------- setup.cfg | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index fd9c67a97..000000000 --- a/.isort.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[settings] -skip=.tox -atomic=true -multi_line_output=5 -known_standard_library=types -known_third_party=pytest,_pytest,django -known_first_party=rest_framework diff --git a/setup.cfg b/setup.cfg index aa34f62b7..5f687f85b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 From fa2392e0b2da8e629c0362a299fb138be402b015 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 7 Feb 2018 14:44:10 -0500 Subject: [PATCH 2/2] Move isort/lint commands out of test runner --- .travis.yml | 2 +- runtests.py | 49 +------------------------------------------------ tox.ini | 13 ++++++++----- 3 files changed, 10 insertions(+), 54 deletions(-) diff --git a/.travis.yml b/.travis.yml index f503eb5e1..397be0359 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/runtests.py b/runtests.py index d0e22a967..c877c6b18 100755 --- a/runtests.py +++ b/runtests.py @@ -1,7 +1,6 @@ #! /usr/bin/env python from __future__ import print_function -import subprocess import sys import pytest @@ -11,35 +10,12 @@ PYTEST_ARGS = { '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) @@ -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: @@ -110,11 +70,4 @@ if __name__ == "__main__": 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)) diff --git a/tox.ini b/tox.ini index d48d79be6..76a6771ec 100644 --- a/tox.ini +++ b/tox.ini @@ -37,12 +37,15 @@ deps = -rrequirements/requirements-testing.txt -rrequirements/requirements-optionals.txt -[testenv:lint] -basepython = python2.7 -commands = ./runtests.py --lintonly +[testenv:isort] +commands = isort --recursive --check-only rest_framework tests {posargs} deps = - -rrequirements/requirements-codestyle.txt - -rrequirements/requirements-testing.txt + -rrequirements/requirements-codestyle.txt + +[testenv:lint] +commands = flake8 rest_framework tests {posargs} +deps = + -rrequirements/requirements-codestyle.txt [testenv:docs] basepython = python2.7