forked from gaphor/gaphor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
venv
executable file
·104 lines (85 loc) · 2.47 KB
/
venv
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
#!/bin/bash
#
# An easy way to set up a virtualenv.
#
# Source this file to work inside this venv:
#
# source ./venv [-f]
#
# Call `./venv -f` to force a new development installation.
#
# If on Macos with brew, make sure we can find the brewed libffi (which is not "linked"):
echo "Are we on Macos with Homebrew installed?"
brew --version >/dev/null 2>&1 && {
libffi_path="$(brew ls libffi | grep pkgconfig | xargs dirname)"
echo "Adding libffi pkg-config path ${libffi_path} to \$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="${libffi_path}:${PKG_CONFIG_PATH:-}"
}
echo "Are we on MSys (Windows)?"
uname -a | grep -q MSYS_NT && {
export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export PATH="/mingw64/bin:${PATH}"
}
(
# Do the whole installation process in a sub-shell, so we can safely fail when
# this file is sourced in the parent shell.
set -euo pipefail
check() {
echo Checking: $@
$@ >/dev/null 2>&1
}
NO_FORCE_INSTALL=true
while getopts 'fSh' OPTION
do
case "$OPTION" in
f)
NO_FORCE_INSTALL=false
;;
S)
VENV_OPTS="--system-site-packages"
;;
h) echo "Usage: $0 [-f] [-S] [-h] # -f = force install, -S = Use system site packages, -h = this message"
exit 0
esac
done
check python3 --version || {
echo "==> Python 3.x not found"
exit 1
}
check pkg-config --print-errors --exists 'gobject-introspection-1.0 >= 1.46.0' || {
echo "==> GObject-Introspection not found, Please check above errors and correct them"
exit 1
}
PYTHON_VER="$(python3 --version | sed 's/^Python \([0-9]\.[0-9]\).[0-9]$/\1/')"
test -d .venv || {
echo "Setting up a virtual env for Gaphor..."
python3 -m venv --prompt Gaphor ${VENV_OPTS:-} .venv
}
source .venv/bin/activate
{ ${NO_FORCE_INSTALL} && test -f .venv/lib/python${PYTHON_VER}/site-packages/gaphor.egg-link; } || {
echo "Installing Gaphor in the virtualenv..."
pip install -U pip
pip install --upgrade poetry==1.0.2
poetry install
}
test_module() {
python3 -c "$1" 2>&- || {
echo "$2"
echo
echo "The Command used to test this:"
echo
echo " >>> $1"
echo
exit 1
}
}
test_module \
"import gi" \
"PyGobject3 (gobject-introspection) can not be loaded"
test_module \
"from gi.repository import Gtk" \
"Gtk3 is not installed in a way it can be loaded in Python"
test_module \
"import gaphor.UML" \
"Gaphor was not installed properly, that should not have happened. Please open an issue on GitHub"
) && source .venv/bin/activate