diff options
author | Andrej Radovic | 2021-11-24 13:05:00 +0100 |
---|---|---|
committer | Andrej Radovic | 2021-11-24 13:05:31 +0100 |
commit | 614709cc0101c15438ccc2b2111cbe5b5ec19263 (patch) | |
tree | dec3df10f4dfb80de83141b8ee68f8fef55f8f19 | |
download | aur-python-reorder-python-imports-isort-wrapper.tar.gz |
Initial commit
-rw-r--r-- | .SRCINFO | 12 | ||||
-rw-r--r-- | PKGBUILD | 16 | ||||
-rwxr-xr-x | isort-rpi | 34 |
3 files changed, 62 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..7950e798b976 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,12 @@ +pkgbase = python-reorder-python-imports-isort-wrapper + pkgdesc = Wrapper for `reorder-python-imports` to emulate isort --diff for \ vscode python plugin and coc-pyright + pkgver = 0.1.0 + pkgrel = 1 + arch = any + license = MIT + depends = bash + depends = python-reorder-python-imports + source = isort-rpi + sha256sums = 7be3f2734f989607894d03697a79e7f212313ae70fd18b06d3abe77a4e1f8b6c + +pkgname = python-reorder-python-imports-isort-wrapper diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..f096dc3db65b --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,16 @@ +# Maintainer: Andrej Radović <r.andrej@gmail.com> +pkgname='python-reorder-python-imports-isort-wrapper' +pkgver=0.1.0 +pkgrel=1 +pkgdesc='Wrapper for `reorder-python-imports` to emulate isort --diff for \ +vscode python plugin and coc-pyright' +depends=('bash' 'python-reorder-python-imports') +license=('MIT') +arch=('any') +source=('isort-rpi') +sha256sums=('7be3f2734f989607894d03697a79e7f212313ae70fd18b06d3abe77a4e1f8b6c') + +package() { + cd "$srcdir" + install -Dm755 isort-rpi -t "$pkgdir"/usr/bin/ +} 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 |