#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2023 Marcel Telka
#

%patch% 01-setuptools-2to3.patch
%patch% 02-test-fixes.patch
%patch% 03-test-locals.patch
%patch% 04-test-coverage.patch
%patch% 05-test-twisted.patch
%patch% 06-DefaultPluginManager.patch

%include-2%
# nose uses custom testing via the selftest.py script
TEST_STYLE = custom
%include-3%
# Support for 2to3 was removed in setuptools 58.0.0 so we cannot rely on
# use_2to3 and we need to convert the code explicitly here.
COMPONENT_PRE_BUILD_ACTION += 2to3-$(PYTHON_VERSION) --write --nobackups --no-diffs $(@D) ;

# We need to convert tests from Python 2 syntax to Python 3 syntax before we
# run them.  See selftest.py for details.
COMPONENT_PRE_TEST_ACTION = \
	cd $(@D) ; $(PYTHON) setup.py --no-user-cfg build_tests ;

# Custom test style
COMPONENT_TEST_CMD =		$(PYTHON) selftest.py
COMPONENT_TEST_ARGS =
COMPONENT_TEST_TARGETS =

# Get verbose test results
COMPONENT_TEST_ENV +=		NOSE_VERBOSE=2

# Normalize pointers
COMPONENT_TEST_TRANSFORMS += "-e 's/0x[0-9a-f]\{12\}/\$$(POINTER)/g'"

# teamcity-messages pollutes test report and causes test_issue135 to fail
TEST_CONFLICTING_PACKAGES.python += library/python/teamcity-messages

# Manually added test dependencies
TEST_REQUIRED_PACKAGES.python += library/python/twisted
%hook-no-license%
cat "$SOURCE_DIR/lgpl.txt" > "$DISTRIBUTION.license"
# The lgpl.txt file contains "Franklin St" instead of "Franklin Street" so
# license-detector fails
LICENSE="LGPL-2.1-only"