-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
64 lines (50 loc) · 2.45 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
# Build individual executables (self contained files).
# Build in the following order: __init__, utils, base, files, awk, scripts.
# This allows copying of scripts directly to user's ~/bin/ even if only internal
# network access is allowed and user does not have administrator's privileges.
PACKAGE_PATH=$(pwd)"/tabtools"
BUILD_PATH=$(pwd)"/dist"
build_python_script() {
SCRIPT_FILENAME=$BUILD_PATH/$1 # add prefir 't' to the function name
mkdir -p $BUILD_PATH
echo "#!/usr/bin/env python3" > $SCRIPT_FILENAME
printf '# VERSION: ' >> $SCRIPT_FILENAME
# Original line to extract the version was rewritten without usage of python to run on bare VM (alpine)
# python -c 'from tabtools import __version__; print(__version__)' >> $SCRIPT_FILENAME
grep -o "[0-9]\+,\s\+[0-9]\+,\s\+[0-9]\+" tabtools/__init__.py | sed 's/\,\s\+/\./g' >> $SCRIPT_FILENAME
# Prefix every line in LICENSE with "# "
cat LICENSE | sed "s/^/# /" >> $SCRIPT_FILENAME
# Loop over modules and concatenate their content.
# Remove relative imports as they would be available after concatenation.
for module in '__init__.py' 'utils.py' 'base.py' 'files.py' 'awk.py' 'scripts.py'
do
echo -e "\n#####\n# $module module\n#####" >> $SCRIPT_FILENAME
cat $PACKAGE_PATH/$module \
| grep -vE '^from tabtools import' \
| grep -vE '^from .base import' \
| grep -vE '^from .utils import' \
| grep -vE '^from .files import' \
| grep -vE '^from .awk import' >> $SCRIPT_FILENAME
done
echo -e "\n\nif __name__ == \"__main__\":\n "$1"()" >> $SCRIPT_FILENAME
chmod +x $SCRIPT_FILENAME
}
build_shell_script() {
SCRIPT_FILENAME=$BUILD_PATH/$1
mkdir -p $BUILD_PATH
echo "#!/usr/bin/env sh" > $SCRIPT_FILENAME
printf '# VERSION: ' >> $SCRIPT_FILENAME
# Original line to extract the version was rewritten without usage of python to run on bare VM (alpine)
# python -c 'from tabtools import __version__; print(__version__)' >> $SCRIPT_FILENAME
grep -o "[0-9]\+,\s\+[0-9]\+,\s\+[0-9]\+" tabtools/__init__.py | sed 's/\,\s\+/\./g' >> $SCRIPT_FILENAME
# Prefix every line in LICENSE with "# "
cat LICENSE | sed "s/^/# /" >> $SCRIPT_FILENAME
cat $(pwd)/bin/$1.sh >> $SCRIPT_FILENAME
chmod +x $SCRIPT_FILENAME
}
build_python_script ttmap
build_python_script ttreduce
build_python_script ttsort
build_python_script ttplot
build_shell_script tttail
build_shell_script ttpretty