## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%bcond tests 1

# For scidash
%global scidash_commit 5d47042d3eb40abcb062ba15f90f64d4d208d433
%global scidash_shortcommit     %(c=%{scidash_commit}; echo ${c:0:7})

%global _description %{expand:
A framework for validating scientific models by creating
experimental-data-driven unit tests.}

Name:           python-sciunit
Version:        0.2.8
Release:        %autorelease
Summary:        Framework for test-driven validation of scientific models

License:        MIT
URL:            http://sciunit.io/

# For tagged releases on Github: pypi does not include docs etc.
Source0:        https://github.com/scidash/sciunit/archive/v%{version}/sciunit-%{version}.tar.gz

# Required for tests
# https://github.com/scidash/sciunit/blob/0.2.2/test.sh#L3
Source1:        https://github.com/scidash/scidash/archive/%{scidash_commit}/scidash-%{scidash_shortcommit}.tar.gz

BuildArch:      noarch

%description %_description

%package -n python3-sciunit
Summary:        %{summary}
BuildRequires:  git-core
BuildRequires:  python3-devel

# Part of sciunit/utils.py (marked by a comment) was copied from cypy in
# https://github.com/scidash/sciunit/commit/28612172bf23c25a9f81ffe5578265aa8849f813.
# The version is assumed; there was only a single release on PyPI at the time.
#
# Upstream was asked to comment per packaging guidelines:
# “Statement on bundling cypy?”
# https://github.com/scidash/sciunit/issues/215
Provides:       bundled(python3dist(cypy)) = 0.2

%description -n python3-sciunit %_description

%prep
%autosetup -n sciunit-%{version} -S git

# Update requirements, our package does not provide bs4
# Remove version pins
# Remove backports.tempfile, we use what's in py3
sed -i -e 's/bs4/beautifulsoup4/' -e '/backports/ d' -e 's/importlib-metadata.*/importlib-metadata/' setup.cfg
sed -i -e 's/backports.tempfile/tempfile/' sciunit/utils.py

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files -l sciunit

%check
%if %{with tests}
# https://github.com/scidash/sciunit/blob/master/test.sh
tar -xf %{SOURCE1}
mv scidash-%{scidash_commit} ../scidash
# Disable test that requires it to be a git repo by adding the necessary decorator
sed -i '/def test_Versioned/i  \ \ \ \ @unittest.skip' sciunit/unit_test/base_tests.py
sed -i '/def test_versioned/i  \ \ \ \ @unittest.skip' sciunit/unit_test/utils_tests.py
# https://github.com/scidash/sciunit/issues/211
sed -i '/def test_source_check/i  \ \ \ \ @unittest.skip' sciunit/unit_test/model_tests.py
# Disable tests failing in Python3.12
# https://github.com/scidash/sciunit/issues/218
sed -i '/def test_testsuite/i  \ \ \ \ @unittest.skip' sciunit/unit_test/test_tests.py
sed -i '/def test_testsuite_set_verbose/i  \ \ \ \ @unittest.skip' sciunit/unit_test/test_tests.py
%{py3_test_envvars} %{python3} -m sciunit.unit_test buffer
%endif

%files -n python3-sciunit -f %{pyproject_files}
%doc README.md
%{_bindir}/sciunit

%changelog
* Thu Jan 04 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.8-1
- Update to 0.2.8 (close RHBZ#2256667)

* Thu Jan 04 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.7-14
- Assert that the .dist-info directory contains a license file

* Tue Dec 19 2023 Lumir Balhar <lbalhar@redhat.com> - 0.2.7-12
- Compatibility with nbconvert 7.13.0

* Fri Oct 13 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.7-11
- F38+: Use %%{py3_test_envvars} to set up test environment

* Tue Sep 05 2023 Sandro <devel@penguinpee.nl> - 0.2.7-10
- Get rid of da (l)imp
- Apply upstream pacth replacing `imp` with `importlib`
- Disable failing tests (reported upstream)
- Close RHBZ#2220493 and RHBZ#2226540

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Wed May 24 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.7-8
- Document cypy bundling

* Wed May 24 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.7-7
- Remove some obsolete details from the spec file
- Don’t use a macro form of “tar”
- No need to manually enable the Python run-time dependency generator
- No need to remove upstream egg-info when using pyproject-rpm-macros

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Mon Jul 04 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 0.2.7-4
- feat: use pyproject macros

* Mon Jul 04 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 0.2.7-3
- feat: fix build

* Wed Jun 15 2022 Python Maint <python-maint@redhat.com> - 0.2.2.2-9
- Rebuilt for Python 3.11

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.2.2-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.2.2-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.2.2.2-6
- Rebuilt for Python 3.10

* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.2.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.2.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Thu Jun 25 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.2.2-3
- Explicitly BR setuptools

* Tue May 26 2020 Miro Hrončok <mhroncok@redhat.com> - 0.2.2.2-2
- Rebuilt for Python 3.9

* Fri May 22 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.2.2-1
- Update to new release
- Includes fix for py3.9
- https://bugzilla.redhat.com/show_bug.cgi?id=1838486

* Thu May 07 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.2-1
- Update as per review comments #1827957
- Remove extra provides
- Improve description for doc sub package

* Sat Apr 25 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.2-1
- Initial build