-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodes
More file actions
executable file
·108 lines (90 loc) · 3.26 KB
/
codes
File metadata and controls
executable file
·108 lines (90 loc) · 3.26 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
#!/bin/bash
# --- Function Definitions ---
# Function to initialize and update Git submodules (Initial checkout)
init_submodules() {
echo "--- Starting Submodule Initialization and Checkout ---"
# 1. Ensure Git submodule configuration is initialized
git submodule init
# 2. Loop through all submodules defined in .gitmodules
git config -f .gitmodules --get-regexp submodule\..*\.path | while read key path
do
echo ""
echo "--- Attempting to checkout $path ---"
# Update/clone the submodule using a selective command
if git submodule update --init -- $path; then
echo "✅ Successfully checked out $path."
else
# Handle Failure (Non-fatal warning)
echo "🚨 WARNING: Failed to checkout $path due to access issues."
echo "Skipping installation for this module."
fi
echo "-----------------------------------"
done
echo "Submodule checkout complete! All accessible codes checked out."
}
# Function to install submodules that are valid Python packages
install_packages() {
echo "--- Starting Python Package Installation (Editable Mode) ---"
# 1. Loop through all submodules defined in .gitmodules
git config -f .gitmodules --get-regexp submodule\..*\.path | while read key path
do
# Check if the path exists AND if it contains a pyproject.toml
if [ -d "$path" ] && [ -f "$path/pyproject.toml" ]; then
echo ""
echo "📦 Installing $path in editable mode (pip install -e)."
# Using -U for upgrade/update in case the package is already installed
pip install -U -e "$path"
fi
done
echo "Installation complete! Environment is ready to use."
}
# Update all submodules to the latest commit on their tracked branch
update_submodules() {
echo "--- Starting Submodule Update (Fetching latest remote commits and REBASING) ---"
# This command fetches the latest remote commit and updates the local submodule
# using a rebase operation instead of a merge.
if git submodule update --remote --rebase; then
echo "✅ All submodules updated successfully using rebase."
else
echo "❌ ERROR: Failed to update one or more submodules via rebase."
echo "Please check permissions and network connectivity, and resolve any rebase conflicts."
fi
}
# Function to display usage information
show_usage() {
echo "Usage: $0 <command>"
echo ""
echo "Available commands:"
echo " init : Initializes and checks out submodules (for first time setup)."
echo " update : Pulls the latest version from the remote branch for all submodules."
echo " install : Installs all submodules that are valid Python packages using 'pip install -U -e'."
echo " help : Show this usage message."
echo ""
}
# --- Main Logic (Command Parser) ---
# Check if a command was provided
if [ -z "$1" ]; then
show_usage
exit 1
fi
COMMAND=$1
case "$COMMAND" in
init)
init_submodules
;;
update)
update_submodules
;;
install)
install_packages
;;
help)
show_usage
;;
*)
echo "❌ Error: Unknown command '$COMMAND'"
show_usage
exit 1
;;
esac
exit 0