-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_pip_package.sh
executable file
·99 lines (73 loc) · 2.11 KB
/
test_pip_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# Test AI Edge Quantizer's pip package and unit tests.
set -e
set -x
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
PYTHON_VERSION="${PYTHON_VERSION:-3.11}"
echo "Testing on Python version ${PYTHON_VERSION}"
function create_venv {
PYENV_ROOT="$(pwd)/pyenv"
if ! git clone https://github.com/pyenv/pyenv.git 2>/dev/null && [ -d "${PYENV_ROOT}" ] ; then
echo "${PYENV_ROOT} exists"
fi
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install -s "${PYTHON_VERSION}"
pyenv global "${PYTHON_VERSION}"
PYTHON_BIN=$(which python)
export PYTHON_BIN
${PYTHON_BIN} -m pip install virtualenv
${PYTHON_BIN} -m virtualenv ai_edge_quantizer_env
source ai_edge_quantizer_env/bin/activate
}
function build_pip_and_install {
# Build and install pip package.
if [[ "${PYTHON_BIN}" == "" ]]; then
echo "python is not available."
exit 1
fi
${PYTHON_BIN} -m pip install --upgrade pip
${PYTHON_BIN} -m pip install build wheel
echo "------ build pip and install -----"
pushd "${SCRIPT_DIR}" > /dev/null
rm -r -f dist # Clean up distributions.
${PYTHON_BIN} setup.py bdist_wheel
local dist_pkg="$(ls dist/${pkg}*.whl)"
${PYTHON_BIN} -m pip install ${dist_pkg?} --ignore-installed
popd > /dev/null
echo
}
function uninstall_pip {
# Uninstall pip package.
echo "------ uninstall pip -----"
local pip_pkg="ai-edge-quantizer"
yes | ${PYTHON_BIN} -m pip uninstall ${pip_pkg}
echo
}
function test_import {
# Test whether import is successful
echo "------ Test import -----"
${PYTHON_BIN} -c "import ai_edge_quantizer"
echo
}
function test_unittest {
echo "=== BEGIN UNIT TESTS ==="
pushd "${SCRIPT_DIR}" > /dev/null
${PYTHON_BIN} -m pip install -r requirements.txt
${PYTHON_BIN} -m unittest discover --pattern *_test.py
popd > /dev/null
echo "=== END UNIT TESTS ==="
echo
echo
}
function test_ai_edge_quantizer {
echo "===== Test AI Edge Quantizer ====="
create_venv
build_pip_and_install
test_import
test_unittest
uninstall_pip
echo
}
test_ai_edge_quantizer
deactivate # deactivate virtualenv.