Repository navigation
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·84 lines (70 loc) · 2.66 KB
/
Copy pathformat.sh
File metadata and controls
executable file
·84 lines (70 loc) · 2.66 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 "🦀 Formatting Rust (.rs) files..."
# rustfmt is optional: most contributors are Python-only and have no Rust
# toolchain. Skip (with a hint) when it is absent instead of force-installing.
# Probe with --version rather than `command -v`: rustup puts a rustfmt shim on
# PATH even when the component is not installed for the active toolchain, and
# the shim only errors out once actually invoked.
# Run rustfmt per-file rather than `cargo fmt` so standalone .rs (cutile-rs
# skill examples, per-op kernel.rs/ffi.rs) are covered, not just crate members.
if rustfmt --version >/dev/null 2>&1; then
rs_files=$(git ls-files '*.rs')
if [ -n "$rs_files" ]; then
echo "$rs_files" | xargs rustfmt --edition 2024
echo "✅ rustfmt formatted $(printf '%s\n' "$rs_files" | wc -l) .rs file(s)."
else
echo "No tracked .rs files; skipping rustfmt."
fi
else
echo "⚠️ rustfmt not available — skipping .rs formatting."
echo " Install with: rustup component add rustfmt (see https://rustup.rs)"
fi
echo ""
echo "✅ Done! SPDX headers added, code is formatted, and imports are sorted."