forked from oracle/wayflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_installation_tools.sh
More file actions
123 lines (103 loc) · 3.36 KB
/
_installation_tools.sh
File metadata and controls
123 lines (103 loc) · 3.36 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
121
122
123
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
#
# This software is under the Apache License 2.0
# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if the user wants to use 'uv' as the installation tool
for arg in "$@"; do
if [ "$arg" = "--use=uv" ]; then
export INSTALL_TOOL="uv"
else
echo "Warning: Ignoring unknown argument: $arg"
fi
done
INSTALL_TOOL="${INSTALL_TOOL:-pip}"
# Helper to run pip or uv depending on flag
run_pip() {
if [ "$INSTALL_TOOL" = "uv" ]; then
uv pip "$@"
else
python -m pip "$@"
fi
}
install_with_pip_or_uv() {
run_pip install "$@"
}
# Sets up internal PyPI mirror for pip or uv
setup_pypi_mirror() {
local PUBLIC_PYPI_MIRROR="https://pypi.org"
if [ "$INSTALL_TOOL" = "pip" ]; then
python -m pip config --user set global.index "$PUBLIC_PYPI_MIRROR/pypi"
python -m pip config --user set global.index-url "$PUBLIC_PYPI_MIRROR/simple"
elif [ "$INSTALL_TOOL" = "uv" ]; then
export UV_INDEX_URL="$PUBLIC_PYPI_MIRROR/simple"
fi
}
# Creates a virtual environment using pip's venv or uv
create_venv() {
local VENV_DIR=".venv-wayflowcore"
echo -e "${BLUE}Creating virtual environment using $INSTALL_TOOL and $PYTHON_CMD...${NC}"
if [ "$INSTALL_TOOL" = "pip" ]; then
"$PYTHON_CMD" -m venv "$VENV_DIR"
elif [ "$INSTALL_TOOL" = "uv" ]; then
uv venv "$VENV_DIR" --python "$PYTHON_CMD"
else
echo -e "${RED}Unsupported INSTALL_TOOL: $INSTALL_TOOL${NC}" >&2
return 1
fi
echo -e "${GREEN}Virtual environment created at .venv-wayflowcore${NC}"
# Activate the environment
source "$VENV_DIR/bin/activate"
echo -e "${BLUE}Virtual environment activated.${NC}"
}
# Upgrades pip or updates uv
upgrade_pip_or_uv() {
echo -e "${BLUE}Upgrading package installer (${INSTALL_TOOL})...${NC}"
install_with_pip_or_uv --upgrade pip
}
prepare_package_installation() {
package_name=$(basename "$1")
if run_pip show "$package_name" &> /dev/null; then
echo -e "${GREEN}Package $package_name is already locally installed.${NC}"
return 1
else
echo -e "${BLUE}Package $package_name not found. Installing from local source \"$1\" ...${NC}"
if [ -d "$1" ]; then
cd "$1"
return 0
else
echo -e "${RED}Error: the local directory $package_name does not exist. cwd: $(pwd)${NC}"
exit 1
fi
fi
}
install_python_package() {
prepare_package_installation "$1"
install_status=$?
if [ "$install_status" -eq 0 ]; then
bash install.sh
cd -
fi
}
install_dev_python_package() {
prepare_package_installation "$1"
install_status=$?
if [ "$install_status" -eq 0 ]; then
bash install-dev.sh
cd -
fi
}
install_requirements_dev() {
echo -e "Installing requirements-dev.txt from $(pwd)..."
install_with_pip_or_uv -r requirements-dev.txt
if [ $? -eq 0 ]; then
echo -e "${GREEN}$(pwd)/requirements-dev.txt installed successfully${NC}"
else
echo -e "${RED}$(pwd)/requirements-dev.txt installation failed. Exiting.${NC}"
exit 1
fi
}