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

# Require mpi for tests, and seem to hang in Mock, so disabled by default
%bcond_with tests

%global _description %{expand: \
SpyKING CIRCUS is a python code to allow fast spike sorting on multi channel
recordings. A publication on the algorithm can be found at
https://elifesciences.org/articles/34518.

It has been tested on datasets coming from in vitro retina with 252 electrodes
MEA, from in vivo hippocampus with tetrodes, in vivo and in vitro cortex data
with 30 and up to 4225 channels, with good results. Synthetic tests on these
data show that cells firing at more than 0.5Hz can be detected, and their
spikes recovered with error rates at around 1%, even resolving overlapping
spikes and synchronous firing. It seems to be compatible with optogenetic
stimulation, based on experimental data obtained in the retina.}


%global forgeurl  https://github.com/spyking-circus/spyking-circus

Name:           python-spyking-circus
Version:        1.1.0
Release:        %autorelease
Summary:        Fast and scalable spike sorting of large-scale extracellular recordings

%global tag  %{version}
%forgemeta

# Automatically converted from old format: CeCILL - review is highly recommended.
License:        LicenseRef-Callaway-CeCILL
URL:            %forgeurl
Source0:        %forgesource

# We install the probe files to datadir
Patch0:         set-probe-datadir.patch
BuildArch:      noarch

%description %_description


%package -n python3-spyking-circus
Summary:        %{summary}
BuildRequires:  python3-devel
BuildRequires:  /usr/bin/patch
%if %{with tests}
BuildRequires:  mpich-devel
BuildRequires:  python3-mpi4py-mpich
BuildRequires:  openmpi-devel
BuildRequires:  python3-mpi4py-openmpi
BuildRequires:  python3-pytest
%endif

%description -n python3-spyking-circus %_description


%package -n python3-spyking-circus-common
Summary:        Common files for %{name}

%description -n python3-spyking-circus-common %_description

# MPICH meta package
%package -n python3-spyking-circus-mpich
Summary:        Meta package for %{name}
Requires:       python3-mpi4py-mpich
Requires:       python3-spyking-circus%{?_isa} = %{version}-%{release}

%description -n python3-spyking-circus-mpich %_description

# OpenMPI meta package
%package -n python3-spyking-circus-openmpi
Summary:        Meta package for %{name}
Requires:       python3-mpi4py-openmpi
Requires:       python3-spyking-circus%{?_isa} = %{version}-%{release}

%description -n python3-spyking-circus-openmpi %_description

%prep
%forgeautosetup -S patch

# Set the path to datadir
sed -i "s|SED_ME|%{_datadir}/spyking-circus/|" setup.py

# remove mpi4py from requires, we add it manually
sed -i "s/'mpi4py', //" setup.py

# Remove env
find . -type f -name "*.py" -exec sed -i '/^#![  ]*\/usr\/bin\/env.*$/ d' {} 2>/dev/null ';'

# Remove nose from tests: we use pytest
sed -i 's/nose,//' tests/__init__.py

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

%install
%pyproject_install
# remove duplicate installed files
mkdir -m 0755 -p $RPM_BUILD_ROOT/%{_datadir}/spyking-circus/
mv $RPM_BUILD_ROOT/%{python3_sitelib}/usr/share/spyking-circus/* $RPM_BUILD_ROOT/%{_datadir}/spyking-circus/
rm -rf $RPM_BUILD_ROOT/%{python3_sitelib}/usr/

%pyproject_save_files -l circus

%check
%if %{with tests}
%{_mpich_load}
%{pytest} tests/
%{_mpich_unload}

%{_openmpi_load}
%{pytest} tests/
%{_openmpi_unload}
%endif

%files -n python3-spyking-circus -f %{pyproject_files}
%doc README.rst
%{_bindir}/circus-artefacts
%{_bindir}/circus-folders
%{_bindir}/circus-gui-matlab
%{_bindir}/circus-gui-python
%{_bindir}/circus-multi
%{_bindir}/spyking-circus
%{_bindir}/spyking-circus-launcher
%{_bindir}/spyking-circus-subtask
%{_datadir}/spyking-circus

%changelog
## START: Generated by rpmautospec
* Wed Sep 04 2024 Miroslav Suchý <msuchy@redhat.com> - 1.1.0-14
- convert license to SPDX

* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sat Jun 15 2024 Python Maint <python-maint@redhat.com> - 1.1.0-12
- Rebuilt for Python 3.13

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

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

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

* Wed Jul 12 2023 Python Maint <python-maint@redhat.com> - 1.1.0-6
- Rebuilt for Python 3.12

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

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

* Wed Jun 29 2022 Python Maint <python-maint@redhat.com> - 1.1.0-3
- Rebuilt for Python 3.11

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

* Sun Jan 16 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 1.1.0-1
- feat: update to 1.1.0

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

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

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

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

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

* Sun Apr 26 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.9.7-1
- Update for review
- Remove mpi4py from auto-requires: we add them explicitly for the mpi implementations
- Correct readme.txt

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

## END: Generated by rpmautospec