| #!/usr/bin/env bash |
| |
| # This script sets up a Python virtualenv for the Web UI. This creates |
| # a new virtualenv and installs nodeenv inside the virtualenv. |
| |
| set -e |
| trap "exit 1" INT |
| |
| CURRDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| |
| : ${VIRTUALENV_NAME:="linters"} |
| : ${VIRTUALENV_DIRECTORY:="${CURRDIR}/.virtualenv"} |
| |
| : ${PYTHON:="$(which python)"} |
| : ${VIRTUALENV:="$(which virtualenv)"} |
| |
| OLD_PYTHONPATH="${PYTHONPATH}" |
| PYTHONPATH="" |
| |
| # If we already have a virtual environment activated, |
| # bail out and advise the user to deactivate. |
| OLD_VIRTUAL_ENV="${VIRTUAL_ENV}" |
| if [ "${OLD_VIRTUAL_ENV}" != "" ]; then |
| echo "Please deactivate your current virtual environment in order to continue." |
| echo "source deactivate" |
| exit 1 |
| fi |
| |
| # Verify that python is installed. |
| if [ "${PYTHON}" = "" ]; then |
| echo "You must have python installed in order to continue." |
| exit 1 |
| fi |
| |
| # Old versions of virtualenv do not remove the bin directory in the |
| # virtual environment even when using `--clear`. We thus remove the |
| # entire directory in case the virtual environment already exists. |
| # See https://github.com/pypa/virtualenv/issues/2 for more info. |
| rm -rf ${VIRTUALENV_DIRECTORY} |
| |
| PYTHON_MAJOR=$(${PYTHON} -c 'import sys; print(sys.version_info[0])') |
| PYTHON_MINOR=$(${PYTHON} -c 'import sys; print(sys.version_info[1])') |
| |
| if [ "${PYTHON_MAJOR}" = "3" ]; then |
| if [ "${PYTHON_MINOR}" -lt "6" ]; then |
| echo "You must be running python 3.6 or newer in order to continue." |
| echo "Consider running as 'PYTHON=python3 ${0}' or similar." |
| exit 1 |
| else |
| # Set up a virtual environment for the linters. |
| ${PYTHON} -m venv --prompt="${VIRTUALENV_NAME}" ${VIRTUALENV_DIRECTORY} |
| fi |
| else |
| echo "You must be running python 3.6 or newer in order to continue." |
| echo "Consider running as 'PYTHON=python3 ${0}' or similar." |
| exit 1 |
| fi |
| |
| source ${VIRTUALENV_DIRECTORY}/bin/activate |
| pip install --upgrade pip |
| pip install -r ${CURRDIR}/pip-requirements.txt |
| |
| # Add Node.js virtual environment to the existing virtual environment. |
| nodeenv -p |
| |
| # Restart the virtual environment to then have npm available. |
| deactivate |
| source ${VIRTUALENV_DIRECTORY}/bin/activate |
| |
| # Install the JavaScript linter in the virtual environment. |
| npm install -g eslint@5.1.0 |
| deactivate |