forked from AhmedMostafa16/PrediKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyenv.sh
More file actions
executable file
·120 lines (97 loc) · 2.69 KB
/
Copy pathpyenv.sh
File metadata and controls
executable file
·120 lines (97 loc) · 2.69 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# [ ] Make it crossplatform compatible
print_help() {
echo "Usage: $0 [option] [env_name]"
echo "Options:"
echo " create Create a new virtual environment"
echo " activate Activate the virtual environment"
echo " install Install dependencies from requirements.txt or setup.py"
echo " export Export installed dependencies to requirements.txt within a virtual environment (default name: .venv)"
echo " remove Deactivate and remove the virtual environment"
}
check_virtualenv() {
if ! command -v virtualenv &> /dev/null; then
echo "virtualenv is not installed. Installing..."
python3 -m pip install --user virtualenv
echo "virtualenv installation complete."
fi
}
create_venv() {
# Check if virtualenv is installed, if not, install it
check_virtualenv
local env_name=${1:-".venv"}
if [ -d "$env_name" ]; then
echo "Virtual environment '$env_name' already exists. Aborting."
return 1
fi
python -m venv "$env_name"
source "./$env_name/bin/activate"
pip install -U pip
}
activate_venv() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found. Use '$0 create [env_name]' to create one."
return 1
fi
source "./$env_name/bin/activate"
}
install_deps() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found. Use '$0 create [env_name]' to create one."
return 1
fi
source "./$env_name/bin/activate"
if [ -f "requirements.txt" ]; then
pip install -r ./requirements.txt
fi
if [ -f "setup.py" ]; then
pip install -e .
fi
}
export_deps() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found. Use '$0 create [env_name]' to create one."
return 1
fi
source "./$env_name/bin/activate"
pip freeze > requirements.txt
echo "Dependencies exported to requirements.txt"
}
remove_venv() {
local env_name=${1:-".venv"}
if [ ! -d "$env_name" ]; then
echo "Virtual environment '$env_name' not found."
return 1
fi
deactivate
rm -rf "$env_name"
}
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
print_help
return 0
fi
case "$1" in
"create")
create_venv "$2"
;;
"activate")
activate_venv "$2"
;;
"install")
install_deps "$2"
;;
"export")
export_deps "$2"
;;
"remove")
remove_venv "$2"
;;
*)
echo "Unknown option: $1"
print_help
exit 1
;;
esac