#!/usr/bin/make -f


export PYBUILD_TEST_PYTEST=1
# Tests are fully written for Python3
export PYBUILD_DISABLE_python2=test
# This file has different version and gives syntax error
export PYBUILD_AFTER_INSTALL_python2=rm -f {destdir}/{install_dir}/gym/utils/reraise_impl_py3.py
export PYBUILD_AFTER_INSTALL_python3=rm -f {destdir}/{install_dir}/gym/utils/reraise_impl_py2.py
export PYBUILD_TEST_ARGS=cd {build_dir}; xvfb-run $(XVFB_OPTS) python{version} -m pytest -v -k "$(EXCLUDED_TESTS)"
export PYBUILD_NAME=gym

XVFB_OPTS=--auto-servernum --server-num=20 -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset"

EXCLUDED_TESTS :=
# atari package is not available
EXCLUDED_TESTS += not atari
EXCLUDED_TESTS += and not spec26
EXCLUDED_TESTS += and not spec27
EXCLUDED_TESTS += and not spec28
EXCLUDED_TESTS += and not spec29
EXCLUDED_TESTS += and not spec30
EXCLUDED_TESTS += and not spec31
EXCLUDED_TESTS += and not spec32
EXCLUDED_TESTS += and not spec33
EXCLUDED_TESTS += and not spec34
EXCLUDED_TESTS += and not spec35
EXCLUDED_TESTS += and not spec36
EXCLUDED_TESTS += and not spec37
EXCLUDED_TESTS += and not spec43
EXCLUDED_TESTS += and not spec44
EXCLUDED_TESTS += and not spec45
EXCLUDED_TESTS += and not spec46
EXCLUDED_TESTS += and not spec47
EXCLUDED_TESTS += and not spec48
EXCLUDED_TESTS += and not spec49
EXCLUDED_TESTS += and not spec50
EXCLUDED_TESTS += and not spec51
EXCLUDED_TESTS += and not spec52
EXCLUDED_TESTS += and not spec53
EXCLUDED_TESTS += and not spec54
EXCLUDED_TESTS += and not spec55
# RuntimeError: generator raised StopIteration, at least on Python 3.7
EXCLUDED_TESTS += and not spec4
# With older scipy
# _parse_args_rvs() got an unexpected keyword argument 'random_state'
SCIPY_VERSION := $(shell dpkg-query -W -f='$${Version}' python3-scipy)
ifeq ($(shell dpkg --compare-versions $(SCIPY_VERSION) lt 0.17~ && echo yes),yes)
  EXCLUDED_TESTS += and not spec18
endif


# Get version from changelog as well as lsb_release
# to compute unique build version (useful for repo mirroring systems doing file pooling)
PKG_VERSION  := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DIST_NAME    := $(shell lsb_release -si)
DIST_RELEASE := $(shell lsb_release -sc)
DIST_VERSION := $(shell lsb_release -sr)
PKG_VERSION_TAG := $(PKG_VERSION)+$(DIST_NAME).$(DIST_RELEASE).$(DIST_VERSION)
SUBSTVARS_BINARY_VERSION := -Vbinary:Version="$(PKG_VERSION_TAG)"
SUBSTVARS_SOURCE_VERSION := -Vsource:Version="$(PKG_VERSION_TAG)"

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

override_dh_auto_test:
	PYBUILD_SYSTEM=custom dh_auto_test

override_dh_gencontrol:
	dh_gencontrol -- -v"$(PKG_VERSION_TAG)" $(SUBSTVARS_BINARY_VERSION) $(SUBSTVARS_SOURCE_VERSION)
