Skip to content

Commit

Permalink
Create bootstrap-py.sh
Browse files Browse the repository at this point in the history
Bootstrap script for python using ctags -x and PYTHONPATH.

Assumes the top-level comment of the first block to be a description of the project.
  • Loading branch information
petterik authored and inimino committed Jun 18, 2024
1 parent 5e203eb commit f092135
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions bootstrap-py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

remove_common_python_functions() {
grep -v '__len__' | grep -v '__getitem__'
}

# 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 | remove_common_python_functions
fi
done
}

cat <<EOF
Here's a description for a program I'm currently working on:
\`\`\`python
EOF

echo -n "$(cmpr --print-block 1)"

cat <<EOF
\`\`\`
Current imports:
\`\`\`python
EOF

echo -n "$(cmpr --print-block $(cmpr --find-block "Imports"))"

cat <<EOF
\`\`\`
Output from \`ctags -x\` run on the program:
\`\`\`
EOF

# Find Python files in current directory, excluding dot-prefixed directories
for f in `ls *.py`; do
ctags -x "$f" | remove_common_python_functions
done

for dir in "$@"; do
find "$dir" -type d \( -name ".*" -prune \) -o -type f -name '*.py' -exec ctags -x {} + | remove_common_python_functions
done

cat <<EOF
\`\`\`
Output from \`ctags -x\` run on library code I've written:
\`\`\`
EOF

# Process PYTHONPATH directories
process_pythonpath

cat <<EOF
\`\`\`
I will provide you with descriptions and you will provide me with code that satisfies the description.
Reply with only with OK.
EOF

0 comments on commit f092135

Please sign in to comment.