Skip to content

Commit 292fb4f

Browse files
committed
update pre-push hooks
1 parent d715d5d commit 292fb4f

3 files changed

Lines changed: 79 additions & 48 deletions

File tree

.githooks/pre-push

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,24 @@
11
#!/usr/bin/env bash
22

3-
# ensure generated python stubs are up-to-date, from sync clients and sift_stream_bindings
4-
53
# Store the root directory of the repository
64
REPO_ROOT="$(git rev-parse --show-toplevel)"
7-
PYTHON_DIR="$REPO_ROOT/python"
8-
BINDINGS_DIR="$REPO_ROOT/rust/crates/sift_stream_bindings"
9-
STUBS_DIR="$PYTHON_DIR/lib/sift_client/resources/sync_stubs"
10-
11-
# Function to check if generated stub files have changed
12-
check_stub_changes() {
13-
local target_path="$1"
14-
local changed_files=$(git status --porcelain "$target_path" | grep -E '\.pyi$' || true)
15-
16-
if [ -n "$changed_files" ]; then
17-
echo "ERROR: Generated python stubs are not up-to-date. Please commit the changed files:"
18-
echo "$changed_files"
19-
exit 1
20-
fi
21-
}
22-
23-
# Function to generate Python stubs
24-
generate_python_stubs() {
25-
echo "Generating Python stubs..."
26-
cd "$PYTHON_DIR"
27-
28-
if [[ ! -d "$PYTHON_DIR/venv" ]]; then
29-
echo "Running bootstrap script..."
30-
bash ./scripts/dev bootstrap
31-
fi
32-
33-
bash ./scripts/dev gen-stubs
34-
check_stub_changes "$STUBS_DIR"
35-
}
5+
GITHOOKS_DIR="$REPO_ROOT/.githooks"
366

37-
# Function to generate bindings stubs
38-
generate_bindings_stubs() {
39-
echo "Generating bindings stubs..."
40-
cd "$BINDINGS_DIR"
41-
cargo run --bin stub_gen
42-
43-
# The stub file is generated in the bindings directory
44-
local stub_file="$BINDINGS_DIR/sift_stream_bindings.pyi"
45-
check_stub_changes "$stub_file"
46-
}
47-
48-
# Check for changes in relevant files
7+
# Check for changes in Python files
498
python_changed_files=($(git diff --name-only --diff-filter=ACM | grep '^python/lib/sift_client/' || true))
50-
bindings_changed_files=($(git diff --name-only --diff-filter=ACM | grep '^rust/crates/sift_stream_bindings/src/' || true))
519

52-
# Generate stubs if needed
5310
if [[ -n "$python_changed_files" ]]; then
54-
generate_python_stubs
11+
echo "Python files changed, running Python stub checks..."
12+
bash "$GITHOOKS_DIR/pre-push-python/stubs.sh"
5513
fi
5614

15+
# Check for changes in Rust bindings files
16+
bindings_changed_files=($(git diff --name-only --diff-filter=ACM | grep '^rust/crates/sift_stream_bindings/src/' || true))
17+
5718
if [[ -n "$bindings_changed_files" ]]; then
58-
generate_bindings_stubs
19+
echo "Rust bindings files changed, running Rust stub checks..."
20+
bash "$GITHOOKS_DIR/pre-push-rust/stubs.sh"
5921
fi
6022

61-
echo "All stubs are up-to-date."
23+
echo "Pre-push checks completed successfully."
24+

.githooks/pre-push-python/stubs.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ensure generated python stubs are up-to-date, from sync clients
2+
3+
# Store the root directory of the repository
4+
REPO_ROOT="$(git rev-parse --show-toplevel)"
5+
PYTHON_DIR="$REPO_ROOT/python"
6+
STUBS_DIR="$PYTHON_DIR/lib/sift_client/resources/sync_stubs"
7+
8+
# Function to check if generated stub files have changed
9+
check_stub_changes() {
10+
local target_path="$1"
11+
local changed_files=$(git status --porcelain "$target_path" | grep -E '\.pyi$' || true)
12+
13+
if [ -n "$changed_files" ]; then
14+
echo "ERROR: Generated python stubs are not up-to-date. Please commit the changed files:"
15+
echo "$changed_files"
16+
exit 1
17+
fi
18+
}
19+
20+
# Function to generate Python stubs
21+
generate_python_stubs() {
22+
echo "Generating Python stubs..."
23+
cd "$PYTHON_DIR"
24+
25+
if [[ ! -d "$PYTHON_DIR/venv" ]]; then
26+
echo "Running bootstrap script..."
27+
bash ./scripts/dev bootstrap
28+
fi
29+
30+
bash ./scripts/dev gen-stubs
31+
check_stub_changes "$STUBS_DIR"
32+
}
33+
34+
generate_python_stubs
35+
36+
echo "All stubs are up-to-date."

.githooks/pre-push-rust/stubs.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ensure generated python stubs are up-to-date, from sift_stream_bindings
2+
3+
# Store the root directory of the repository
4+
REPO_ROOT="$(git rev-parse --show-toplevel)"
5+
BINDINGS_DIR="$REPO_ROOT/rust/crates/sift_stream_bindings"
6+
7+
# Function to check if generated stub files have changed
8+
check_stub_changes() {
9+
local target_path="$1"
10+
local changed_files=$(git status --porcelain "$target_path" | grep -E '\.pyi$' || true)
11+
12+
if [ -n "$changed_files" ]; then
13+
echo "ERROR: Generated python stubs are not up-to-date. Please commit the changed files:"
14+
echo "$changed_files"
15+
exit 1
16+
fi
17+
}
18+
19+
# Function to generate bindings stubs
20+
generate_bindings_stubs() {
21+
echo "Generating bindings stubs..."
22+
cd "$BINDINGS_DIR"
23+
cargo run --bin stub_gen
24+
25+
# The stub file is generated in the bindings directory
26+
local stub_file="$BINDINGS_DIR/sift_stream_bindings.pyi"
27+
check_stub_changes "$stub_file"
28+
}
29+
30+
generate_bindings_stubs
31+
32+
echo "All stubs are up-to-date."

0 commit comments

Comments
 (0)