-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformat_code.sh
More file actions
executable file
·62 lines (51 loc) · 1.75 KB
/
format_code.sh
File metadata and controls
executable file
·62 lines (51 loc) · 1.75 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
# format_code.sh - Reliable wrapper for black and isort
# Usage: ./format_code.sh <file_or_directory>
#
# This script ensures tools run from the correct directory and with proper paths
set -e # Exit on error
# Get the directory where this script lives (project root)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$SCRIPT_DIR"
QUICKBBS_DIR="$PROJECT_ROOT/quickbbs"
# Change to quickbbs directory (where manage.py lives)
cd "$QUICKBBS_DIR" || exit 1
echo "Working directory: $(pwd)"
echo "Formatting: $*"
echo ""
# Run black and isort on provided arguments
if [ $# -eq 0 ]; then
echo "Usage: $0 <file_or_directory> [additional files...]"
echo "Example: $0 frontend/utilities.py"
echo "Example: $0 quickbbs/frontend/managers.py"
exit 1
fi
# Normalize paths - strip "quickbbs/" prefix if present since we're already in that directory
NORMALIZED_ARGS=()
for arg in "$@"; do
# Remove leading "quickbbs/" if present
normalized="${arg#quickbbs/}"
# Check if the normalized path exists relative to current directory
if [ -e "$normalized" ]; then
NORMALIZED_ARGS+=("$normalized")
echo " → $normalized"
else
# If it doesn't exist, try the original path (might be absolute)
if [ -e "$arg" ]; then
NORMALIZED_ARGS+=("$arg")
echo " → $arg"
else
echo "Warning: Cannot find $arg or $normalized - trying anyway"
NORMALIZED_ARGS+=("$normalized")
fi
fi
done
echo ""
# Run black
echo "Running black..."
black "${NORMALIZED_ARGS[@]}" || { echo "Black failed"; exit 1; }
# Run isort
echo "Running isort..."
isort "${NORMALIZED_ARGS[@]}" || { echo "Isort failed"; exit 1; }
echo ""
echo "✅ Formatting complete!"