build_amdapy_doc.sh 1.68 KB
#!/bin/bash

SCRIPT=$(readlink -f "$0")
export SCRIPTDIR=$(dirname "$SCRIPT")
export AMDA_IHM="$SCRIPTDIR/.."

GIT_REPOSITORY="https://github.com/cdppirap/amdapy.git"

BUILD_DIR="$AMDA_IHM/scripts/amdapy_doc_build"
PYTHON_VENV="$BUILD_DIR/amdapy_venv"
AMDAPY_PATH="$BUILD_DIR/amdapy"

DST_DIR="$AMDA_IHM/help"

HOSTNAME=`hostname`
if [ "$HOSTNAME" = "cdpp3" ]
then
    GIT_BRANCH="master"
else
    GIT_BRANCH="dev"
fi

mkdir -p "$BUILD_DIR"

if [ -d "$PYTHON_VENV" ]
then
    # Activate virtual env.
    source "$PYTHON_VENV/bin/activate"
else
    # Build & activate virtual env.
    python3.6 -m venv "$PYTHON_VENV"
    source "$PYTHON_VENV/bin/activate"
    pip install --upgrade pip
    pip install pandas numpy lxml matplotlib build sphinx nbsphinx ipython
fi

if [ -d "$AMDAPY_PATH" ]
then
    # Pull repository
    cd $AMDAPY_PATH
    git checkout $GIT_BRANCH
    git pull -c http.sslVerify=0
else
    # Clone repository
    cd $BUILD_DIR
    git clone -c http.sslVerify=0 $GIT_REPOSITORY
    cd $AMDAPY_PATH
    git checkout $GIT_BRANCH
fi

# Package generation
cd $AMDAPY_PATH
python -m build

# Docs generation
cd $AMDAPY_PATH/amdapy/docs
make clean
make html

if [ ! -z "$DST_DIR" ]
then
    # Export docs only if DST_DIR is not empty
    if [ -d "$DST_DIR" ]
    then
        # Does not automatically create DST_DIR to prevent any improper handling
        if [ -d "$DST_DIR/amdapy" ]
        then
            # Cleanup existing HTML dir
            rm -Rf "$DST_DIR/amdapy"
        fi
        cp -R "$AMDAPY_PATH/amdapy/docs/_build/html" "$DST_DIR/amdapy"
    else
        echo "[WARNING] Destination directory not exists ($DST_DIR). Cannot export documentation\n"
    fi
fi

# Deactivate virtual env.
deactivate