This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·86 lines (64 loc) · 2.15 KB
/
install.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
#!/bin/sh
# Installs PyVism locally in a virtual environment along its dependencies.
PY_MIN_SUPPORTED="11"
python_bin="python3"
. ./utils.sh
get_python_minor_version() {
python3 -c 'import sys; print(sys.version_info[1])'
}
check_minor_version() {
# $1 = current minor version we're checking
# $2 = threshold ; must be set to the last Python minor version
# $3 = minor version fallback ; must be set to `python3`'s minor version
if [ "${1}" -le "${2}" ]; then
if command -v "python3.$1" > /dev/null 2>&1; then
echo "$1"
else
check_minor_version "$(($1 + 1))" "$2" "$3"
fi
else
echo "$3"
fi
}
check_binary "$python_bin"
py_minor_ver=$($python_bin -c 'import sys; print(sys.version_info[1])')
if [ "${py_minor_ver}" -lt "$PY_MIN_SUPPORTED" ]; then
perror "'python3' version is 3.$py_minor_ver ; PyVism requires 3.11+."
pnewline
max_version_found=$(check_minor_version "$PY_MIN_SUPPORTED" 11 "$py_minor_ver")
if [ "${max_version_found}" -eq "${py_minor_ver}" ]; then
throw_error "The minimum Python version for PyVism is 3.11, but you have 3.${py_minor_ver}" 2
fi
pinfo "Found 'python3.$max_version_found'."
psuccess "PyVism supports it! This binary will be used instead."
pnewline
python_bin="python3.$max_version_found"
fi
if [ -z "${VIRTUAL_ENV}" ]; then
pinfo "Currently not in a virtual environment -- will create it for you!"
check_binary 'virtualenv'
virtualenv .venv --python "$python_bin" >/dev/null
. .venv/bin/activate
else
. "${VIRTUAL_ENV}/bin/activate"
fi
pnewline
pinfo 'Installing dependencies...'
pip install -r requirements.txt >/dev/null 2>&1
psuccess 'Dependencies installed.'
pinfo 'Installing PyVism...'
if ! pip install -e . > /dev/null 2>&1; then
throw_error 'An error occurred with pip during PyVism installation.' 2
fi
psuccess 'PyVism installed locally.'
pnewline
cat <<EOF > "$VIRTUAL_ENV/bin/vism"
#!/usr/bin/env $python_bin
# Generated from install.sh
from pyvism.cli import main
if __name__ == "__main__":
raise SystemExit(main())
EOF
chmod u+x "$VIRTUAL_ENV/bin/vism"
psuccess 'PyVism is now installed in the virtual environment.'
pinfo 'The command is accessible by typing "vism" inside the virtual environment.'