Repository navigation
Expand file tree
/
Copy pathrun_examples.sh
More file actions
executable file
·102 lines (90 loc) · 3.22 KB
/
Copy pathrun_examples.sh
File metadata and controls
executable file
·102 lines (90 loc) · 3.22 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
#!/bin/bash
# Script to build ProllyTree and run Python examples
# Usage: ./run_examples.sh [example_name]
# If no example name is provided, all examples will be run
# Define available examples using a case statement instead of associative array
# This is more portable across different shells
get_example_file() {
case "$1" in
"basic") echo "basic_usage.py" ;;
"sql") echo "sql_example.py" ;;
"merge") echo "merge_example.py" ;;
"namespaced") echo "namespaced_example.py" ;;
"text_index") echo "text_index_example.py" ;;
*) echo "" ;;
esac
}
# Check if a specific example was requested
REQUESTED_EXAMPLE=$1
# Function to show usage
show_usage() {
echo "Usage: $0 [example_name]"
echo ""
echo "Available examples:"
echo " basic - Basic memory usage example"
echo " sql - SQL query example"
echo " merge - Branch merging with conflict resolution example"
echo " namespaced - Multi-namespace KV store example"
echo " text_index - Text indexing + vector search on NamespacedKvStore"
echo ""
echo "If no example name is provided, all examples will be run."
}
# Validate requested example if provided
if [ ! -z "$REQUESTED_EXAMPLE" ]; then
if [ "$REQUESTED_EXAMPLE" == "--help" ] || [ "$REQUESTED_EXAMPLE" == "-h" ]; then
show_usage
exit 0
fi
EXAMPLE_FILE=$(get_example_file "$REQUESTED_EXAMPLE")
if [ -z "$EXAMPLE_FILE" ]; then
echo "❌ Error: Unknown example '$REQUESTED_EXAMPLE'"
echo ""
show_usage
exit 1
fi
fi
if [ -z "$REQUESTED_EXAMPLE" ]; then
echo "🔧 Building ProllyTree Python bindings for all examples..."
else
echo "🔧 Building ProllyTree Python bindings for '$REQUESTED_EXAMPLE' example..."
fi
echo "This may take a few minutes on first build..."
# Change to project root
cd ../..
# Build the Python bindings
if ./python/build_python.sh --all-features --install; then
echo "✅ ProllyTree built successfully!"
# Change back to examples directory
cd python/examples
# Function to run a single example
run_example() {
local name=$1
local file=$2
echo ""
echo "🚀 Running $name example..."
python "$file"
}
# Run examples based on request
if [ -z "$REQUESTED_EXAMPLE" ]; then
# Run all examples
echo ""
echo "📚 Running all examples..."
run_example "basic memory usage" "basic_usage.py"
run_example "SQL" "sql_example.py"
run_example "merge with conflict resolution" "merge_example.py"
run_example "namespaced KV store" "namespaced_example.py"
run_example "text indexing + search" "text_index_example.py"
else
# Run only the requested example
EXAMPLE_FILE=$(get_example_file "$REQUESTED_EXAMPLE")
run_example "$REQUESTED_EXAMPLE" "$EXAMPLE_FILE"
fi
else
echo "❌ Build failed. Please check the error messages above."
echo ""
echo "Common issues:"
echo "1. Make sure you have Rust installed: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
echo "2. Install maturin: pip install maturin"
echo "3. Make sure you're using Python 3.8 or higher"
exit 1
fi