From 48e55875fe695a1c9655d95df093ec896e7becd8 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 7 Jan 2020 16:04:54 -0800 Subject: [PATCH] lint: Run isort as a linter. With a change to increase the line length to 100 characters by tabbott. Fixes #2665. Signed-off-by: Anders Kaseorg --- .isort.cfg | 2 +- tools/lint | 3 +++ tools/run-isort | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100755 tools/run-isort diff --git a/.isort.cfg b/.isort.cfg index dc8638df4f..a58ddc8a8d 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -3,4 +3,4 @@ multi_line_output = 3 known_third_party = netifaces include_trailing_comma = True use_parentheses = True -line_length = 88 +line_length = 100 diff --git a/tools/lint b/tools/lint index 2c379c83e5..0b5801e3d3 100755 --- a/tools/lint +++ b/tools/lint @@ -89,6 +89,9 @@ def run() -> None: linter_config.external_linter('gitlint', ['tools/commit-message-lint'], description="Checks commit messages for common formatting errors." "(config: .gitlint)") + linter_config.external_linter('isort', ['tools/run-isort'], ['py'], + description="Sorts Python import statements", + fix_arg='--fix') semgrep_command = ["semgrep", "--config=./tools/semgrep.yml", "--error", # This option is dangerous in the context of running diff --git a/tools/run-isort b/tools/run-isort new file mode 100755 index 0000000000..016521891a --- /dev/null +++ b/tools/run-isort @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +if [ "$1" = "--fix" ]; then + shift + exec isort "$@" +else + exec isort --check-only --diff "$@" +fi