Skip to content

Commit 0ffeace

Browse files
committed
simplified the run-all script in boids so it can be used with the chatbot as well
1 parent d98802a commit 0ffeace

File tree

2 files changed

+73
-52
lines changed

2 files changed

+73
-52
lines changed

notebooks/tps/boids/.teacher/run-all.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# find the current folder name without the teacher part
4+
5+
function find-stem() {
6+
while true; do
7+
stem=$(basename $(pwd))
8+
[[ "$stem" == "/" ]] && {
9+
echo "SLASH"
10+
return
11+
}
12+
! [[ $stem =~ .*teacher.* ]] && {
13+
echo $stem
14+
return
15+
}
16+
cd ..
17+
done
18+
}
19+
20+
STEM=$(find-stem)
21+
22+
23+
# extract the docstring from a file
24+
25+
function extract-docstring() {
26+
local input="$1"; shift
27+
python << EOF
28+
import ast
29+
30+
with open('${input}') as f:
31+
code = ast.parse(f.read())
32+
33+
for node in ast.walk(code):
34+
# if isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.Module)):
35+
if isinstance(node, (ast.Module)):
36+
docstring = ast.get_docstring(node)
37+
if docstring:
38+
print(docstring)
39+
EOF
40+
}
41+
42+
43+
function run-one() {
44+
local current="$1"; shift
45+
[[ -f $current ]] || {
46+
echo "File not found: $current"
47+
return
48+
}
49+
echo ========== "$current "
50+
extract-docstring $current
51+
# python $current "$@" 2>&1 | grep -v 'Warning: Expected'
52+
python $current
53+
}
54+
55+
function run-all() {
56+
local current
57+
for current in ${STEM}-[0-9]*.py $FOCUS; do
58+
[[ -f $current ]] || continue
59+
run-one $current
60+
done
61+
}
62+
63+
function main() {
64+
if [[ -z "$@" ]]; then
65+
run-all
66+
else
67+
for current in "$@"; do
68+
run-one $current
69+
done
70+
fi
71+
}
72+
73+
main "$@"

notebooks/tps/boids/.teacher/util.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)