-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
combine.sh
executable file
·61 lines (52 loc) · 1.21 KB
/
combine.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
#!/usr/bin/env bash
src="./src/brew_file"
dest="./bin/brew-file"
ruff check --fix "$src"
ruff format "$src"
tmp_backup=$(mktemp)
if [ -f "$dest" ];then
mv "$dest" "$tmp_backup"
echo "Old brew-file was moved to $tmp_backup"
fi
imports=""
contents=""
for f in "$src/"{info.py,utils.py,brew_helper.py,brew_info.py,brew_file.py,main.py}; do
import_flag=0
while IFS= read -r line;do
if [ "$import_flag" -gt 0 ]; then
if [ "$import_flag" -eq 1 ]; then
imports="$imports$line"$'\n'
fi
if [[ "$line" =~ \) ]];then
import_flag=0
fi
elif [[ "$line" =~ (^from|^import) ]];then
if [[ ! "$line" =~ from\ *\. ]];then
imports="$imports$line"$'\n'
fi
if [[ "$line" =~ \( ]] && [[ ! "$line" =~ \) ]];then
if [[ "$line" =~ from\ *\. ]];then
import_flag=2
else
import_flag=1
fi
fi
else
contents="$contents$line"$'\n'
fi
done < "$f"
done
{
echo "#!/usr/bin/env python3"
echo "$imports"
echo "$contents"
} > "$dest"
chmod 755 "$dest"
ruff check --fix "$dest"
ruff format "$dest"
if [ -f "$tmp_backup" ];then
diff -u "$tmp_backup" "$dest"
else
echo "bin/brew-file was created newly"
exit 1
fi