#!/usr/bin/make -f

include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --buildsystem=pybuild --with python3

override_dh_auto_clean:
	python3 setup.py clean
	rm -rf build .stestr *.egg-info .pytest_cache
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_auto_build:
	echo "Do nothing..."

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2 --in-tmp

	mkdir -p $(CURDIR)/debian/tmp/etc/rally
	oslo-config-generator --output-file $(CURDIR)/debian/tmp/etc/rally/rally-openstack.conf \
		--namespace rally \
		--namespace rally_openstack \
		--namespace oslo.db \
		--namespace oslo.log

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	set -e ; set -x ; for PYVER in $(PYTHON3S); do \
		PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages \
			PYTHON=python$$PYVER \
			python$$PYVER -m pytest -Wignore -Wignore::pytest.PytestCollectionWarning --ignore tests/unit/test_pytest_launcher.py tests/unit -k 'not test_all_plugins_have_docstrings and not test_schema_is_valid and not test_schema_is_valid and not test_plugins_loaded' ; \
	done
endif

	dh_install

	mkdir -p $(CURDIR)/debian/python3-rally-openstack/etc/rally
	mv $(CURDIR)/debian/python3-rally-openstack/usr/lib/python3/dist-packages/rally_openstack/verification/tempest/config.ini \
		$(CURDIR)/debian/python3-rally-openstack/etc/rally/
	ln -s /etc/rally/config.ini $(CURDIR)/debian/python3-rally-openstack/usr/lib/python3/dist-packages/rally_openstack/verification/tempest/config.ini
	
#	rm -rf $(CURDIR)/debian/python3-rally/usr/etc
#	mv $(CURDIR)/debian/python3-rally/usr/bin $(CURDIR)/debian/rally/usr


override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
	rm -rf $(CURDIR)/debian/python3-rally-openstack/usr/share/doc/python3-rally-openstack/rally-jobs/plugins/__pycache__
	rm -rf $(CURDIR)/debian/python3-rally-openstack/usr/share/doc/python3-rally-openstack/rally-jobs/plugins/test_relative_import/__pycache__