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

%bcond tests 1

%global commit e5e063b09d094ff79d2089261828fd2b2c843ab6
%global snapdate 20231006

Name:           python-nipy
Version:        0.5.0^%{snapdate}git%(c='%{commit}'; echo "${c:0:7}")
Release:        %autorelease
Epoch:          1
Summary:        Neuroimaging in Python FMRI analysis package

License:        BSD-3-Clause
URL:            https://nipy.org/nipy
Source0:        https://github.com/nipy/nipy/archive/%{commit}/nipy-%{commit}.tar.gz

# Man pages hand-written for Fedora in groff_man(7) format based on --help
Source10:       nipy_3dto4d.1
Source11:       nipy_4d_realign.1
Source12:       nipy_4dto3d.1
Source13:       nipy_diagnose.1
Source14:       nipy_tsdiffana.1

# Do not compare strings by identity (address)
# https://github.com/nipy/nipy/pull/540
Patch:          https://github.com/nipy/nipy/pull/540.patch
# Remove executable filesystem permissions from files that don’t need it
# https://github.com/nipy/nipy/pull/541
Patch:          https://github.com/nipy/nipy/pull/541.patch
# Fix backslash escaping issues in docstrings
# https://github.com/nipy/nipy/pull/543
Patch:          https://github.com/nipy/nipy/pull/543.patch
# Cython: declare pointers one per line
# https://github.com/nipy/nipy/pull/544
Patch:          https://github.com/nipy/nipy/pull/544.patch
# Improve const-correctness in C code
# https://github.com/nipy/nipy/pull/545
Patch:          https://github.com/nipy/nipy/pull/545.patch

BuildRequires:  python3-devel
BuildRequires:  gcc
BuildRequires:  pkgconfig(flexiblas)

# A weak dependency; may enable more tests
BuildRequires:  python3dist(matplotlib)

%if %{with tests}
BuildRequires:  nipy-data
%endif

%global _docdir_fmt %{name}

%global common_description %{expand:
Neuroimaging tools for Python.

The aim of NIPY is to produce a platform-independent Python environment for the
analysis of functional brain imaging data using an open development model.

In NIPY we aim to:

• Provide an open source, mixed language scientific programming environment
  suitable for rapid development.
• Create software components in this environment to make it easy to develop
  tools for MRI, EEG, PET and other modalities.
• Create and maintain a wide base of developers to contribute to this platform.
• Maintain and develop this framework as a single, easily installable bundle.}

%description %{common_description}


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

# Adds various plotting functionality, but not an “official” dependency
Recommends:     python3dist(matplotlib)

Suggests:       nipy-data

# The nipy.algorithms.statistics.models subpackage was forked from an
# undetermined version of scipy.stats.models in commit 55a9162 on 2011-09-13;
# before this, the upstream version was monkey-patched via
# nipy.fixes.scipy.stats.models.
Provides:       bundled(python3dist(scipy))

%description -n python3-nipy %{common_description}


%package doc
Summary:        Documentation and examples for python-nipy

BuildArch:      noarch

Requires:       nipy-data

%description doc
%{summary}.


%prep
%autosetup -n nipy-%{commit} -p1

# Remove bundled lapack_lite:
rm -rvf lib/lapack_lite/
sed -r -i 's/^.*lapack_lite/# &/' lib/meson.build
sed -r -i 's/^#(external *= *)(False|0)/\1True/' setup.cfg

# It looks like fff/fff_python_wrapper is a part of nipy rather than a bundled
# exgternal library.

# https://docs.fedoraproject.org/en-US/packaging-guidelines/BLAS_LAPACK/
sed -r -i 's/openblas/flexiblas/' nipy/labs/meson.build

# Remove pre-generated Cython C sources (there should not be any):
grep -FrlI 'Generated by Cython' . | xargs -r rm -vf

%py3_shebang_fix nipy examples

cp -p nipy/algorithms/statistics/models/LICENSE.txt scipy-LICENSE.txt

# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
sed -r -e 's/^(pytest-cov|coverage|pre-commit)/# &/' dev-requirements.txt |
  tee dev-requirements-filtered.txt


%generate_buildrequires
%pyproject_buildrequires -w %{?with_tests:dev-requirements-filtered.txt}


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files nipy

install -t '%{buildroot}%{_mandir}/man1' -m 0644 -p -D \
    '%{SOURCE10}' '%{SOURCE11}' '%{SOURCE12}' '%{SOURCE13}' '%{SOURCE14}'


%check
%pyproject_check_import -e '*.test*'
%if %{with tests}
# The docstring says: “fixme : this one often fails. I don't really see why”
k="${k-}${k+ and }not test_gmm_bf"

# See: .github/workflows/test.yml
mkdir -p for_testing
cd for_testing
%pytest -v --doctest-plus --ignore-glob='__config__.py' -k "${k-}" --pyargs nipy
%endif


%files -n python3-nipy -f %{pyproject_files}
%license LICENSE
%license scipy-LICENSE.txt

%{_bindir}/nipy_3dto4d
%{_bindir}/nipy_4d_realign
%{_bindir}/nipy_4dto3d
%{_bindir}/nipy_diagnose
%{_bindir}/nipy_tsdiffana

%{_mandir}/man1/nipy_3dto4d.1*
%{_mandir}/man1/nipy_4d_realign.1*
%{_mandir}/man1/nipy_4dto3d.1*
%{_mandir}/man1/nipy_diagnose.1*
%{_mandir}/man1/nipy_tsdiffana.1*


%files doc
%license LICENSE
%license scipy-LICENSE.txt

%doc AUTHOR
%doc Changelog
%doc README.rst
%doc THANKS

%doc examples/


%changelog
* Thu Nov 09 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20231006gite5e063b-5
- Updated patch for upstream PR#543

* Mon Oct 16 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20231006gite5e063b-4
- Simplify smoke-test excludes

* Mon Oct 16 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20231006gite5e063b-3
- Skip a known-to-upstream flaky test

* Mon Oct 16 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20231006gite5e063b-2
- Patch several minor issues (sending PR’s upstream)

* Mon Oct 16 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20231006gite5e063b-1
- Update to a current snapshot
- Upstream has ported to a meson build system
- Drop all the unused boilerplate for Sphinx-generated PDF docs
- Don’t patch for numpy 1.24 compatibility

* Thu Oct 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230923git961fa38-2
- Replace deprecated %%{pyproject_build_lib} macro

* Mon Sep 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230923git961fa38-1
- Update to a current snapshot (961fa38)

* Mon Sep 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230922gita2e068b-4
- Revert "Call nipnost (nosetests) with --traverse-namespace"

* Sun Sep 24 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230922gita2e068b-3
- Temporarily ignore test failures
- Fix RHBZ#2226258, fix RHBZ#2220359

* Fri Sep 22 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230922gita2e068b-2
- Call nipnost (nosetests) with --traverse-namespace
- This imitates upstream’s GitHub workflow, but we don’t see any effect

* Fri Sep 22 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230922gita2e068b-1
- Update to a current snapshot (ad68834)

* Fri Sep 22 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921gite754499-2
- Remove the PyPI mock dependency upstream

* Fri Sep 22 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921gite754499-1
- Update to a current snapshot (e754499)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921gitad68834-1
- Update to a current snapshot (ad68834)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git47a22d0-3
- Use new (rpm 4.17.1+) bcond style

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git47a22d0-2
- Updated py3k shim package again

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git47a22d0-1
- Update to a current snapshot (47a22d0)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git6823b5a-1
- Update to a current snapshot (6823b5a)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git46eff4c-4
- Improved GIFTI patch

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git46eff4c-3
- Replace deprecated/removed matplotlib.cm.LUTSIZE

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git46eff4c-2
- Update py3k shim patch

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git46eff4c-1
- Update to a current snapshot (46eff4c)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git5694194-2
- Fix test creating unsupported double-precision GiftiDataArray

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git5694194-1
- Update to a current snapshot (5694194)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git27da590-2
- Offer a PR for our version of the py3k shim patch

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git27da590-1
- Update to a current snapshot (27da590)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git5d53932-2
- Don’t use nose.tools.assert_equals

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230921git5d53932-1
- Update to a current snapshot (5d53932)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230405git7eede02-3
- Stop using deprecated unittest.TestCase.assert_() alias

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230405git7eede02-2
- Use the Cython<3 compat package

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230405git7eede02-1
- Update to a current snapshot (7eede02)

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230206git9512cd9-2
- Backport upstream PR#507: rename setattr_on_read to auto_attr

* Thu Sep 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1:0.5.0^20230206git9512cd9-1
- Fix incorrect snapshot info field in Version
- Preserving correct ordering requires introducing an Epoch

* Sun Jul 23 2023 Python Maint <python-maint@redhat.com> - 0.5.0^9512cd9git20230206-10
- Rebuilt for Python 3.12

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.5.0^9512cd9git20230206-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Tue Jul 18 2023 Python Maint <python-maint@redhat.com> - 0.5.0^9512cd9git20230206-8
- Rebuilt for Python 3.12

* Wed Feb 08 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.5.0^19971cdgit20230102-1
- Update to a current snapshot (9512cd9)
- Drop conditionals for EOL Fedoras and for EPEL8 and older
- Remove spurious BuildRequires on git-core
- Update URL to HTTPS
- Update description from upstream
- Handle dependencies more methodically
- Allow the examples to retain shebangs (but do fix them)
- Split docs/examples into a -doc subpackage and depend on nipy-data
- Add Changelog to the documentation
- Simplify the tests to match .travis.yml
- Remove generated Cython files in prep to prove they are re-generated
- Downgrade matplotlib to a weak dep. and add it as a BR
- Properly indicate partial scipy bundling
- Update License to SPDX
- Port to pyproject-rpm-macros
- Add man pages for the command-line tools
- Add some support for PDF documentation, but do not enable it yet
- Fix compatibility with nibabel 5.0.0
- Unbundle six via a PR/patch to upstream rather than downstream-only

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

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

* Wed Jun 22 2022 Charalampos Stratakis <cstratak@redhat.com> - 0.5.0-5
- Fix FTBFS with Python 3.11 and setuptools >= 62.1.0
Resolves: rhbz#2099030, rhbz#2097101

* Fri Jun 17 2022 Python Maint <python-maint@redhat.com> - 0.5.0-4
- Rebuilt for Python 3.11

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

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

* Sun Jul 04 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.5.0-1
- Update to latest release
- remove unneeded explicity provides
- remove s390x test exlusions
- Enable all tests

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

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

* Sun Aug 16 2020 Iñaki Úcar <iucar@fedoraproject.org> - 0.4.2-11
- https://fedoraproject.org/wiki/Changes/FlexiBLAS_as_BLAS/LAPACK_manager

* Thu Aug 13 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.4.2-10
- Temporarily disable tests
- #1800845

* Sat Aug 01 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-9
- Second attempt - Rebuilt for
  https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

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

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

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

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

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

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

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

* Tue Aug 14 2018 Miro Hrončok <mhroncok@redhat.com> - 0.4.2-1
- Update to 0.4.2
- Remove python2 subpackage

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

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

* Mon Mar 26 2018 Iryna Shcherbina <ishcherb@redhat.com> - 0.4.1-5
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)

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

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sun Feb 12 2017 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4.1-1
- Update to latest version

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Mon Dec 19 2016 Miro Hrončok <mhroncok@redhat.com> - 0.4.0-7
- Rebuild for Python 3.6

* Sat Oct 15 2016 Peter Robinson <pbrobinson@fedoraproject.org> - 0.4.0-6
- rebuilt for matplotlib-2.0.0

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.4.0-5
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Sun Nov 29 2015 Igor Gnatenko <i.gnatenko.brain@gmail.com> - 0.4.0-3
- Use one directory for building

* Sat Nov 28 2015 Igor Gnatenko <i.gnatenko.brain@gmail.com> - 0.4.0-2
- Do not use obsolete py3dir
- Have only one binary

* Sun Nov 01 2015 Igor Gnatenko <i.gnatenko.brain@gmail.com> - 0.4.0-1
- Initial package