# Template file for 'python-sqlalchemy-migrate'
pkgname=python-sqlalchemy-migrate
version=0.9.1
revision=1
noarch=yes
wrksrc="${pkgname#*-}-${version}"
build_style=python-module
python_versions="2.7 3.4"
hostmakedepends="python-setuptools python3.4-setuptools"
makedepends="
 python-pbr python3.4-pbr python-SQLAlchemy python3.4-SQLAlchemy
 python-decorator python3.4-decorator python-six python3.4-six
 python-tempita python3.4-tempita"
depends="python python-SQLAlchemy python-decorator python-six python-tempita"
replaces="sqlalchemy-migrate>=0"
pycompile_module="migrate"
short_desc="Database schema migration for SQLAlchemy (Python2)"
maintainer="Alessio Sergi <al3hex@gmail.com>"
homepage="https://github.com/stackforge/sqlalchemy-migrate"
license="MIT"
distfiles="https://pypi.python.org/packages/source/s/sqlalchemy-migrate/sqlalchemy-migrate-${version}.tar.gz"
checksum=16e327c9642ca4c99a70dcac3b39aeb821edaf5214834b47fb0a89bac44af23b

post_extract() {
	cp -a ${wrksrc} /tmp/python2.7-build
	cp -a ${wrksrc} /tmp/python3.4-build
	mv /tmp/python{2.7,3.4}-build ${wrksrc}
}

pre_build() {
	cd ${wrksrc}/python3.4-build
	sed -i 's,migrate =,migrate3 =,;s,migrate-repository =,migrate-repository3 =,' setup.cfg
	find . -type f -name '*.py' -exec sed -i -e '/^#!/s,python$,&3.4,' {} +
}

do_build() {
	cd ${wrksrc}/python2.7-build
	python setup.py build

	cd ${wrksrc}/python3.4-build
	python3.4 setup.py build
}

do_install() {
	cd ${wrksrc}/python2.7-build
	python setup.py install --root=${DESTDIR}

	cd ${wrksrc}/python3.4-build
	python3.4 setup.py install --root=${DESTDIR}
}

post_install() {
	vlicense COPYING LICENSE
}

python3.4-sqlalchemy-migrate_package() {
	noarch=yes
	depends="python python3.4-SQLAlchemy python3.4-decorator python3.4-six python3.4-tempita"
	pycompile_version="3.4"
	pycompile_module="migrate"
	short_desc="${short_desc/Python2/Python3.4}"
	pkg_install() {
		vmove usr/bin/migrate*3
		vmove usr/lib/python3.4
		vlicense ${wrksrc}/COPYING LICENSE
	}
}
