Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,59 @@
REPO_ROOT="$(git rev-parse --show-toplevel)"
GITHOOKS_DIR="$REPO_ROOT/.githooks"

# Track failures
FAILED=0

echo "========================================"
echo " Pre-Push Checks"
echo "========================================"
echo

# Check for changes in Python files
python_changed_files=($(git diff --name-only --diff-filter=ACM | grep '^python/lib/sift_client/' || true))
# Compare against the remote branch being pushed to
python_changed_files=($(git diff --name-only --diff-filter=ACM @{upstream}... | grep '^python/' || true))

echo "→ Python files changed:"
if [[ -n "$python_changed_files" ]]; then
echo "Python files changed, running Python formatting and linting..."
bash "$GITHOOKS_DIR/pre-push-python/fmt-lint.sh"
echo " ${python_changed_files[*]}"
echo
echo " [1/3] Formatting and linting..."
bash "$GITHOOKS_DIR/pre-push-python/fmt-lint.sh" || FAILED=1

echo "Running Python stub checks..."
bash "$GITHOOKS_DIR/pre-push-python/stubs.sh"
echo " [2/3] Stub generation..."
bash "$GITHOOKS_DIR/pre-push-python/stubs.sh" || FAILED=1

echo " [3/3] Extras validation..."
bash "$GITHOOKS_DIR/pre-push-python/extras.sh" || FAILED=1
echo
else
echo " (none)"
echo
fi

# Check for changes in Rust bindings files
bindings_changed_files=($(git diff --name-only --diff-filter=ACM | grep '^rust/crates/sift_stream_bindings/src/' || true))
bindings_changed_files=($(git diff --name-only --diff-filter=ACM @{upstream}... | grep '^rust/crates/sift_stream_bindings/src/' || true))

echo "→ Rust binding files changed:"
if [[ -n "$bindings_changed_files" ]]; then
echo "Rust bindings files changed, running Rust stub checks..."
bash "$GITHOOKS_DIR/pre-push-rust/stubs.sh"
echo " ${bindings_changed_files[*]}"
echo
echo " [1/1] Stub generation..."
bash "$GITHOOKS_DIR/pre-push-rust/stubs.sh" || FAILED=1
echo
else
echo " (none)"
echo
fi

echo "Pre-push checks completed successfully."
if [[ $FAILED -eq 1 ]]; then
echo "========================================"
echo " ✗ Some checks failed"
echo "========================================"
exit 1
else
echo "========================================"
echo " ✓ All checks passed"
echo "========================================"
fi

37 changes: 37 additions & 0 deletions .githooks/pre-push-python/extras.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ensure generated pyproject.toml extras are up-to-date

# Store the root directory of the repository
REPO_ROOT="$(git rev-parse --show-toplevel)"
PYTHON_DIR="$REPO_ROOT/python"
PYPROJECT_FILE="$PYTHON_DIR/pyproject.toml"

# Function to check if pyproject.toml has changed
check_extras_changes() {
local target_path="$1"
local changed_files=$(git status --porcelain "$target_path" || true)

if [ -n "$changed_files" ]; then
echo " ❌ ERROR: Generated extras are not up-to-date:"
echo "$changed_files" | sed 's/^/ /'
echo " Please commit these changes before pushing."
exit 1
fi
}

# Function to generate Python extras
generate_python_extras() {
echo " → Generating extras..."
cd "$PYTHON_DIR"

if [[ ! -d "$PYTHON_DIR/venv" ]]; then
echo " → Running bootstrap script..."
bash ./scripts/dev bootstrap
fi

bash ./scripts/dev gen-extras
check_extras_changes "$PYPROJECT_FILE"
}

generate_python_extras

echo " ✓ Extras are up-to-date"
14 changes: 6 additions & 8 deletions .githooks/pre-push-python/fmt-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ set -e
REPO_ROOT="$(git rev-parse --show-toplevel)"
PYTHON_DIR="$REPO_ROOT/python"

echo "Running Python formatting and linting with --fix..."

# Change to Python directory
cd "$PYTHON_DIR"

# Run ruff format (formatter)
echo "Running ruff format..."
echo "Running ruff format..."
bash ./scripts/dev fmt

# Run ruff check with --fix (linter)
echo "Running ruff check --fix..."
echo "Running ruff check --fix..."
bash ./scripts/dev lint-fix

# Check if any files were modified by formatting/linting
Expand All @@ -25,11 +23,11 @@ changed_files=$(git status --porcelain python/lib/sift_client/ | grep -E '\.py$'

if [ -n "$changed_files" ]; then
echo ""
echo "ERROR: Formatting/linting made changes to the following files:"
echo "$changed_files"
echo "ERROR: Formatting/linting made changes:"
echo "$changed_files" | sed 's/^/ /'
echo ""
echo "Please commit these changes before pushing."
echo " Please commit these changes before pushing."
exit 1
fi

echo "Python formatting and linting completed successfully."
echo " ✓ Formatting and linting passed"
11 changes: 6 additions & 5 deletions .githooks/pre-push-python/stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ check_stub_changes() {
local changed_files=$(git status --porcelain "$target_path" | grep -E '\.pyi$' || true)

if [ -n "$changed_files" ]; then
echo "ERROR: Generated python stubs are not up-to-date. Please commit the changed files:"
echo "$changed_files"
echo " ❌ ERROR: Generated stubs are not up-to-date:"
echo "$changed_files" | sed 's/^/ /'
echo " Please commit these changes before pushing."
exit 1
fi
}

# Function to generate Python stubs
generate_python_stubs() {
echo "Generating Python stubs..."
echo " → Generating stubs..."
cd "$PYTHON_DIR"

if [[ ! -d "$PYTHON_DIR/venv" ]]; then
echo "Running bootstrap script..."
echo "Running bootstrap script..."
bash ./scripts/dev bootstrap
fi

Expand All @@ -33,4 +34,4 @@ generate_python_stubs() {

generate_python_stubs

echo "All stubs are up-to-date."
echo " ✓ Stubs are up-to-date"
9 changes: 5 additions & 4 deletions .githooks/pre-push-rust/stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ check_stub_changes() {
local changed_files=$(git status --porcelain "$target_path" | grep -E '\.pyi$' || true)

if [ -n "$changed_files" ]; then
echo "ERROR: Generated python stubs are not up-to-date. Please commit the changed files:"
echo "$changed_files"
echo " ❌ ERROR: Generated stubs are not up-to-date:"
echo "$changed_files" | sed 's/^/ /'
echo " Please commit these changes before pushing."
exit 1
fi
}

# Function to generate bindings stubs
generate_bindings_stubs() {
echo "Generating bindings stubs..."
echo " → Generating stubs..."
cd "$BINDINGS_DIR"
cargo run --bin stub_gen

Expand All @@ -29,4 +30,4 @@ generate_bindings_stubs() {

generate_bindings_stubs

echo "All stubs are up-to-date."
echo " ✓ Stubs are up-to-date"
8 changes: 4 additions & 4 deletions .github/workflows/python_build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Deploy Python Docs (Dev)

on:
pull_request:
types: [opened, synchronize, closed]
types: [ opened, synchronize, closed ]
paths:
- 'python/docs/**'
- 'python/lib/**'
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install dependencies
run: |
cd python
pip install -e .[docs,development]
pip install -e .[docs-build]

- name: Extract version
id: version
Expand Down Expand Up @@ -91,8 +91,8 @@ jobs:
- name: Install dependencies
run: |
cd python
pip install -e .[docs,development]
pip install -e .[docs-build]

- name: Fetch gh-pages branch
run: git fetch origin gh-pages --depth=1

Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/python_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
id: install
run: |
python -m pip install --upgrade pip
pip install '.[development,data_review,openssl,tdms,rosbags,hdf5,sift-stream]'
pip install '.[dev-all]'

- name: Lint
run: |
Expand All @@ -48,6 +48,16 @@ jobs:
run: |
pyright lib

- name: Check Stubs Generation
working-directory: .
run: |
bash .githooks/pre-push-python/stubs.sh

- name: Check Extras Generation
working-directory: .
run: |
bash .githooks/pre-push-python/extras.sh

- name: Pytest Unit Tests
run: |
pytest -m "not integration"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/python_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:

publish-to-pypi:
name: Upload release to PyPI
needs: [python-ci, build-offline-archives]
needs: [ python-ci, build-offline-archives ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sift_py
permissions:
id-token: write
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
Expand All @@ -38,7 +38,7 @@ jobs:

create-github-release:
name: Create GitHub Release
needs: [build-offline-archives]
needs: [ build-offline-archives ]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Install dependencies
run: |
cd python
pip install -e .[docs,development]
pip install -e .[docs-build]

- name: Extract version and check if stable
id: version
Expand All @@ -125,7 +125,7 @@ jobs:
MINOR=${BASH_REMATCH[2]}
SUFFIX=${BASH_REMATCH[3]}
VERSION="v${MAJOR}.${MINOR}"

# Check if this is a stable release (no suffix like -alpha, -beta, -rc)
if [[ -z "$SUFFIX" ]]; then
# Stable release - use 'latest' alias and make visible
Expand Down
Loading
Loading