From 16de4f829e2d99191bf70511e76cadc17144fd83 Mon Sep 17 00:00:00 2001 From: Devon Mackay Date: Fri, 6 Jul 2018 13:08:02 -0400 Subject: [PATCH] Add file to contain functions used by setup --- script/include/setup_functions.inc.sh | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 script/include/setup_functions.inc.sh diff --git a/script/include/setup_functions.inc.sh b/script/include/setup_functions.inc.sh new file mode 100644 index 00000000..7c4a6741 --- /dev/null +++ b/script/include/setup_functions.inc.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# setup_functions.inc.sh: Functions used by the setup script + +install_pipenv() { + exit_code=0 + + # Ensure we are not in a virtual env already + if [ -z "${VIRTUAL_ENV+xxxx}" ]; then + if ! check_pip_for pipenv; then + # pipenv is not installed, so install it + echo "Installing pipenv..." + pip install pipenv + # Capture pip exit code + exit_code="${?}" + fi + fi + + return "${exit_code}" +} + +create_virtual_environment() { + default_python_version=3.6 + # Parse out the required Python version from the Pipfile + python_version=$(grep python_version ./Pipfile | cut -d '"' -f 2) + + # If we ended up with an empty string for the required Python version, + # specify the default version + if [ -z "${python_version}" ]; then + python_version="${default_python_version}" + fi + + # Create a new virtual environment for the app + # The environment will be in a directory called .venv off the app + # root directory + echo "Creating virtual environment using Python version ${python_version}..." + return $(PIPENV_VENV_IN_PROJECT=true pipenv --python "${python_version}") +} + +install_sass() { + if ! type sass >/dev/null; then + if type gem >/dev/null; then + echo 'Installing a sass compiler (gem)...' + gem install sass + else + echo 'Could not install a sass compiler. Please install a version of sass.' + fi + fi +}