bump 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Bump version of python package in current directory.
  3. # Updates version in package/__init__.py, and version embedded as
  4. # reStructuredtext in README.
  5. #
  6. # Usage: BUMP package_name [new_version] [-c]
  7. # If new_version is not specified the release part of the version will
  8. # be incremented.
  9. # if -c is set it will be commited and pushed.
  10. bump_version () {
  11. commit=0
  12. while getopts "c" flag; do
  13. case $flag in
  14. c)
  15. commit=1
  16. ;;
  17. esac
  18. done
  19. shift $(($OPTIND - 1))
  20. package="$1"
  21. new_version="$2"
  22. [ $commit ] && git pull origin master
  23. current=$(python -c "
  24. import $package
  25. print($package.__version__)
  26. ")
  27. cur_major=$(echo "$current" | cut -d. -f 1)
  28. cur_minor=$(echo "$current" | cut -d. -f 2)
  29. cur_release=$(echo "$current" | cut -d. -f 3)
  30. if [ -z "$new_version" ]; then
  31. new_version="$cur_major.$cur_minor.$(($cur_release + 1))";
  32. new_as_tuple="($cur_major, $cur_minor, $(($cur_release + 1)))";
  33. fi
  34. new_major=$(echo "$new_version" | cut -d. -f 1)
  35. new_minor=$(echo "$new_version" | cut -d. -f 2)
  36. new_release=$(echo "$new_version" | cut -d. -f 3)
  37. new_as_tuple="($new_major, $new_minor, $new_release)"
  38. echo "$package: $current -> $new_version"
  39. perl -pi -e"s/(VERSION\s*=\s*)\((.+?)\);?/\$1$new_as_tuple/" \
  40. "$package/__init__.py"
  41. perl -pi -e"s/(:Version:)\s*(.+?)(\s*$)/\$1 $new_version\$3/i" README
  42. [ $commit ] && (
  43. git commit "$package/__init__.py" README \
  44. -m "Bumped version to $new_version";
  45. git push;
  46. )
  47. }
  48. if [ -z "$1" ]; then
  49. echo "Usage: $(basename $0) package_name [new_version]"
  50. exit 1
  51. fi
  52. bump_version $*