forked from d-w-d/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_initial_setup
executable file
·58 lines (44 loc) · 1.95 KB
/
_initial_setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /bin/bash
### Set your environment variables in file '.env' before sourcing this script.
### Source this script before running/working on your python3 project.
### The main logic of this script is placed in the main() function.
### We only want the main function to be called if this script is sourced (not sh-ed);
### (that way we can export environment variables defined herein or in .env)
### This script uses a 'trick' to tell if it's being sourced or sh-ed; see below.
main() {
clear
echo """
=======================================================
Initializing Python Virtual Environment
=======================================================
"""
sleep 1
### 1. Get rid of caches NOT in .venv
find . -type d ! -path './.venv/*' -name '__pycache__' -exec rm -rf {} +
find . -type d ! -path './.venv/*' -name '.pytest_cache' -exec rm -rf {} +
find . -type d ! -path './.venv/*' -name '.pytest_cache' -exec rm -rf {} +
### 2. Load vars defined in .env
source _load_env_vars
### 3. Check for existence of `.venv` dir
if [ ! -d $PWD/.venv ]; then
echo "Virtual Environment Not Found -- Creating '.venv'"
$PYTHON_3_5_OR_HIGHER -m venv .venv
fi
### 4. Activate VENV
source ./.venv/bin/activate
### 5. Install package dependencies for project
if [[ $1 == 'pip' ]]; then
# Specify 'pip' to use pip install
echo "Installing dependencies with pip"
./_pip_install
else
# Default installation is with pipenv
echo "Installing dependencies with pipenv"
PIPENV_VERBOSITY=-1 pipenv install --dev
fi
### 6. Link git pre-commit-hook script
ln -fs $PWD/_precommit_hook $PWD/.git/hooks/pre-commit
}
## Trick to check if this script is being sourced or sh-ed; executes 'main' iff sourced
unset BASH_SOURCE 2>/dev/null
test ".$0" == ".$BASH_SOURCE" && echo "You must <SOURCE> (not SH) this script!!!" || main "$@"