From f2eacd366041a25f580fe1558e968698edef7feb Mon Sep 17 00:00:00 2001 From: Rizwan Mansuri Date: Sat, 13 Apr 2019 11:22:29 +0100 Subject: [PATCH] Black configuration --- requirements/requirements-codestyle.txt | 3 +++ runtests.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/requirements/requirements-codestyle.txt b/requirements/requirements-codestyle.txt index 8cbd41c50..2b7bad436 100644 --- a/requirements/requirements-codestyle.txt +++ b/requirements/requirements-codestyle.txt @@ -5,3 +5,6 @@ pycodestyle==2.3.1 # Sort and lint imports isort==4.3.3 + +# black +black==19.3b0 \ No newline at end of file diff --git a/runtests.py b/runtests.py index 16b47ce2a..4dc475375 100755 --- a/runtests.py +++ b/runtests.py @@ -15,6 +15,8 @@ FLAKE8_ARGS = ['rest_framework', 'tests'] ISORT_ARGS = ['--recursive', '--check-only', '--diff', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests'] +BLACK_ARGS = ['--check', '--verbose'] + def exit_on_failure(ret, message=None): if ret: @@ -40,6 +42,17 @@ def isort_main(args): return ret +def black_main(args): + print('Running black code checking') + ret = subprocess.call(['black', '.'] + args) + + if ret: + print('black failed: Some code have incorrectly formatted. Fix by running `black .`') + else: + print('black passed') + + return ret + def split_class_and_function(string): class_string, function_string = string.split('.', 1) return "%s and %s" % (class_string, function_string) @@ -59,9 +72,11 @@ if __name__ == "__main__": try: sys.argv.remove('--nolint') except ValueError: + run_black = True run_flake8 = True run_isort = True else: + run_black = False run_flake8 = False run_isort = False @@ -78,6 +93,7 @@ if __name__ == "__main__": style = 'default' else: style = 'fast' + run_black = False run_flake8 = False run_isort = False @@ -117,3 +133,6 @@ if __name__ == "__main__": if run_isort: exit_on_failure(isort_main(ISORT_ARGS)) + + if run_black: + exit_on_failure(black_main(BLACK_ARGS))