-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat-all.sh
More file actions
executable file
·32 lines (24 loc) · 1.15 KB
/
format-all.sh
File metadata and controls
executable file
·32 lines (24 loc) · 1.15 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
#!/bin/bash
# Script to format all Python files according to project rules that aren't ignored by gitignore
echo "===== Formatting Python Files ====="
# Check if tools are installed
command -v black >/dev/null 2>&1 || { echo "Error: black is not installed. Run: pip install black"; exit 1; }
command -v isort >/dev/null 2>&1 || { echo "Error: isort is not installed. Run: pip install isort"; exit 1; }
command -v flake8 >/dev/null 2>&1 || { echo "Error: flake8 is not installed. Run: pip install flake8"; exit 1; }
command -v git >/dev/null 2>&1 || { echo "Error: git is not installed."; exit 1; }
# Find all Python files tracked by git (respects .gitignore)
PYTHON_FILES=$(git ls-files "*.py")
if [ -z "$PYTHON_FILES" ]; then
echo "No Python files found that are tracked by git."
exit 0
fi
# Format files with black
echo "Running Black formatter..."
black $PYTHON_FILES
# Sort imports with isort (using black compatibility)
echo -e "\nSorting imports with isort..."
isort --profile black $PYTHON_FILES
# Check remaining issues with flake8
echo -e "\nChecking for remaining issues with flake8..."
flake8 $PYTHON_FILES
echo -e "\n===== Formatting complete ====="