-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·172 lines (149 loc) · 4.83 KB
/
build.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
init_vars() {
if command -v python3 > /dev/null; then
PYTHON=python3
elif command -v python > /dev/null; then
PYTHON=python
else
command python3
fi
PROJECT_BASEDIR=$(realpath "$(dirname "$0")")
VERSION="$("$PYTHON" -c 'import platform; print(platform.python_version())')"
PYTHON_VERSION_NUM=$(echo "$VERSION" | awk -F'.' '{print $1$2}')
if [ "${PYTHON_VERSION_NUM}" == "39" ]; then
DIST_EXECUTOR_MD5="c349b0bb78cd162412aaaa121f828e4a"
DOWNLOAD_PATH="https://mindpandas.obs.cn-north-4.myhuaweicloud.com/latest/py39/dist_executor.tar.gz"
elif [ "${PYTHON_VERSION_NUM}" == "38" ]; then
DIST_EXECUTOR_MD5="aa34d8dae4e2b84ce7a33285fd299da8"
DOWNLOAD_PATH="https://mindpandas.obs.cn-north-4.myhuaweicloud.com/latest/py38/dist_executor.tar.gz"
fi
}
rename_wheel() {
cd "$PROJECT_BASEDIR/output" || exit
PACKAGE_LIST=$(ls mindpandas-*-any.whl) || exit
for PACKAGE_ORIG in $PACKAGE_LIST; do
MINDPANDAS_VERSION=$(echo "$PACKAGE_ORIG" | awk -F'-' '{print $2}')
PYTHON_VERSION_TAG="cp$PYTHON_VERSION_NUM"
PYTHON_ABI_TAG="cp$(python3-config --extension-suffix | awk -F'-' '{print $2}')"
MACHINE_TAG="$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m)"
PACKAGE_NEW="mindpandas-$MINDPANDAS_VERSION-$PYTHON_VERSION_TAG-$PYTHON_ABI_TAG-$MACHINE_TAG.whl"
mv "$PACKAGE_ORIG" "$PACKAGE_NEW"
done
}
write_checksum() {
cd "$PROJECT_BASEDIR/output" || exit
PACKAGE_LIST=$(ls mindpandas-*.whl) || exit
for PACKAGE_NAME in $PACKAGE_LIST; do
sha256sum -b "$PACKAGE_NAME" >"$PACKAGE_NAME.sha256"
done
}
solve_dependency() {
echo "Solving Dependency"
if [[ "${BUILD_LOCAL}" != "True" ]]; then
# Download for user
solved=0
if [ -e "dist_executor.tar.gz" ]; then
executor_md5=$(md5sum dist_executor.tar.gz |awk -F ' ' '{print $1}')
if [ "${executor_md5}" == "${DIST_EXECUTOR_MD5}" ]; then
echo "dist_executor md5: ${executor_md5}"
solved=1
else
echo "dist_executor md5 mismatch"
rm dist_executor.tar.gz
fi
fi
if [ ${solved} -ne 1 ]; then
echo "Downloading dependency"
wget ${DOWNLOAD_PATH}
fi
fi
if [ -d mindpandas/dist_executor ];then
rm -rf mindpandas/dist_executor
fi
tar -xzf dist_executor.tar.gz -C mindpandas/
chmod +wx -R mindpandas/dist_executor
}
clean_files() {
cd "$PROJECT_BASEDIR" || exit
rm -rf build/
rm -rf mindpandas.egg-info
rm -rf dist_executor.tar.gz
rm -rf mindpandas/dist_executor
}
build_wheel() {
cd "$PROJECT_BASEDIR" || exit
if [ $# -gt 0 ]; then
if [ "$1" = "clean" ]; then
echo "start cleaning mindpandas"
clean_files
echo "clean mindpandas done"
exit
elif [[ "${BUILD_LOCAL}" = "True" ]]; then
echo "use existing dist_executor.tar.gz"
else
echo "unknown command: $1"
exit
fi
fi
echo "start building mindpandas"
if ! "$PYTHON" -c 'import sys; assert sys.version_info.major == 3 and sys.version_info.minor in {8, 9}' > /dev/null; then
echo "Python 3.8 or 3.9 is required. You are running $("$PYTHON" -V)"
exit 1
fi
rm -rf output
solve_dependency
"$PYTHON" setup.py bdist_wheel
if [ ! -x "dist" ]; then
echo "Build failed"
exit 1
fi
mv dist output
rename_wheel
write_checksum
clean_files
echo "Build success, output directory is: $PROJECT_BASEDIR/output"
}
show_usage() {
echo "Build mindpandas"
echo ""
echo "usage: build.sh [-hl] [clean]"
echo ""
echo "options:"
echo " -h show this help message and exit"
echo " -l build with local dist_executor"
echo " clean clean build files"
}
check_opts() {
while getopts 'hl' OPT; do
case "$OPT" in
h)
show_usage
exit 0
;;
l)
BUILD_LOCAL="True"
;;
\?)
show_usage
exit 1
;;
esac
done
}
check_opts "$@"
init_vars
build_wheel "$@"