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

%global _description %{expand:
NeuroM is a Python-based toolkit for the analysis and processing of neuron
morphologies.

Documentation is available at https://neurom.readthedocs.io/
}
%global forgeurl    https://github.com/BlueBrain/NeuroM

Name:           python-neurom
Version:        3.2.2
Release:        %autorelease
Summary:        Neuronal Morphology Analysis Tool

%global tag  v%{version}
%forgemeta

License:        BSD-3-Clause
URL:            %forgeurl
Source:         %forgesource

# Broken call to Rectangle constructor
# https://github.com/BlueBrain/NeuroM/issues/1079
#
# Fixed by:
#
# Remove py37, add py311, and fix Rectangle kwarg error
# https://github.com/BlueBrain/NeuroM/pull/1082
#
# We patch in only the actual fix:
#
# Fix Rectangle kwarg
# https://github.com/BlueBrain/NeuroM/pull/1082/commits/1655ab3b1c5f66db3a06431c48f44a8dc61164d8
Patch:          %{url}/pull/1082/commits/1655ab3b1c5f66db3a06431c48f44a8dc61164d8.patch

# Remove a few useless shebang lines
# https://github.com/BlueBrain/NeuroM/pull/1083
Patch:          %{url}/pull/1083.patch

# Replace PyPI mock test dependency with unittest.mock
# https://github.com/BlueBrain/NeuroM/pull/1084
Patch:          %{url}/pull/1084.patch

BuildArch:      noarch

%description %_description

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

BuildRequires:  python3-devel

%description -n python3-neurom %_description

%pyproject_extras_subpkg -n python3-neurom plotly

%package doc
Summary:        Documentation for %{name}

%description doc %_description

%prep
%forgeautosetup -p1

%py3_shebang_fix examples/

# correct config files path
# not sure why this was changed: https://github.com/BlueBrain/NeuroM/commit/dbc3bd069a6fbded6c4a64cc038adb37c0b06932
sed -i 's|graft neurom/config|graft neurom/apps/config|' MANIFEST.in

%generate_buildrequires
export SETUPTOOLS_SCM_PRETEND_VERSION=%{version}
%pyproject_buildrequires -t -x plotly

%build
export SETUPTOOLS_SCM_PRETEND_VERSION=%{version}
%pyproject_wheel

%install
export SETUPTOOLS_SCM_PRETEND_VERSION=%{version}
%pyproject_install
%pyproject_save_files neurom

# Remove spurious installed files
rm -rf $RPM_BUILD_ROOT/%{python3_sitelib}/tests/

%check
export SETUPTOOLS_SCM_PRETEND_VERSION=%{version}
# tests failing
# reported upstream: https://github.com/BlueBrain/NeuroM/issues/983
k="${k-}${k+ and }not test_extract_dataframe_multiproc"
k="${k-}${k+ and }not test_extract_stats_scalar_feature"
k="${k-}${k+ and }not test_markers"
k="${k-}${k+ and }not test_single_neurite_no_soma"
k="${k-}${k+ and }not test_skip_header"
%tox -- -- -k "${k-}"

%files -n python3-neurom -f %{pyproject_files}
%doc AUTHORS.md
%doc CHANGELOG.rst
%doc README.md
%{_bindir}/neurom

%files doc
%license LICENSE.txt
%doc examples/
%doc tutorial/

%changelog
* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-16
- Update the list of test skips

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-14
- Package the changelog as documentation

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-12
- Replace python-mock test dependency with unittest.mock

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-11
- Add a metapackage for the “plotly” extra

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-10
- Better shebang line fixing
- Send a PR upstream to remove useless shebangs; apply it as a patch
- Use the py3_shebang_fix macro instead of sed to fix shebangs in examples

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-9
- Patch matplotlib 3.8 incompatibility

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-6
- Drop bogus BuildRequires on python3-toml

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-5
- Update License to SPDX

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

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

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

* Sun Oct 09 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.2.2-1
- feat: update to 3.2.2 (fixes rh#2082562)

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

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

* Thu Mar 03 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.1.0-3
- fix: patch manifest to include default config file

* Thu Mar 03 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.1.0-2
- fix: install config files dir

* Sun Feb 20 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.1.0-1
- feat: update to 3.1.0 (fixes rhbz#1952492)

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

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

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

* Wed Apr 14 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 1.8.0-1
- Initial build