-
-
Save arne-cl/2f0c4e6a87a85aabb8ef to your computer and use it in GitHub Desktop.
converts epydoc docstrings to sphinx docstrings (restructuredText)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Script for migrating from epydoc to Sphinx style docstrings. | |
# | |
# WARNING: THIS SCRIPT MODIFIES FILES IN PLACE. BE SURE TO BACKUP THEM BEFORE | |
# RUNNING IT. | |
# | |
# Forked from: https://gist.github.com/Kami/6734885 | |
DIRECTORY=$1 | |
SED=`which gsed gnused sed` | |
for value in $SED | |
do | |
SED=${value} | |
break | |
done | |
if [ ! $DIRECTORY ]; then | |
echo "Usage: ./migrate_docstrings.sh <directory with your code>" | |
exit 1 | |
fi | |
OLD_VALUES[0]='@type' | |
OLD_VALUES[1]='@keyword' | |
OLD_VALUES[2]='@param' | |
OLD_VALUES[3]='@return' | |
OLD_VALUES[4]='@rtype' | |
OLD_VALUES[5]='L{\([^}]\+\)}' | |
OLD_VALUES[6]='C{\([^}]\+\)}' | |
OLD_VALUES[7]='@\(ivar\|cvar\|var\)' | |
OLD_VALUES[8]='I{\([^}]\+\)}' | |
NEW_VALUES[0]=':type' | |
NEW_VALUES[1]=':keyword' | |
NEW_VALUES[2]=':param' | |
NEW_VALUES[3]=':return' | |
NEW_VALUES[4]=':rtype' | |
NEW_VALUES[5]=':class:`\1`' | |
NEW_VALUES[6]='``\1``' | |
NEW_VALUES[7]=':\1' | |
NEW_VALUES[8]='``\1``' | |
for (( i = 0 ; i < ${#OLD_VALUES[@]} ; i++ )) | |
do | |
old_value=${OLD_VALUES[$i]} | |
new_value=${NEW_VALUES[$i]} | |
cmd="find ${DIRECTORY} -name '*.py' -type f -print0 | xargs -0 ${SED} -i -e 's/${old_value}/${new_value}/g'" | |
echo "Migrating: ${old_value} -> ${new_value}" | |
eval "$cmd" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment