# $Id: PKGBUILD 84317 2013-02-16 11:58:07Z bpiotrowski $
# Maintainer: Thomas Dziedzic < gostrc at gmail >
# Contributor: Mike Sampson <mike at sambodata dot com>
# Contributor: Anton Bazhenov <anton.bazhenov at gmail>

pkgname=('bpython' 'bpython2')
pkgver=0.12
pkgrel=2
pkgdesc='Fancy interface to the Python interpreter'
arch=('any')
url='http://bpython-interpreter.org/'
license=('MIT')
makedepends=('python-distribute' 'python2-distribute')
source=(http://bpython-interpreter.org/releases/bpython-${pkgver}.tar.gz)
md5sums=('14cbe92620d386a769b3faa282a1d6c3')

build() {
  cp -r bpython-${pkgver} bpython2-${pkgver}

  cd bpython-${pkgver}
  python setup.py build

  cd ${srcdir}/bpython2-${pkgver}
  python2 setup.py build
}

package_bpython() {
  depends=('python-pygments')
  optdepends=('python-urwid: for bpython-urwid')

  cd bpython-${pkgver}

  python setup.py install \
    --root=${pkgdir} \
    --optimize=1

  install -Dm644 LICENSE \
    ${pkgdir}/usr/share/licenses/bpython/LICENSE

  # pygtk isn't available for python3 (fs#33705)
  rm $pkgdir/usr/bin/bpython-gtk
}

package_bpython2() {
  depends=('python2-pygments')
  optdepends=('pygtk: for bpython2-gtk'
              'python2-urwid: for bpython2-urwid')

  cd bpython2-${pkgver}

  python2 setup.py install \
    --root=${pkgdir} \
    --optimize=1

  install -Dm644 LICENSE \
    ${pkgdir}/usr/share/licenses/bpython2/LICENSE

  # conflicting files with bpython
  mv ${pkgdir}/usr/bin/bpython \
    ${pkgdir}/usr/bin/bpython2
  mv ${pkgdir}/usr/bin/bpython-gtk \
    ${pkgdir}/usr/bin/bpython2-gtk
  mv ${pkgdir}/usr/bin/bpython-urwid \
    ${pkgdir}/usr/bin/bpython2-urwid
  mv ${pkgdir}/usr/share/applications/bpython.desktop \
    ${pkgdir}/usr/share/applications/bpython2.desktop

  # fix the .desktop file for the rename
  sed \
    -e 's/bpython/&2/' \
    -i ${pkgdir}/usr/share/applications/bpython2.desktop
}
