diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-02-01 22:56:27 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 531f376274ba214f3b414ee92ae38f1185340f55 (patch) | |
tree | a7aa52f700b866611220a21d62ffd2ebe5bca5af /build.sh | |
parent | 8d41a996d7d3bbe27ec7d127d8695a9908081a7d (diff) | |
download | wee-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`.
Diffstat (limited to 'build.sh')
-rwxr-xr-x | build.sh | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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 |