-
Notifications
You must be signed in to change notification settings - Fork 1
/
venv.sh
executable file
·49 lines (42 loc) · 1.24 KB
/
venv.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
#!/bin/bash
# https://github.com/dubniczky/Shell-Utilities
# Initialize a python virtual environment and install packages
VENV_LIB="venv"
VENV_NAME=".venv"
VENV_DEPS="requirements.txt"
PYTHON_VERSION="3"
# Help
if [ "$1" = "help" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: venv [name?] [version?]"
echo " name: The name of the virtual environment folder. Default: $VENV_NAME"
echo " version: The version of python to use. Default: $PYTHON_VERSION"
exit 0
fi
# Assign parameters
if [ ! -z $1 ]; then
VENV_NAME=$1
fi
if [ ! -z $1 ]; then
PYTHON_VERSION=$1
fi
# Check python installation and create venv
echo "Creating virtual environment... ($VENV_NAME/)"
python$PYTHON_VERSION -m $VENV_LIB "$VENV_NAME"
if [ $? -ne 0 ]; then
echo "Failed to create virtual environment."
exit 1
fi
# Install packages with pip
echo "Installing packages... (/$VENV_DEPS)"
if [ -f "$VENV_DEPS" ]; then
echo "Installing dependencies from requirements file..."
./$VENV_NAME/bin/pip install -r $VENV_DEPS
else
echo "No requirements file found, skipping install."
echo "Created requirements file: $VENV_DEPS"
fi
# Show instructions
echo "Environment loaded!"
echo ""
echo "Activate:"
echo ". $VENV_NAME/bin/activate"