-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependencies.sh
More file actions
executable file
·71 lines (60 loc) · 2 KB
/
dependencies.sh
File metadata and controls
executable file
·71 lines (60 loc) · 2 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
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REQUIREMENTS="${SCRIPT_DIR}/requirements.txt"
# Check if requirements.txt exists
if [ ! -f "$REQUIREMENTS" ]; then
echo "Error: requirements.txt not found"
exit 1
fi
# Try pipx first (recommended and safest)
if command -v pipx >/dev/null 2>&1; then
echo "Installing with pipx..."
while IFS= read -r package || [ -n "$package" ]; do
[[ -z "$package" || "$package" =~ ^[[:space:]]*# ]] && continue
package_name=$(echo "$package" | sed 's/[>=<~!].*//' | xargs)
pipx install "$package" --force 2>/dev/null || true
done < "$REQUIREMENTS"
echo "Done!"
exit 0
fi
# Suggest installing pipx if not found
echo "pipx not found. Please install it first (recommended):"
if command -v brew >/dev/null 2>&1; then
echo " brew install pipx"
else
echo " python3 -m pip install --user pipx"
fi
echo " pipx ensurepath"
echo ""
echo "Or, to continue anyway, use one of these:"
echo " 1. Create a venv manually: python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
echo " 2. Use pip3 --user with --break-system-packages (safe when combined with --user)"
echo ""
read -p "Continue with pip3 --user anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
# Try pip3 --user only if user confirms
if command -v pip3 >/dev/null 2>&1; then
echo "Installing with pip3 --user..."
pip3 install --user --break-system-packages -r "$REQUIREMENTS"
# Warn about PATH if needed
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo "Warning: Add ~/.local/bin to your PATH:"
echo 'export PATH="$HOME/.local/bin:$PATH"'
fi
echo "Done!"
exit 0
fi
# Fallback to venv
echo "Installing in virtual environment..."
VENV_DIR="${SCRIPT_DIR}/venv"
if [ ! -d "$VENV_DIR" ]; then
python3 -m venv "$VENV_DIR"
fi
source "$VENV_DIR/bin/activate"
pip install -r "$REQUIREMENTS"
deactivate
echo "Done! Activate with: source venv/bin/activate"