forked from bbrewington/peoria-il-equity-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·66 lines (54 loc) · 1.71 KB
/
setup.sh
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
59
60
61
62
63
64
65
66
#############
# VARIABLES #
#############
# TODO: Change these variables to match your project
VENV_NAME=.venv;
PROJECT_DIR=peoria_dei_data; # Path relative to top-level git directory
REQ_TXT_RELATIVE_PATH=../requirements.txt; # Path relative to PROJECT_DIR
############
# OVERVIEW #
############
# This script will create a virtual environment for your project and install the packages listed in requirements.txt
# It works on both Windows and Unix-based systems (Linux, MacOS, etc.)
# Folder structure:
# - top-level git directory
# - setup.sh
# - requirements.txt <-- example...see comment on REQ_TXT_RELATIVE_PATH above
# - project_dir
# - .venv
########
# CODE #
########
# Set working directory
cd $(git rev-parse --show-toplevel)/$PROJECT_DIR;
# Create .gitignore if doesn't exist
if [[ ! -e .gitignore ]]; then
touch .gitignore;
fi
# Deactivate virtual environment if currently active
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo 'deactivating Virtual Env';
deactivate;
fi
# Set platform-specific subdir (handles if running this on Windows)
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
VENV_SUBDIR="Scripts";
PYTHON_EXEC=python;
else
VENV_SUBDIR="bin";
PYTHON_EXEC=python3;
fi
# Make sure VENV_NAME is in .gitignore
if grep -q "^$VENV_NAME" .gitignore; then
echo "Virtual environment already in .gitignore";
else
echo $VENV_NAME >> .gitignore;
fi
# Create virtual environment & activate it
$PYTHON_EXEC -m venv $VENV_NAME;
source "$VENV_NAME/$VENV_SUBDIR/activate";
$PYTHON_EXEC -m pip install --upgrade pip;
pip install -r $REQ_TXT_RELATIVE_PATH;
# Add virtual environment to Jupyter Kernel
pip install ipykernel
$PYTHON_EXEC -m ipykernel install --user --name=$VENV_NAME