savkov/randhy

View on GitHub
build.sh

Summary

Maintainability
Test Coverage
#!/bin/bash

# Building packages and uploading them to PyPi
# You can provide the directories containing packages to build (otherwise all directories are processed)

set -e

DIRS="$@"
BASE_DIR=$(pwd)
SETUP="setup.py"

warn() {
    echo "$@" 1>&2
}

die() {
    warn "$@"
    exit 1
}

build() {
    DIR="${1/%\//}"
    echo "Checking directory $DIR"
    cd "$BASE_DIR/$DIR"
    [ ! -e $SETUP ] && warn "No $SETUP file, skipping" && return
    PACKAGE_NAME=$(python $SETUP --fullname)
    echo "Package $PACKAGE_NAME"
    python "$SETUP" sdist bdist_wheel || die "Building package $PACKAGE_NAME failed"
    twine upload -u $PYPI_USER -p $PYPI_PWD *dist/* || die "Uploading package $PACKAGE_NAME failed on file dist/$X"
}

if [ -n "$DIRS" ]; then
    for dir in $DIRS; do
        build $dir
    done
else
    ls -d */ | while read dir; do
        build $dir
    done
fi