2019-02-27 22:20:29 +01:00
#!/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.
#
2020-02-23 13:50:27 -05:00
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2019-02-27 22:20:29 +01:00
2019-03-29 11:23:52 +01:00
# 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:-}"
}
2019-11-15 21:58:51 +01:00
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}"
}
2019-02-28 21:15:14 +01:00
(
# 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
2019-02-27 22:20:29 +01:00
2019-02-28 21:15:14 +01:00
check() {
echo Checking: $@
$@ >/dev/null 2>&1
}
NO_FORCE_INSTALL=true
2019-02-27 22:20:29 +01:00
2019-11-15 21:58:51 +01:00
while getopts 'fSh' OPTION
2019-02-28 21:15:14 +01:00
do
case "$OPTION" in
f)
NO_FORCE_INSTALL=false
;;
2019-11-15 21:58:51 +01:00
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
2019-02-28 21:15:14 +01:00
esac
done
2019-02-27 22:20:29 +01:00
2019-02-28 21:15:14 +01:00
check python3 --version || {
echo "==> Python 3.x not found"
exit 1
}
2019-02-27 22:20:29 +01:00
2019-02-28 21:15:14 +01:00
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
}
2019-02-27 22:20:29 +01:00
2019-02-28 21:15:14 +01:00
PYTHON_VER="$(python3 --version | sed 's/^Python \([0-9]\.[0-9]\).[0-9]$/\1/')"
2019-02-27 22:20:29 +01:00
2020-02-23 13:50:27 -05:00
test -d $SCRIPT_DIR/.venv || {
2019-02-28 21:15:14 +01:00
echo "Setting up a virtual env for Gaphor..."
2020-02-23 13:50:27 -05:00
python3 -m venv --prompt Gaphor ${VENV_OPTS:-} $SCRIPT_DIR/.venv
2019-02-27 22:20:29 +01:00
}
2020-02-23 13:50:27 -05:00
source $SCRIPT_DIR/.venv/bin/activate
2019-02-28 21:15:14 +01:00
2020-02-23 13:50:27 -05:00
{ ${NO_FORCE_INSTALL} && test -f $SCRIPT_DIR/.venv/lib/python${PYTHON_VER}/site-packages/gaphor.egg-link; } || {
2019-02-28 21:15:14 +01:00
echo "Installing Gaphor in the virtualenv..."
2019-04-27 23:40:04 +02:00
2020-02-23 12:41:43 -05:00
# Use 1.0.0b7 until https://github.com/python-poetry/poetry/issues/1880 is fixed
pip install --upgrade poetry==1.0.0b7
poetry config virtualenvs.create false
2019-10-27 10:37:12 -04:00
poetry install
2019-02-28 21:15:14 +01:00
}
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"
2019-02-27 22:20:29 +01:00
2019-02-28 21:15:14 +01:00
test_module \
"import gaphor.UML" \
"Gaphor was not installed properly, that should not have happened. Please open an issue on GitHub"
2019-02-27 22:20:29 +01:00
2020-02-23 13:50:27 -05:00
) && source $SCRIPT_DIR/.venv/bin/activate