## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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

# Try to download data, so a few are disabled.
# We test these in mock using --with=net_tests --enable-network
%bcond_with net_tests

%global pypi_name elephant

Name:       python-elephant
Version:    0.12.0
Release:    %autorelease
Summary:    Elephant is a package for analysis of electrophysiology data in Python
License:    BSD
URL:        http://neuralensemble.org/elephant
Source0:    %{pypi_source elephant}
# All changes are here
# https://github.com/sanjayankur31/elephant/tree/fedora-0.11.1
Patch0:     0001-use-fedora-build-flags.patch

# python-pyedflib does not support s390x, so the complete dep tree needs to also exclude it
# https://src.fedoraproject.org/rpms/python-pyedflib/blob/rawhide/f/python-pyedflib.spec
ExcludeArch: s390x

# Includes a modified copy of fim, so we cannot use the system copy of pyfim.
# https://github.com/NeuralEnsemble/elephant/issues/471#issuecomment-1098908479

BuildRequires:  git-core
BuildRequires:  gcc-c++
BuildRequires:  python3-devel

%description
Elephant - Electrophysiology Analysis Toolkit Elephant is a package for the
analysis of neurophysiology data, based on Neo.

%package -n     python3-elephant
Summary:        %{summary}


%description -n python3-elephant
Elephant - Electrophysiology Analysis Toolkit Elephant is a package for the
analysis of neurophysiology data, based on Neo.

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

# Loosen scipy version cap
# https://github.com/NeuralEnsemble/elephant/issues/47
sed -i 's/scipy.*/scipy/' requirements/requirements.txt

for lib in $(find . -type f -name "*.py"); do
 sed '1{\@^#!/usr/bin/env python@d}' $lib > $lib.new &&
 touch -r $lib $lib.new &&
 mv $lib.new $lib
done

# collect all test requirements in one file
echo >> requirements/requirements-tests.txt
cat requirements/requirements-extras.txt >> requirements/requirements-tests.txt

%generate_buildrequires
%pyproject_buildrequires -r requirements/requirements-tests.txt

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files elephant

%check
# One test fails generally: reported upstream
# https://github.com/NeuralEnsemble/elephant/issues/410
# Fixed upstream (but Fedora dropped armv7hl support in F37)
# https://github.com/NeuralEnsemble/elephant/pull/500
#k="not test__UE_surrogate"

# fails on aarch64
# reported upstream: https://github.com/NeuralEnsemble/elephant/issues/479
%ifarch %{arm64}
k="${k:-}${k:+ and }not test_welch_psd_multidim_input and not test_welch_cohere_multidim_input and not test_multitaper_cohere_perfect_cohere"
%endif

# fails on ppc64le
%ifarch %{power64}
k="${k:-}${k:+ and} not test_multitaper_cohere_perfect_cohere"
%endif

%if %{without net_tests}
# Disable tests that download bits
k="${k:-}${k:+ and }not test_repr and not test__UE_surrogate and not test_spike_contrast_with_Izhikevich_network_auto and not test_Riehle_et_al_97_UE and not test_multitaper_psd_against_nitime and not test_WPLI_ and not test_victor_purpura_matlab_comparison_"
%endif

# serial
# MPI tests hang in mock and builders, not sure why, so we skip them for the moment
%pytest -v -k "${k} and not test_parallel"

%files -n python3-elephant -f %{pyproject_files}
%license LICENSE.txt elephant/spade_src/LICENSE

%changelog
* Mon Feb 27 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.12.0-2
- fix: deselect failing tests

* Mon Feb 27 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.12.0-1
- feat: update to 0.12.0 (fixes rhbz#2137931, fixes rhbz#2173307)

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

* Sun Oct 09 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.11.1-3
- feat: exclude s390x

* Fri Sep 09 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.11.1-2
- chore: add comment about upstream fix

* Fri Sep 09 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.11.1-1
- feat: update to 0.11.1

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

* Mon Jul 04 2022 Python Maint <python-maint@redhat.com> 0.11.0-2
- Rebuilt for Python 3.11

* Thu Apr 21 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.11.0-1
- feat: update to 0.11.0 (Fixes rhbz#2070262)

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

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

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

* Fri Mar 12 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.10.0-2
- Add py_provides macro for F32

* Thu Mar 11 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.10.0-1
- Update to new release
- Enable all non-network dependent tests
- File bug for failing tests
- Update fim tweak: no longer required in the test file
- include statsmodels dependency

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

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

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

* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.4-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Mon Dec 23 2019 Luis Bazan <lbazan@fedoraproject.org> - 0.6.4-1
- New upstream version

* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 0.6.2-5
- Rebuilt for Python 3.8

* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Fri Jun 14 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.6.2-3
- Use pyfim which is 10 times faster than the python fast_fca according to docs
- Patch out bits that try to download fim
- Version neo requirements

* Fri Jun 14 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.6.2-2
- Report issues upstream and add links to spec file

* Tue Jun 11 2019 Luis Bazan <lbazan@fedoraproject.org> - 0.6.2-2
- Fix comment #11 BZ#1651824

* Fri Jun 07 2019 Luis Bazan <lbazan@fedoraproject.org> - 0.6.2-1
- Initial package.