## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%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

# Sphinx-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# We can generate PDF documentation as a substitute.
%bcond doc_pdf 1

# Tests failing--Maybe related to new Zarr version
# https://github.com/SpikeInterface/probeinterface/issues/313
#
# Incompatible with Zarr 3
# https://bugzilla.redhat.com/show_bug.cgi?id=2338932
#
# Turn this off to disable Zarr tests if we still are not compatible when it’s
# time to ship Zarr 3.
%bcond zarr 1

Name:           python-probeinterface
Version:        0.2.25
Release:        %autorelease
Summary:        Handles probe layout, geometry, and wiring to device

# SPDX
License:        MIT
URL:            https://github.com/SpikeInterface/probeinterface
# The GitHub tarball has documentation, examples, and tests; the PyPI one does
# not.
Source0:        %{url}/archive/%{version}/probeinterface-%{version}.tar.gz
# Probe definitions are normally downloaded at runtime. We can get tests and
# examples that rely on probe definitions to work in an offline environment by
# pre-populating the local cache. See also
# https://github.com/SpikeInterface/probeinterface/issues/70.
#
# This URL comes from probeinterface/library.py, where it is called public_url.
%global probe_url https://raw.githubusercontent.com/SpikeInterface/probeinterface_library/main
Source1:        %{probe_url}/neuronexus/A1x32-Poly3-10mm-50-177/A1x32-Poly3-10mm-50-177.json
Source2:        %{probe_url}/cambridgeneurotech/ASSY-156-P-1/ASSY-156-P-1.json

BuildArch:      noarch

BuildRequires:  python3-devel
BuildRequires:  tomcli

%if %{with doc_pdf}
BuildRequires:  make
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
BuildRequires:  /usr/bin/xindy
BuildRequires:  tex-xetex-bin
%endif

%global common_description %{expand:
A Python package to handle the layout, geometry, and wiring of silicon probes
for extracellular electrophysiology experiments.

Goals

Make a lightweight package to handle:

  • probe contact geometry (both 2D and 3D layouts)
  • probe shape (contour of the probe, shape of channel contact, …)
  • probe wiring to device (the physical layout often doesn’t match the channel
    ordering)
  • combining several probes into a device with global geometry + global wiring
  • exporting probe geometry data into JSON files
  • loading existing probe geometry files (Neuronexus, imec, Cambridge
    Neurotech…) Started here

Bonus:

  • optional plotting (based on matplotlib)
  • load/save geometry using common formats (PRB, CSV, NWB, …)
  • handle SI length units correctly um/mm/…

Target users/project:

  • spikeinterface team: integrate this into spikeextractor for channel
    location
  • neo team: handle array_annotations for AnalogSignal
  • spikeforest team: use this package for plotting probe activity
  • phy team: integrate for probe display
  • spyking-circus team: handle probe with this package
  • kilosort team: handle probe with this package
  • tridesclous team: handle probe with this package
  • open ephys team: automatically generate channel map configuration files}

%description %{common_description}


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

%description -n python3-probeinterface %{common_description}


%package        doc
Summary:        Documentation for probeinterface

%description    doc %{common_description}


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

# Do not require an exact matplotlib version to build documentation:
sed -r -i 's/(matplotlib)==/\1>=/' pyproject.toml

# Drop coverage tools from test dependencies.
#
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
tomcli set pyproject.toml lists delitem --type regex \
    project.optional-dependencies.test 'pytest-cov\b.*'

%if %{without zarr}
tomcli set pyproject.toml lists delitem --type regex \
    project.optional-dependencies.test 'zarr\b.*'
%endif

# Pre-populate the probe definition cache
PROBE_CACHE="${HOME}/.config/probeinterface/library"
install -t "${PROBE_CACHE}/neuronexus" -p -m 0644 -D '%{SOURCE1}'
install -t "${PROBE_CACHE}/cambridgeneurotech" -p -m 0644 -D '%{SOURCE2}'

# Since pdflatex cannot handle Unicode inputs in general:
echo "latex_engine = 'xelatex'" >> doc/conf.py


%generate_buildrequires
%pyproject_buildrequires -x test%{?with_doc_pdf:,docs}


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files -l probeinterface

%if %{with doc_pdf}
# Building this in %%install instead of %%build is a hack, but it is the
# easiest workaround for the unusual fact that importing the package requires
# proper distribution metadata.
PYTHONPATH='%{buildroot}%{python3_sitelib}' %make_build -C doc latex \
    SPHINXOPTS='-j%{?_smp_build_ncpus}'
%make_build -C doc/_build/latex LATEXMKOPTS='-quiet'
%endif


%check
# The probeinterface.testing module loads probe.json.schema, which doesn’t ship
# with the wheel
# https://github.com/SpikeInterface/probeinterface/issues/321
#
# A proposed solution is:
#
# Move probeinterface.testing out of the API; fixes #321
# https://github.com/SpikeInterface/probeinterface/pull/322
#
# This is a temporary workaround:
ln -s "${PWD}/resources/" '%{buildroot}%{python3_sitelib}/../resources'
trap 'rm %{buildroot}%{python3_sitelib}/../resources' INT TERM EXIT

%pyproject_check_import

# Skip tests that unconditionally download probe interface definitions and
# bypass the cache.
# https://github.com/SpikeInterface/probeinterface/issues/70.
k="${k-}${k+ and }not test_download_probeinterface_file"
k="${k-}${k+ and }not test_get_from_cache"

%if %{without zarr}
k="${k-}${k+ and }not test_save_to_zarr"
%endif

%pytest -k "${k-}"


%files -n python3-probeinterface -f %{pyproject_files}
%doc README.md


%files doc
%license LICENSE
%doc examples/
%if %{with doc_pdf}
%doc doc/_build/latex/probeinterface.pdf
%endif


%changelog
## START: Generated by rpmautospec
* Fri Feb 07 2025 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.25-2
- Conditionalize Zarr BuildRequires and associated tests

* Fri Feb 07 2025 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.25-1
- Update to 0.2.25 (close RHBZ#2344205)

* Sat Jan 18 2025 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.24-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild

* Fri Sep 06 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.24-1
- Update to 0.2.24 (close RHBZ#2310398)

* Thu Jul 18 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.23-1
- Update to 0.2.23 (close RHBZ#2298480)

* Mon Jul 15 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.22-1
- Update to 0.2.22 (close RHBZ#2297975)

* Mon Jun 17 2024 Python Maint <python-maint@redhat.com> - 0.2.21-3
- Rebuilt for Python 3.13

* Mon Feb 05 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.21-1
- Update to 0.2.21 (close RHBZ#2262778)

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

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

* Mon Dec 18 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.20-2
- Assert that %%pyproject_files contains a license file

* Tue Dec 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.20-1
- Update to 0.2.20 (close RHBZ#2254044)

* Thu Nov 02 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.19-1
- Update to 0.2.19

* Tue Oct 31 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.18-1
- Update to 0.2.18 (close RHBZ#2247108)

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

* Wed Jul 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.17-3
- Use trailing slashes for directories in files lists

* Wed Jun 28 2023 Python Maint <python-maint@redhat.com> - 0.2.17-2
- Rebuilt for Python 3.12

* Tue Jun 27 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.17-1
- Update to 0.2.17 (close RHBZ#2217884)

* Mon Jun 19 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.16-3
- Use new (rpm 4.17.1+) bcond style

* Sat Mar 18 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.16-2
- Don’t assume %%_smp_mflags is -j%%_smp_build_ncpus

* Thu Feb 09 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.16-1
- Update to 0.2.16 (close RHBZ#2168525)

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

* Mon Dec 12 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.15-1
- Update to 0.2.15 (close RHBZ#2152539)

* Thu Oct 27 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.14-1
- Update to 0.2.14 (close RHBZ#2138117)

* Fri Oct 21 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.13-1
- Update to 0.2.13 (close RHBZ#2136599)

* Mon Oct 10 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.12-1
- Update to 0.2.12 (close RHBZ#2133405)

* Mon Oct 10 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.11-2
- Confirm License is SPDX MIT

* Wed Sep 14 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.11-1
- Update to 0.2.11 (close RHBZ#2126799)

* Thu Sep 01 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.10-1
- Update to 0.2.10 (close RHBZ#2123300)

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

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

* Fri Apr 15 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.9-1
- Update to 0.2.9 (close RHBZ#2075767)

* Wed Mar 23 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.8-1
- Update to 0.2.8 (close RHBZ#2067101)

* Tue Mar 01 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.7-1
- Update to 0.2.7 (close RHBZ#2059621)

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

* Tue Dec 28 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.2.6-1
- Initial package (close RHBZ#2012917)
## END: Generated by rpmautospec