-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_dependencies.sh
More file actions
118 lines (103 loc) · 4.74 KB
/
install_dependencies.sh
File metadata and controls
118 lines (103 loc) · 4.74 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
#!/bin/bash
# Script to install dependencies from pyproject.toml using Poetry and export requirements.txt
# This script assumes pyproject.toml is in the same directory as the script (e.g., botlab root).
set -e # Exit on error
VERBOSE_POETRY_FLAG=""
# Parse command line options
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose|-vv|-vvv)
VERBOSE_POETRY_FLAG=$1
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [-v|--verbose|-vv|-vvv]"
echo " -v, --verbose: Enable Poetry's verbose output"
echo " -vv, -vvv: Enable more verbose output"
exit 1
;;
esac
done
# Get the directory of this script, which is assumed to be the project root (e.g., botlab/)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "$SCRIPT_DIR" # Ensure we are in the project root
echo "Running in directory: $SCRIPT_DIR"
echo "Looking for pyproject.toml in this directory..."
# Check if pyproject.toml file exists in the current directory (project root)
if [ ! -f "pyproject.toml" ]; then
echo "Error: pyproject.toml not found in $SCRIPT_DIR!"
echo "Please ensure the file has been moved to the root of the 'botlab' directory."
exit 1
fi
# Check if poetry is installed
if ! command -v poetry &> /dev/null; then
echo "Poetry not found. Do you want to install it? (y/n)"
read -r install_poetry
if [[ "$install_poetry" =~ ^[Yy]$ ]]; then
echo "Installing Poetry using the official installer..."
curl -sSL https://install.python-poetry.org | python3.13 -
# Ensure Poetry's bin directory is in PATH for the current script session
echo "Ensuring $HOME/.local/bin is in PATH for this script session."
export PATH="$HOME/.local/bin:$PATH"
# Check if PATH is already in .bashrc and add if not (for future sessions)
if grep -q "PATH=\"\$HOME/.local/bin:\$PATH\"" ~/.bashrc; then
echo "Poetry PATH entry already found in .bashrc."
else
echo "Adding Poetry to PATH in .bashrc for future sessions."
echo '' >> ~/.bashrc # Add a newline for separation
echo '# Add Poetry to PATH' >> ~/.bashrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo "Poetry PATH added to ~/.bashrc. Please source it or open a new terminal for it to take effect in other sessions."
fi
# Verify poetry command is now available
if ! command -v poetry &> /dev/null; then
echo "Error: 'poetry' command still not found after attempting to update PATH for current session."
echo "Current PATH: $PATH"
echo "Poetry is expected to be in $HOME/.local/bin."
echo "Please check your Poetry installation and the script's output."
exit 1
else
echo "Poetry command is now available in the current session."
fi
else
echo "Poetry installation skipped. Please install Poetry manually and run this script again."
exit 1
fi
fi
# Check if python3.13 installed and configure Poetry to use it
if ! command -v python3.13 &> /dev/null; then
echo "Error: python3.13 could not be found. Please install it first."
exit 1
else
echo "Python 3.13 found. Attempting to configure Poetry to use it..."
if poetry env use python3.13 $VERBOSE_POETRY_FLAG; then
echo "Poetry successfully configured to use python3.13."
else
echo "Error: 'poetry env use python3.13' failed."
echo "Please check Poetry's output above for details. Make sure python3.13 is a functional installation that Poetry can use."
exit 1
fi
fi
echo "Poetry found and configured to use python3.13. Proceeding with operations using pyproject.toml in $SCRIPT_DIR."
# Install dependencies using Poetry
echo "Installing dependencies from pyproject.toml using 'poetry install'..."
# The $VERBOSE_POETRY_FLAG will add verbosity to the poetry command if -v was passed to the script
if poetry install $VERBOSE_POETRY_FLAG; then
echo "Poetry install completed successfully."
else
echo "Error: Poetry install failed. Check poetry output for details."
exit 1
fi
# Export dependencies to requirements.txt
echo "Exporting dependencies to requirements.txt..."
poetry self add poetry-plugin-export
# The output file "requirements.txt" will be created in the current directory ($SCRIPT_DIR)
# The $VERBOSE_POETRY_FLAG will add verbosity if enabled
if poetry export -f requirements.txt --output "requirements.txt" --without-hashes $VERBOSE_POETRY_FLAG; then
echo "Successfully exported requirements.txt to $SCRIPT_DIR/requirements.txt"
else
echo "Error: Poetry export failed. Check poetry output for details."
exit 1
fi
echo "All operations (install and export) completed successfully!"