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

Name:           python-klusta
Version:        3.0.16
Release:        %autorelease
Summary:        Spike detection and automatic clustering for spike sorting

# Do not include test data in the source RPM because it does not have a known
# license. See:
#
# Please assign a license to the data
# https://github.com/kwikteam/phy-data/issues/1
#
# We use a global rather than a bcond because this affects the contents of the
# source RPM, but we leave in all the boilerplate for testing with data from
# the phy-data repository because it can still be done manually in mock builds
# outside of Fedora infrastructure, and because it will make it easy to enable
# these tests in the future if upstream does assign a proper licenses.
%global phy_data 0

License:        BSD-3-Clause
URL:            https://github.com/kwikteam/klusta
Source0:        %{pypi_source klusta}
%if 0%{?phy_data}
%global phy_data_url https://github.com/kwikteam/phy-data
%global phy_data_commit 804635aa76987a8900f3468cb08acf53139743a1
Source1:        %{phy_data_url}/archive/%{phy_data_commit}/phy-data-%{phy_data_commit}.tar.gz
%endif

# Add missing runtime/install-time dependencies to setup.py
# https://github.com/kwikteam/klusta/pull/80
#
# Includes:
#
# Require setuptools, klusta/__init__.py imports pkg_resources
# https://github.com/kwikteam/klusta/pull/76
Patch:          %{url}/pull/80.patch
# Stop using numpy type aliases that were deprecated in 1.20 and later removed
# https://github.com/kwikteam/klusta/pull/81
Patch:          %{url}/pull/81.patch
# Do not pass a float as the num argument to np.linspace
# Fixes compatibility of test_apply_filter with recent versions of numpy.
# https://github.com/kwikteam/klusta/pull/82
Patch:          %{url}/pull/82.patch

BuildArch:      noarch

BuildRequires:  python3-devel
# For tests:
BuildRequires:  %{py3_dist pytest}
BuildRequires:  %{py3_dist responses}

BuildRequires:  help2man

%global common_description %{expand:
klusta is an open source package for automatic spike sorting of multielectrode
neurophysiological recordings made with probes containing up to a few dozens of
sites.

klusta implements the following features:

  • Kwik: An HDF5-based file format that stores the results of a spike sorting
    session.
  • Spike detection (also known as SpikeDetekt): an algorithm designed for
    probes containing tens of channels, based on a flood-fill algorithm in the
    adjacency graph formed by the recording sites in the probe.
  • Automatic clustering (also known as Masked KlustaKwik): an automatic
    clustering algorithm designed for high-dimensional structured datasets.}

%description %{common_description}


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

%description -n python3-klusta %{common_description}


%prep
%autosetup -n klusta-%{version} -p1

%if 0%{?phy_data}
# Mock out a home directory with downloaded data for testing
%setup -q -n klusta-%{version} -T -D -b 1
mkdir -p _user_home/.klusta/test_data
ln -s '../../../../phy-data-%{phy_data_commit}/test/test-32ch-10s.dat' \
    _user_home/.klusta/test_data/
%endif


%generate_buildrequires
%pyproject_buildrequires


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files -l klusta

# Do this in %%install to use the generated entry point
install -d '%{buildroot}%{_mandir}/man1'
%{py3_test_envvars} help2man \
    --no-info \
    --name='Spikesort a dataset' \
    --version-string='%{version}' \
    --output='%{buildroot}%{_mandir}/man1/klusta.1' \
    '%{buildroot}%{_bindir}/klusta'


%check
%pyproject_check_import

# These tests require python3dist(klustakwik2), not packaged.
k="${k-}${k+ and }not test_klustakwik"
k="${k-}${k+ and }not test_launch_real"
k="${k-}${k+ and }not test_launch_shanks"
k="${k-}${k+ and }not test_sparsify_features_masks"

%if !0%{?phy_data}
# These tests require data from https://github.com/kwikteam/phy-data, either as
# an additional source or downloaded from the network.
k="${k-}${k+ and }not test_spike_detect_methods[real]"
k="${k-}${k+ and }not test_spike_detect_real_data[real]"
%endif

mkdir -p _empty
cd _empty
%if 0%{?phy_data}
HOME="${PWD}/../_user_home" \
%endif
    %pytest -v -k "${k-}" %{buildroot}%{python3_sitelib}/klusta


%files -n python3-klusta -f %{pyproject_files}
%doc README.md
%{_bindir}/klusta
%{_mandir}/man1/klusta.1*


%changelog
## START: Generated by rpmautospec
* Mon Dec 16 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.16-32
- Modernize packaging (fix RHBZ#2319674)
- Port to pyproject-rpm-macros
- Handle dependencies properly
- Generate a man page
- Actually run the tests
- Patch for compatibility with recent numpy versions

* Wed Sep 04 2024 Miroslav Suchý <msuchy@redhat.com> - 3.0.16-30
- convert license to SPDX

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

* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 3.0.16-28
- Rebuilt for Python 3.13

* Sat Jan 27 2024 Maxwell G <maxwell@gtmx.me> - 3.0.16-27
- Remove unused python3-mock test dependency

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

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

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

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

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

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

* Tue Jun 14 2022 Python Maint <python-maint@redhat.com> - 3.0.16-20
- Rebuilt for Python 3.11

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

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

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

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

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

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

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

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

* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 3.0.16-11
- Rebuilt for Python 3.8.0rc1 (#1748018)

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

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

* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.0.16-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Wed Oct 31 2018 Miro Hrončok <mhroncok@redhat.com> - 3.0.16-7
- Subpackage python2-klusta has been removed
  See https://fedoraproject.org/wiki/Changes/Mass_Python_2_Package_Removal

* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 3.0.16-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Fri Jun 29 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.0.16-5
- Fix build

* Tue Jun 19 2018 Miro Hrončok <mhroncok@redhat.com> - 3.0.16-4
- Rebuilt for Python 3.7

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 3.0.16-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Tue Jan 09 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.0.16-2
- Update based on review comments 1532082
- use py_dist macros

* Sun Jan 07 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.0.16-1
- Initial build

## END: Generated by rpmautospec