diff options
Diffstat (limited to 'isort-rpi')
-rwxr-xr-x | isort-rpi | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/isort-rpi b/isort-rpi new file mode 100755 index 000000000000..03c64d21a759 --- /dev/null +++ b/isort-rpi @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +# This script is a wrapper for reorder-python-imports that emulates +# `isort --diff`, because that command is used by: +# +# - pyright : https://github.com/microsoft/pyright +# - ms-python.python vscode extension +# - coc-pyright neovim extension +# +# For all of these extensions, just add the following setting: +# "python.sortImports.path": "isort-rpi", +# +# The script detects if the first argument is --diff, in which case it +# generates a diff output with the import order changes. + +if ! command -v reorder-python-imports &>/dev/null; then + echo "reorder-python-imports can't be found." 1>&2 + exit 1 +fi + +if [ "$1" = "--diff" ]; then + shift + filename=$1 + shift + printf '%s %s\n+++ %s\n' "---" "$filename" "$filename" + diff -u "$filename" \ + <(reorder-python-imports \ + "$@" \ + - <"$filename" || true) \ + | tail +3 +else + reorder-python-imports "$@" +fi |