-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·182 lines (150 loc) · 5.36 KB
/
run.sh
File metadata and controls
executable file
·182 lines (150 loc) · 5.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
# CE Library Wizard runner script
# This script sets up Poetry and runs the CLI
#
# Environment variables:
# DEBUG=1 or CE_DEBUG=1 - Enable verbose output including Poetry installation details
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if python3 is available
if ! command -v python3 &> /dev/null; then
print_error "python3 is not installed. Please install Python 3.10 or higher."
exit 1
fi
# Get Python version
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
print_info "Found Python $PYTHON_VERSION"
# Check Python version is 3.10+
if ! python3 -c 'import sys; exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then
print_error "Python 3.10 or higher is required. Found Python $PYTHON_VERSION"
exit 1
fi
# Set up directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Always cleanup existing environment to ensure fresh install
if [ -d ".venv" ]; then
print_info "Cleaning up existing virtual environment..."
rm -rf .venv
fi
# Check if Poetry is installed
if ! command -v poetry &> /dev/null; then
print_info "Poetry not found. Installing Poetry..."
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Add Poetry to PATH for this session
export PATH="$HOME/.local/bin:$PATH"
# Check again
if ! command -v poetry &> /dev/null; then
print_error "Failed to install Poetry"
print_info "Please install Poetry manually: https://python-poetry.org/docs/#installation"
exit 1
fi
print_info "Poetry installed successfully!"
fi
# Configure Poetry to create virtual environment in project directory
poetry config virtualenvs.in-project true --local 2>/dev/null || true
# Check if poetry.lock is out of sync before installing
if [ -f "poetry.lock" ]; then
if ! poetry check --lock 2>/dev/null; then
print_error "poetry.lock file is out of sync with pyproject.toml"
print_info "Running 'poetry lock' to fix this..."
if ! poetry lock; then
print_error "Failed to update poetry.lock file"
exit 1
fi
print_info "poetry.lock updated successfully"
fi
fi
# Install dependencies
print_info "Installing dependencies with Poetry..."
if [[ "${DEBUG:-}" == "1" || "${CE_DEBUG:-}" == "1" ]]; then
poetry install --no-interaction --no-ansi
else
# Capture output even in quiet mode to detect issues
INSTALL_OUTPUT=$(poetry install --no-interaction --no-ansi --quiet 2>&1)
INSTALL_EXIT_CODE=$?
fi
if [[ "${DEBUG:-}" == "1" || "${CE_DEBUG:-}" == "1" ]]; then
INSTALL_EXIT_CODE=$?
fi
if [ $INSTALL_EXIT_CODE -eq 0 ]; then
print_info "Installation complete!"
else
print_error "Failed to install dependencies"
if [[ "${DEBUG:-}" != "1" && "${CE_DEBUG:-}" != "1" ]]; then
print_info "Error output:"
echo "$INSTALL_OUTPUT"
print_info "Run with DEBUG=1 for more detailed output"
fi
exit 1
fi
# Check if GitHub authentication is available
if [ -z "$GITHUB_TOKEN" ] && ! command -v gh &> /dev/null; then
print_warning "No GitHub authentication found."
print_info "To enable PR creation, use one of these options:"
print_info " - Install and authenticate GitHub CLI: gh auth login"
print_info " - Set GITHUB_TOKEN environment variable"
print_info " - Use --oauth flag for browser-based authentication"
echo
elif [ -z "$GITHUB_TOKEN" ] && ! gh auth status &> /dev/null; then
print_warning "GitHub CLI is installed but not authenticated."
print_info "To enable PR creation, run: gh auth login"
echo
fi
# Check for special commands
if [ "$1" = "--format" ]; then
if [ "$2" = "--check" ]; then
print_info "Running code quality checks..."
echo "======================================"
echo
print_info "Running black formatter check..."
if ! poetry run black --check --diff .; then
print_error "Black formatting check failed!"
exit 1
fi
print_info "Running ruff linter check..."
if ! poetry run ruff check .; then
print_error "Ruff linting check failed!"
exit 1
fi
print_info "Running pytype type checking..."
if poetry run pytype; then
print_info "PyType type checking passed!"
else
print_warning "PyType type checking completed with warnings (not failing build)"
fi
print_info "All code quality checks passed!"
exit 0
else
print_info "Running code formatters..."
echo "======================================"
echo
print_info "Running black formatter..."
poetry run black .
print_info "Running ruff formatter..."
poetry run ruff check --fix .
print_info "Formatting complete!"
exit 0
fi
fi
# Run the CLI
print_info "Starting CE Library Wizard..."
echo "======================================"
echo
# Pass all arguments to the CLI using Poetry
exec poetry run ce-lib-wizard "$@"