-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
337 lines (292 loc) · 9.15 KB
/
install.sh
File metadata and controls
337 lines (292 loc) · 9.15 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
# TagManager Installation Script
# Supports local and remote (PyPI) installation with automatic upgrades
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Emojis for better UX
ROCKET="🚀"
PACKAGE="📦"
CHECK="✅"
WARNING="⚠️"
ERROR="❌"
INFO="ℹ️"
SPARKLES="✨"
GEAR="⚙️"
# Configuration
PACKAGE_NAME="tagmanager-cli"
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIST_DIR="$PROJECT_DIR/dist"
PYPROJECT_FILE="$PROJECT_DIR/pyproject.toml"
# Functions
print_header() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} TagManager Installation Script${NC}"
echo -e "${BLUE}================================${NC}"
echo
}
print_success() {
echo -e "${GREEN}${CHECK} $1${NC}"
}
print_info() {
echo -e "${CYAN}${INFO} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}${WARNING} $1${NC}"
}
print_error() {
echo -e "${RED}${ERROR} $1${NC}"
}
print_step() {
echo -e "${PURPLE}${GEAR} $1${NC}"
}
get_current_version() {
if [[ -f "$PYPROJECT_FILE" ]]; then
grep "version" "$PYPROJECT_FILE" | sed 's/.*version.*=.*"\(.*\)".*/\1/'
else
echo "unknown"
fi
}
check_dependencies() {
print_step "Checking dependencies..."
# Check Python
if ! command -v python &> /dev/null && ! command -v python3 &> /dev/null; then
print_error "Python is not installed or not in PATH"
exit 1
fi
# Always use the workspace virtual environment if available
VENV_PY="$PROJECT_DIR/.venv/Scripts/python.exe"
VENV_PIP="$PROJECT_DIR/.venv/Scripts/pip.exe"
if [[ -f "$VENV_PY" && -f "$VENV_PIP" ]]; then
PYTHON_CMD="$VENV_PY"
PIP_CMD="$VENV_PIP"
print_info "Using venv Python: $($PYTHON_CMD --version)"
else
# Fallback to system Python if venv not found
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
PIP_CMD="pip3"
else
PYTHON_CMD="python"
PIP_CMD="pip"
fi
print_info "Using system Python: $($PYTHON_CMD --version)"
fi
# Check pip
if ! "$PIP_CMD" --version &> /dev/null; then
print_error "pip is not installed or not in PATH"
exit 1
fi
print_success "Dependencies check passed"
}
install_build_tools() {
print_step "Installing/upgrading build tools..."
# Use python -m pip so upgrading pip works on Windows (pip.exe cannot replace itself).
"$PYTHON_CMD" -m pip install --upgrade pip build twine
print_success "Build tools ready"
}
build_package() {
print_step "Building package..."
cd "$PROJECT_DIR"
# Clean previous builds
if [[ -d "$DIST_DIR" ]]; then
rm -rf "$DIST_DIR"
print_info "Cleaned previous build artifacts"
fi
# Build package
"$PYTHON_CMD" -m build
if [[ $? -eq 0 ]]; then
print_success "Package built successfully"
ls -la "$DIST_DIR"
else
print_error "Package build failed"
exit 1
fi
}
install_local() {
print_step "Installing package locally..."
# Uninstall existing version
"$PIP_CMD" uninstall $PACKAGE_NAME -y 2>/dev/null || true
# Find the wheel file
WHEEL_FILE=$(find "$DIST_DIR" -name "*.whl" | head -n 1)
if [[ -z "$WHEEL_FILE" ]]; then
print_error "No wheel file found in $DIST_DIR"
exit 1
fi
# Install the wheel
"$PIP_CMD" install "$WHEEL_FILE"
if [[ $? -eq 0 ]]; then
print_success "Package installed locally"
test_installation
else
print_error "Local installation failed"
exit 1
fi
}
publish_to_pypi() {
print_step "Publishing to PyPI..."
# Check if we have PyPI credentials
if [[ -z "$TWINE_USERNAME" ]] && [[ ! -f ~/.pypirc ]]; then
print_warning "PyPI credentials not found"
echo -e "${YELLOW}Please set up PyPI credentials:${NC}"
echo "1. Create account at https://pypi.org"
echo "2. Generate API token"
echo "3. Set TWINE_USERNAME=__token__ and TWINE_PASSWORD=<your-token>"
echo " OR create ~/.pypirc file"
echo
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Aborted PyPI upload"
return 1
fi
fi
# Upload to PyPI
echo -e "${YELLOW}${ROCKET} Uploading to PyPI...${NC}"
twine upload "$DIST_DIR"/*
if [[ $? -eq 0 ]]; then
print_success "Package published to PyPI successfully!"
echo -e "${SPARKLES} Users can now install with: ${GREEN}pip install $PACKAGE_NAME${NC}"
else
print_error "PyPI upload failed"
return 1
fi
}
install_from_pypi() {
print_step "Installing from PyPI..."
# Uninstall local version
"$PIP_CMD" uninstall $PACKAGE_NAME -y 2>/dev/null || true
# Install from PyPI
"$PIP_CMD" install --upgrade $PACKAGE_NAME
if [[ $? -eq 0 ]]; then
print_success "Package installed from PyPI"
test_installation
else
print_error "PyPI installation failed"
exit 1
fi
}
test_installation() {
print_step "Testing installation..."
# Test both command aliases
if command -v tm &> /dev/null; then
print_success "Command 'tm' is available"
VERSION_OUTPUT=$(tm --help | head -n 5)
print_info "tm --help works"
else
print_error "Command 'tm' not found"
return 1
fi
if command -v tagmanager &> /dev/null; then
print_success "Command 'tagmanager' is available"
print_info "tagmanager --help works"
else
print_warning "Command 'tagmanager' not found (but tm works)"
fi
# Test basic functionality
if tm stats &> /dev/null; then
print_success "Basic functionality test passed"
else
print_info "Basic functionality test completed (no tags yet)"
fi
}
show_usage() {
echo -e "${CYAN}Usage:${NC}"
echo " ./install.sh --local Install package locally from source"
echo " ./install.sh --remote Publish to PyPI and install from there"
echo " ./install.sh --help Show this help message"
echo
echo -e "${CYAN}Options:${NC}"
echo " --local Build and install package locally"
echo " --remote Build, publish to PyPI, then install from PyPI"
echo " --build-only Build package without installing"
echo " --test-only Test existing installation"
echo " --help Show this help message"
echo
echo -e "${CYAN}Examples:${NC}"
echo " ./install.sh --local # Quick local install"
echo " ./install.sh --remote # Publish and install"
echo " python bump_version.py patch && ./install.sh --remote # Bump and publish"
}
show_post_install_info() {
local version=$(get_current_version)
echo
echo -e "${GREEN}${SPARKLES} Installation Complete! ${SPARKLES}${NC}"
echo -e "${BLUE}================================${NC}"
echo -e "${CYAN}Package:${NC} $PACKAGE_NAME v$version"
echo -e "${CYAN}Commands:${NC} tm, tagmanager"
echo
echo -e "${CYAN}Quick Start:${NC}"
echo " tm --help # Show all commands"
echo " tm add file.txt --tags work # Add tags to file"
echo " tm search --tags work # Search by tags"
echo " tm ls --tree # Tree view"
echo " tm stats --chart # Statistics"
echo
echo -e "${CYAN}Next Steps:${NC}"
echo " • Read the documentation: README.md"
echo " • Check installation guide: INSTALLATION.md"
echo " • Start tagging your files!"
echo -e "${BLUE}================================${NC}"
}
# Main script logic
main() {
print_header
case "${1:-}" in
--local)
check_dependencies
install_build_tools
build_package
install_local
show_post_install_info
;;
--remote)
check_dependencies
install_build_tools
build_package
# Publish to PyPI
if publish_to_pypi; then
print_info "Waiting 30 seconds for PyPI to process..."
sleep 30
install_from_pypi
show_post_install_info
else
print_warning "PyPI upload failed, installing locally instead"
install_local
show_post_install_info
fi
;;
--build-only)
check_dependencies
install_build_tools
build_package
print_success "Build complete. Files in: $DIST_DIR"
;;
--test-only)
test_installation
;;
--help|-h)
show_usage
;;
"")
print_error "No option specified"
echo
show_usage
exit 1
;;
*)
print_error "Unknown option: $1"
echo
show_usage
exit 1
;;
esac
}
# Run main function
main "$@"