-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.sh
More file actions
35 lines (28 loc) · 995 Bytes
/
Copy pathenv.sh
File metadata and controls
35 lines (28 loc) · 995 Bytes
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
#!/usr/bin/env bash
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "Please use 'source $(basename "$0")'"
exit 1
fi
TARGET_DIR="${1:-$(pwd)}"
if [[ ! -d "$TARGET_DIR" ]]; then
echo "Error: Target directory '$TARGET_DIR' does not exist."
return 1
fi
if [[ "$(uname)" != "Darwin" ]] && ! (python3 -m venv --help &>/dev/null); then
echo "Installing python3-venv..."
sudo apt update && sudo apt install -y python3-venv
fi
if [[ ! -d "$TARGET_DIR/env/" ]]; then
echo "Creating virtual environment in $TARGET_DIR/env/ ..."
python3 -m venv "$TARGET_DIR/env/"
fi
if [[ -z "$VIRTUAL_ENV" ]]; then
echo "Activating virtual environment from $TARGET_DIR/env/ ..."
source "$TARGET_DIR/env/bin/activate"
fi
if [[ -f "$TARGET_DIR/requirements.txt" ]]; then
echo "Installing requirements from $TARGET_DIR/requirements.txt ..."
# no internet halts next 2 lines
pip install --upgrade pip
pip install --upgrade -r "$TARGET_DIR/requirements.txt"
fi