summarylogtreecommitdiffstats
path: root/isort-rpi
diff options
context:
space:
mode:
authorAndrej Radovic2021-11-24 13:05:00 +0100
committerAndrej Radovic2021-11-24 13:05:31 +0100
commit614709cc0101c15438ccc2b2111cbe5b5ec19263 (patch)
treedec3df10f4dfb80de83141b8ee68f8fef55f8f19 /isort-rpi
downloadaur-python-reorder-python-imports-isort-wrapper.tar.gz
Initial commit
Diffstat (limited to 'isort-rpi')
-rwxr-xr-xisort-rpi34
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