common_utils.sh 1.53 KB
Newer Older
1
2
3
4
#!/bin/bash
# Utilities for both OSX and Docker
set -e

5
6
7
# Get our own location on this filesystem
MULTIBUILD_DIR=$(dirname "${BASH_SOURCE[0]}")

8
9
10
11
function abspath {
    python -c "import os.path; print(os.path.abspath('$1'))"
}

12
13
14
15
16
function relpath {
    # Path of first input relative to second (or $PWD if not specified)
    python -c "import os.path; print(os.path.relpath('$1','${2:-$PWD}'))"
}

Matthew Brett's avatar
Matthew Brett committed
17
18
19
20
function realpath {
    python -c "import os; print(os.path.realpath('$1'))"
}

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function get_root {
    abspath $MULTIBUILD_DIR/..
}

function lex_ver {
    # Echoes dot-separated version string padded with zeros
    # Thus:
    # 3.2.1 -> 003002001
    # 3     -> 003000000
    echo $1 | awk -F "." '{printf "%03d%03d%03d", $1, $2, $3}'
}

function is_function {
    set +e
    $(declare -Ff "$1") > /dev/null && echo true
    set -e
}

function clean_fix_source {
    git checkout $1
    git clean -fxd
    git reset --hard
    git submodule update --init --recursive
    if [ -n $(is_function "patch_source") ]; then patch_source; fi
}
46
47
48
49
50
51
52
53

function install_wheel {
    # Install test dependencies and built wheel
    # Pass any input flags to pip install steps
    # Depends on:
    #     MANYLINUX_URL
    #     WHEEL_SDIR
    #     TEST_DEPENDS  (optional)
54
    local wheelhouse=$(get_root)/$WHEEL_SDIR
55
56
57
58
59
    if [ -n "$TEST_DEPENDS" ]; then
        pip install --find-links $MANYLINUX_URL $@ $TEST_DEPENDS
    fi
    # Install compatible wheel
    pip install --find-links $MANYLINUX_URL $@ \
60
        $(python $MULTIBUILD_DIR/supported_wheels.py $wheelhouse/*.whl)
61
}