format.sh 771 字节
Newer Older
1 2 3 4 5 6 7
#!/usr/bin/env bash
set -e
cd $(dirname $0)/..

ISORT_ARG=""
BLACK_ARG=""

8
while getopts 'dt:' OPT; do
9 10 11 12 13
    case $OPT in
        d)
            ISORT_ARG="--diff --check-only"
            BLACK_ARG="--diff --check"
            ;;
14 15 16
        t)
            TARGET=$OPTARG
            ;;
17 18 19 20 21
        ?)
            echo "Usage: `basename $0` [-d]"
    esac
done

22 23 24 25 26 27 28
if [[ $TARGET ]]; then
    directories=($TARGET)
else
    directories=(megengine test)
    if [[ -d examples ]]; then
        directories+=(examples)
    fi
29
fi
30

31 32
# do not isort megengine/__init__.py file, caused we must
# init library load path before load dependent lib in core
33 34
isort $ISORT_ARG -j $(nproc) -rc "${directories[@]}" -s megengine/__init__.py
black $BLACK_ARG --target-version=py35 -- "${directories[@]}"