-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·62 lines (49 loc) · 1.63 KB
/
format.sh
File metadata and controls
executable file
·62 lines (49 loc) · 1.63 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
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: MIT
# Quick formatting script for TileGym development
# Formats code and sorts imports using ruff
set -e
RUFF_VERSION="0.14.9"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "Checking pre-commit installation..."
if ! command -v pre-commit &> /dev/null; then
echo "📦 Installing pre-commit..."
pip install pre-commit
fi
echo ""
echo "Installing pre-commit hooks..."
pre-commit install-hooks
echo ""
echo "Running all formatting and checks..."
# Run pre-commit on all files, continue even if some checks fail
# (some hooks like ruff are auto-fixers and will modify files)
set +e # Temporarily allow errors to see full output
pre-commit run --all-files
exit_code=$?
set -e # Re-enable error exit
if [ $exit_code -ne 0 ]; then
echo ""
echo "Some files were modified by auto-fixers. Running again to verify..."
pre-commit run --all-files
fi
echo ""
echo "✅ Done! All checks of pre-commit hooks completed."
echo "🔍 Checking ruff installation..."
if ! python3 -m ruff --version 2>/dev/null | grep -q "$RUFF_VERSION"; then
echo "📦 Installing ruff $RUFF_VERSION..."
pip install "ruff==$RUFF_VERSION"
fi
echo ""
echo "📝 Adding SPDX headers to files..."
python3 .github/scripts/check_spdx_headers.py --action write
echo ""
echo "📋 Sorting imports..."
python3 -m ruff check --select I --fix .
echo ""
echo "✨ Formatting code..."
python3 -m ruff format .
echo ""
echo "✅ Done! SPDX headers added, code is formatted, and imports are sorted."