-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_template
executable file
·124 lines (108 loc) · 3.52 KB
/
install_template
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
121
122
123
124
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Get the local directory (where the script is located)
source variables.sh
if [[ "$(uname)" == "MINGW"* ]] || [[ "$(uname)" == "CYGWIN"* ]] || [[ "$(uname)" == "MSYS"* ]]; then
OS="Windows"
ENV_FOLDER="$VENV/Scripts"
else
OS="NotWindows"
ENV_FOLDER="$VENV/bin"
fi
# Function to create a virtual environment
create_env() {
echo -e "\n*************************************************************"
echo -e "Using shell: $SHELL"
if [ ! -d "$DEST_DIR" ]; then
mkdir -p "$DEST_DIR"
fi
cp "$LOCAL_DIR/requirements.txt" "$DEST_DIR"
# Check if python3 exists
if command -v python3 &> /dev/null
then
python3 entrypoint.py "$DEST_DIR"
elif command -v python &> /dev/null
then
python entrypoint.py "$DEST_DIR"
else
echo "Python is not installed. Please install Python and try again."
exit 1
fi
# Write the path of the virtual environment to a file
echo "$VENV" > "$ADDON_VENV_FILE"
}
build_project() {
echo -e "\n*************************************************************"
echo -e "\nBuilding seeq-addon-template project"
if [ -f "$ENV_FOLDER/python" ]; then
set +e
err=$("$ENV_FOLDER"/python -m build 2> /dev/null)
set -e
if [[ $err == *"ERROR"* ]]; then
echo "$err"
exit 1
fi
else
echo "File not found: $ENV_FOLDER/python."
exit 1
fi
echo -e "Build successful"
}
install_project() {
echo -e "\n*************************************************************"
echo -e "\nInstalling seeq-addon-template project"
version=$(grep 'version =' pyproject.toml | sed 's/version = //g' | tr -d '"')
echo "seeq-addon-template version: $version"
echo -e "Installing in python environment"
"$ENV_FOLDER"/pip install dist/addon-"$version"-py3-none-any.whl -U > /dev/null
if [ ! -d "$DEST_DIR/bin" ]; then
echo "Creating directory $DEST_DIR/bin"
mkdir -p "$DEST_DIR/bin"
fi
echo -e "Copying files to $DEST_DIR/bin"
chmod +x "$ADDON_SCRIPT_PATH"
chmod +x "$ADDON_VENV_FILE"
chmod +x "$VARIABLES_FILE"
cp "$ADDON_SCRIPT_PATH" "$ADDON_SCRIPT_LOCAL_PATH"
cp "$ADDON_VENV_FILE" "$ADDON_VENV_FILE_LOCAL_PATH"
cp "$VARIABLES_FILE" "$VARIABLES_FILE_LOCAL_PATH"
if [[ "$OS" == "Windows" ]]; then
cp "$ADDON_SCRIPT_PATH_WINDOWS" "$ADDON_SCRIPT_LOCAL_PATH_WINDOWS"
cp "$VARIABLES_FILE_WINDOWS" "$VARIABLES_FILE_LOCAL_PATH_WINDOWS"
fi
}
add_to_path() {
echo -e "\n*************************************************************"
echo -e "\nAdding directories to your PATH"
files_to_check=(~/.bashrc ~/.zshrc ~/.bash_profile)
# Loop over the files
for file in "${files_to_check[@]}"; do
if grep -Fxq "$PATH_START_MARKER" "$file"; then
echo "Path already in $file"
else
echo "Adding path to $file"
echo "$ADD_TO_PATH" >> "$file"
fi
done
}
info() {
echo -e "\n************************************************************"
echo -e "\nInstallation complete"
echo -e "CLOSE THIS TERMINAL NOW AND OPEN A NEW ONE"
echo -e "Then, run 'addon --help' to see the available options"
echo -e "For example, to create an example Add-on, run the command"
echo -e " 'addon create <destination_dir>'"
echo -e "\n************************************************************"
}
create_env
build_project
install_project
add_to_path
info
read -n1 -rp "Press any key to exit..."
if [[ "$(uname)" == "Darwin" ]]; then
osascript -e 'tell application "Terminal" to close first window'
else
echo -e "CLOSE THIS TERMINAL NOW AND OPEN A NEW ONE"
fi