This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_2to3.sh
executable file
·84 lines (74 loc) · 2.61 KB
/
run_2to3.sh
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
# Check if stdout is a tty and supports color
# If not, they will be undefined and hence resolve to empty strings
if test -t 1
then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8
then
C_RED='\033[1;31m'
C_GREEN='\033[1;32m'
C_BLUE='\033[1;34m'
C_YELLOW='\033[1;33m'
C_NC='\033[0m'
fi
fi
# Function to check if a list (string of space-separated words)
# contains a string
function contains() {
local haystack="$1"
local needle="$2"
if [[ $haystack =~ (^|[[:space:]])"$needle"($|[[:space:]]) ]]
then
res=0
else
res=1
fi
return $res
}
# Fixers that we want to skip, e.g. because they just break things
# funcattrs: Fixes nothing, just breaks a couple lines
# idioms: All valid changes were backported, now just breaks a couple lines
# noop_u: u'' r'' is a noop on py3. We can do this at a later point
# object_super: class foo(object): is a noop on py3. We can do this at a later point
# unicode_literals: u'' is a noop on py3. We can do this at a later point
# ws_comma: Pure PEP8 fixer. Will be done when/if we PEP8 the codebase
SKIPPED_FIXERS="funcattrs idioms noop_u object_super unicode_literals ws_comma"
# The working directory that the script was run in
WORKING_DIR="$(pwd)"
# The directory that we want to run 2to3 on
TARGET_DIR="$(readlink -fn ../wrye-bash)"
cd "$TARGET_DIR"
# Check that the user won't have existing changes added into our commits
if [ ! -z "$(git status --porcelain)" ]
then
echo -e "${C_RED}Error:${C_NC} $TARGET_DIR has uncommited changes."
echo "Commit or stash them before running this script."
exit 1
fi
# Disable commit signing temporarily to avoid the 50+ popups
git config --local commit.gpgSign false
cd "$WORKING_DIR"
fixers="$(python3 -m lib2to3 -l | tail -n +2)"
echo -e "${C_BLUE}::${C_NC} Running $(echo $fixers | wc -w) fixers"
while IFS= read -r fixer
do
# Skip this fixer if it's in SKIPPED_FIXERS
if $(contains "$SKIPPED_FIXERS" "$fixer")
then
echo -e "${C_YELLOW}::${C_NC} Skipping fixer '$fixer'"
continue
fi
echo -e "${C_YELLOW}::${C_NC} Running fixer '$fixer'"
# Silently run the fixer, then commit the result
python3 -m lib2to3 -f "$fixer" -w -n --no-diff "$TARGET_DIR"
cd "$TARGET_DIR"
git commit -a -m "2to3: Run fixer '$fixer'"
cd "$WORKING_DIR"
echo -e "${C_GREEN}::${C_NC} Finished running fixer '$fixer'"
done <<< "$fixers"
# Unset the gpgSign config option again
cd "$TARGET_DIR"
git config --local --unset commit.gpgSign
cd "$WORKING_DIR"
echo -e "${C_BLUE}::${C_NC} Done running all fixers"