aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-02-01 22:56:27 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit531f376274ba214f3b414ee92ae38f1185340f55 (patch)
treea7aa52f700b866611220a21d62ffd2ebe5bca5af
parent8d41a996d7d3bbe27ec7d127d8695a9908081a7d (diff)
downloadwee-slack-531f376274ba214f3b414ee92ae38f1185340f55.tar.gz
Handle multiline and indented imports in build.sh
This is pretty hacky, the awk script joins some lines it shouldn't so I should look into that, but now it works without manual changes at least. Any indented import is assumed to be within `if TYPE_CHECKING` and replaced with `pass`.
-rwxr-xr-xbuild.sh8
1 files changed, 6 insertions, 2 deletions
diff --git a/build.sh b/build.sh
index 5fcfbdf..3247682 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,11 @@
#!/bin/bash
-contents="$(cat slack/*.py main.py | grep -Ev '^from slack[. ]')"
+shopt -s extglob
+
+contents="$(cat slack/util.py slack/task.py slack/!(util|task).py main.py | \
+ awk -v RS='\\([^)]+\\)' '/from.*import/ {gsub(/[[:space:]]+/, "", RT)} {ORS=RT} 1' | \
+ grep -Ev '^from slack[. ]')"
echo "$contents" | grep '^from __future__' | sort -u > build/slack.py
echo "$contents" | grep -v '^from __future__' | grep -E '^(import|from)' | sort -u >> build/slack.py
-echo "$contents" | grep -Ev '^(import|from)' >> build/slack.py
+echo "$contents" | grep -Ev '^(import|from)' | sed 's/^\( \+\)\(import\|from\).*/\1pass/' >> build/slack.py