-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap-py.sh
63 lines (46 loc) · 1.5 KB
/
bootstrap-py.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
#!/bin/bash
filter_common_python_functions() {
grep -v '__len__' | grep -v '__getitem__' | awk '{split($4,a,"/"); $4=a[length(a)]; print $0}' | sort -n -k 3
}
# Function to check and process Python files in directories from PYTHONPATH
process_pythonpath() {
IFS=':' read -ra DIRS <<< "$PYTHONPATH"
for dir in "${DIRS[@]}"; do
# Check if directory contains __init__.py
if [ -f "$dir/__init__.py" ]; then
# If yes, find Python files in this directory
find "$dir" -maxdepth 1 -type f -name '*.py' -exec ctags -x {} + | grep -v namespace | grep -v variable | filter_common_python_functions
fi
done
}
cat <<EOF
I'm working on a Python program.
Top level comment:
\`\`\`python
EOF
echo -n "$(cmpr --print-block 1)"
cat <<EOF
\`\`\`
Existing functions:
\`\`\`
EOF
# Find Python files in current directory, excluding dot-prefixed directories
for f in `ls *.py`; do
ctags -x "$f" | filter_common_python_functions
done
for dir in "$@"; do
find "$dir" -type d \( -name ".*" -prune \) -o -type f -name '*.py' -exec ctags -x {} + | filter_common_python_functions
done
cat <<EOF
\`\`\`
You can also utilize thse library functions:
\`\`\`
EOF
# Process PYTHONPATH directories
process_pythonpath
cat <<EOF
\`\`\`
I will provide you with descriptions of code. Use existing functions, library code and 3rd party libraries and provide me with code that satisfies the description.
Don't redefine functions that already exist, just use them.
Reply only with OK.
EOF