Skip to content
Closed
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
17 changes: 15 additions & 2 deletions .github/workflows/pr-test-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ jobs:
- id: check
uses: ./.github/actions/check-ci

lint-imports:
needs: check-ci
if: needs.check-ci.outputs.should_run == 'true'
runs-on: k8s-runner-cpu
permissions:
contents: read
steps:
- uses: actions/checkout@v6

- name: Check for deeply nested imports
run: |
bash scripts/check-deep-imports.sh $(find . -name '*.rs' -not -path './target/*' -not -path './TensorRT-LLM/*')

python-lint:
needs: check-ci
if: needs.check-ci.outputs.should_run == 'true'
Expand Down Expand Up @@ -578,7 +591,7 @@ jobs:
path: benchmark_go_bindings/

finish:
needs: [check-ci, python-lint, grpc-proto-build-check, build-wheel, python-unit-tests, unit-tests, gateway-e2e, go-unit-tests, go-bindings-e2e]
needs: [check-ci, lint-imports, python-lint, grpc-proto-build-check, build-wheel, python-unit-tests, unit-tests, gateway-e2e, go-unit-tests, go-bindings-e2e]
if: always()
runs-on: k8s-runner-cpu
permissions: {}
Expand All @@ -588,7 +601,7 @@ jobs:
if [[ "${{ needs.check-ci.outputs.should_run }}" != "true" ]]; then
echo "CI was skipped (external contributor without run-ci label)"
exit 0
elif [[ "${{ needs.python-lint.result }}" == "failure" || "${{ needs.grpc-proto-build-check.result }}" == "failure" || "${{ needs.build-wheel.result }}" == "failure" || "${{ needs.python-unit-tests.result }}" == "failure" || "${{ needs.unit-tests.result }}" == "failure" || "${{ needs.gateway-e2e.result }}" == "failure" || "${{ needs.go-unit-tests.result }}" == "failure" || "${{ needs.go-bindings-e2e.result }}" == "failure" ]]; then
elif [[ "${{ needs.lint-imports.result }}" == "failure" || "${{ needs.python-lint.result }}" == "failure" || "${{ needs.grpc-proto-build-check.result }}" == "failure" || "${{ needs.build-wheel.result }}" == "failure" || "${{ needs.python-unit-tests.result }}" == "failure" || "${{ needs.unit-tests.result }}" == "failure" || "${{ needs.gateway-e2e.result }}" == "failure" || "${{ needs.go-unit-tests.result }}" == "failure" || "${{ needs.go-bindings-e2e.result }}" == "failure" ]]; then
echo "One or more jobs failed"
exit 1
else
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ repos:
types: [rust]
pass_filenames: false

- id: check-deep-imports
name: check-deep-imports
description: Reject internal imports with more than 4 path segments
entry: scripts/check-deep-imports.sh
language: script
types: [rust]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion grpc_client/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ dependencies = [
readme = "README.md"
license = { text = "Apache-2.0" }
authors = [
{name = "Simo Lin", email = "linsimo.mark@gmail.com"},
{name = "Chang Su", email = "mckvtl@gmail.com"},
{name = "Simo Lin", email = "linsimo.mark@gmail.com"},
{name = "Keyang Ru", email = "rukeyang@gmail.com"}
]
classifiers = [
Expand Down
27 changes: 27 additions & 0 deletions scripts/check-deep-imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Checks for deeply nested internal imports (5+ path segments) in Rust files.
# Only flags crate:: and super:: paths (external crate imports are ignored).
set -euo pipefail

MAX_SEGMENTS=4
violations=0

for file in "$@"; do
[[ -f "$file" ]] || continue

# Match: use crate::a::b::c::d (5+ segments starting with crate/super)
# {4,} means 4+ additional ::word segments after crate/super = 5+ total
while IFS= read -r line_info; do
line_num="${line_info%%:*}"
line_content="${line_info#*:}"
echo " $file:$line_num:$line_content"
((violations++))
done < <(grep -nE '^\s*use\s+(crate|super)(::\w+){4,}' "$file" 2>/dev/null || true)
Comment thread
CatherineSue marked this conversation as resolved.
Resolved
done

if [[ $violations -gt 0 ]]; then
echo ""
echo "Found $violations import(s) exceeding $MAX_SEGMENTS path segments."
echo "Consider using shorter paths or re-exports to reduce import depth."
exit 1
fi
Loading