#! /bin/sh

cd "`dirname \"$0\"`"/cheetah3 &&
umask 022 &&
chmod -R a+rX . &&

set-commit-date.py &&
../build-docs &&

if [ ! -d build ]; then mkdir build; fi &&
python setup.py sdist &&

for py in 2.7 3.3 3.4 3.5 3.6; do
   find build -name '*.py[co]' -delete &&
   python$py setup.py build_ext &&
   python$py setup.py build --executable '/usr/bin/env python' &&
   python$py    -m compileall build &&
   python$py -O -m compileall build &&
   python$py setup.py bdist_egg &&
   python$py setup.py bdist_wheel &&
   cd dist &&
   v="`echo $py | sed 's/\.//'`" &&
   for f in Cheetah3-*-cp$v-*-linux_i686.whl; do
      if [ $py = 2.7 -o $py = 3.3 ]; then
         python3.4 -m auditwheel repair -w . $f
      else
         python$py -m auditwheel repair -w . $f
      fi &&
      rm $f
   done &&
   cd ..
done &&

twine upload --sign dist/* &&
exec rm -rf build dist docs/html Cheetah3.egg-info
