improvements to init.sh: more robust python setup stuff

This commit is contained in:
Rasmus Andersson 2018-08-28 08:49:45 -07:00
parent 97ae311709
commit 5ecf53902e

68
init.sh
View file

@ -31,10 +31,15 @@ else
if [[ "$1" == "-h" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "--help" ]]; then if [[ "$1" == "-h" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "--help" ]]; then
echo "usage: $0 [options]" >&2 echo "usage: $0 [options]" >&2
echo "options:" >&2 echo "options:" >&2
echo " -f Force generation of build/etc/generated.make" >&2 echo " -clean Start from scratch" >&2
exit 1 exit 1
fi fi
clean=false
if [[ "$1" == "-clean" ]]; then
clean=true
fi
# ———————————————————————————————————————————————————————————————————————————————————————————————— # ————————————————————————————————————————————————————————————————————————————————————————————————
# virtualenv # virtualenv
@ -50,19 +55,41 @@ else
VENV_ACTIVE=true VENV_ACTIVE=true
fi fi
if ! (which virtualenv >/dev/null); then require_virtualenv() {
echo "$0: Can't find virtualenv in PATH -- install through 'pip install --user virtualenv'" >&2 # find pip
exit 1 export pip=$(which pip2)
fi if [ "$pip" = "" ]; then
export pip=$(which pip)
fi
echo "using pip: $pip $(pip --version)"
if [ "$pip" = "" ]; then
echo "Pip for Python 2 not found (tried pip and pip2 in PATH)" >&2
exit 1
elif ! ($pip --version 2>&1 | grep -q 'ython 2'); then
echo "Pip for Python 2 not found (found pip for different python version)" >&2
exit 1
fi
# find virtualenv
if ! ($pip show virtualenv >/dev/null); then
echo "$0: Can't find virtualenv -- install through '$pip install --user virtualenv'" >&2
exit 1
fi
virtualenv_pkgdir=$($pip show virtualenv | grep Location | cut -d ' ' -f 2)
export virtualenv="$(dirname "$(dirname "$(dirname "$virtualenv_pkgdir")")")/bin/virtualenv"
echo "using virtualenv: $virtualenv"
}
# TODO: allow setting a flag to recreate venv
# rm -rf "$VENV_DIR"
if [[ ! -d "$VENV_DIR/bin" ]]; then if [[ ! -d "$VENV_DIR/bin" ]]; then
echo "Setting up virtualenv in '$VENV_DIR'" echo "Setting up virtualenv in '$VENV_DIR'"
virtualenv "$VENV_DIR" require_virtualenv
else $virtualenv "$VENV_DIR"
if [[ ! -z $VIRTUAL_ENV ]] && [[ "$VIRTUAL_ENV" != "$VENV_DIR_ABS" ]]; then elif [[ ! -z $VIRTUAL_ENV ]] && [[ "$VIRTUAL_ENV" != "$VENV_DIR_ABS" ]]; then
echo "Looks like the repository has moved location -- updating virtualenv" echo "Looks like the repository has moved location -- updating virtualenv"
virtualenv "$VENV_DIR" require_virtualenv
fi $virtualenv "$VENV_DIR"
fi fi
source "$VENV_DIR/bin/activate" source "$VENV_DIR/bin/activate"
@ -162,8 +189,17 @@ else
DIR=$1 DIR=$1
REF_FILE=$DIR/$2 REF_FILE=$DIR/$2
set -e set -e
if [ ! -f "$REF_FILE" ] || has_newer "$DIR" "$REF_FILE"; then if $clean || [ ! -f "$REF_FILE" ] || has_newer "$DIR" "$REF_FILE"; then
pushd "$DIR" >/dev/null pushd "$DIR" >/dev/null
if $clean; then
find . \
-type f \
-name '*.c' -or \
-name '*.o' -or \
-name '*.pyc' -or \
-name '*.pyo' \
| xargs rm
fi
if [ -f requirements.txt ]; then if [ -f requirements.txt ]; then
pip install -r requirements.txt pip install -r requirements.txt
fi fi
@ -184,6 +220,10 @@ else
# create and mount spare disk image needed on macOS to support case-sensitive filenames # create and mount spare disk image needed on macOS to support case-sensitive filenames
if [[ "$(uname)" = *Darwin* ]]; then if [[ "$(uname)" = *Darwin* ]]; then
bash misc/mac-tmp-disk-mount.sh bash misc/mac-tmp-disk-mount.sh
if $clean; then
echo "[clean] rm -rf '$BUILD_TMP_DIR'/*"
rm -rf "$BUILD_TMP_DIR"/*
fi
else else
mkdir -p "$BUILD_TMP_DIR" mkdir -p "$BUILD_TMP_DIR"
fi fi
@ -209,9 +249,7 @@ else
# Only generate if there are changes to the font sources # Only generate if there are changes to the font sources
NEED_GENERATE=false NEED_GENERATE=false
if [[ "$1" == "-f" ]]; then if $clean || [[ ! -f "$GEN_MAKE_FILE" ]] || [[ "$0" -nt "$GEN_MAKE_FILE" ]]; then
NEED_GENERATE=true
elif [[ ! -f "$GEN_MAKE_FILE" ]] || [[ "$0" -nt "$GEN_MAKE_FILE" ]]; then
NEED_GENERATE=true NEED_GENERATE=true
else else
for style in "${master_styles[@]}"; do for style in "${master_styles[@]}"; do