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
64REPO_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
498python_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
5310if [[ -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"
5513fi
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+
5718if [[ -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"
5921fi
6022
61- echo " All stubs are up-to-date."
23+ echo " Pre-push checks completed successfully."
24+
0 commit comments