## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## 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

%global desc %{expand: \
DIPY is a python library for the analysis of MR diffusion imaging.

DIPY is for research only; please contact admins@dipy.org if you plan
to deploy in clinical settings.

Current information can always be found on the DIPY website:
https://dipy.org/}

# Full documentation downloads 100+MB of data, so we'd rather users look at the
# upstream documentation
%bcond docs 0

# There are a lot of tests and they take a while to complete.
%bcond tests 1

Name:           python-dipy
Version:        1.10.0
Release:        %autorelease
Summary:        Diffusion MRI Imaging in Python

%global forgeurl https://github.com/nipy/dipy/
%global tag %{version}
%forgemeta

# SPDX
License:        BSD-3-Clause
URL:            https://dipy.org/
Source:         %forgesource

BuildRequires:      python3-devel
BuildRequires:      gcc-c++
%if %{with tests}
BuildRequires:      %{py3_dist pytest}
%endif
# Required for some modules but not in Fedora yet
# BuildRequires:      %%{py3_dist cvxpy}

# Drop i686
# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
ExcludeArch:        %{ix86}

%description
%{desc}

%package -n python3-dipy
Summary:            %{summary}
Suggests:           %{py3_dist ipython}

%description -n python3-dipy
%{desc}

%package doc
BuildArch:      noarch
Summary:        %{summary}

%description doc
Documentation for %{name}.


%prep
%forgeautosetup -p1

# Correct interpreter for these---used in building docs and so on
sed -i 's/#!\/usr\/bin\/env python[0-9]?/#!\/usr\/bin\/python3/' doc/tools/docgen_cmd.py
sed -i 's/#!\/usr\/bin\/env python[0-9]?/#!\/usr\/bin\/python3/' doc/tools/build_modref_templates.py
find tools/ -name "*.py" -exec sed -i 's/#!\/usr\/bin\/env python[0-9]?/#!\/usr\/bin\/python3/' '{}' \;

# Other shebangs and permission fixes
for f in "dipy/stats/resampling.py" "dipy/reconst/dki.py" "dipy/reconst/dti.py"  "dipy/workflows/mask.py" "dipy/workflows/tracking.py" "dipy/reconst/dki_micro.py" "dipy/reconst/msdki.py" "dipy/workflows/tests/test_stats.py"
do
    chmod -x "$f"
    sed -i '/^#!\/usr\/bin\/env python/ d' "$f"
    sed -i '/^#!\/usr\/bin\/python/ d' "$f"
done

# Remove executable bit from examples
chmod a-x doc/examples/*.py

%generate_buildrequires
%pyproject_buildrequires -p

%build
%pyproject_wheel

%if %{with docs}
pushd doc
    export PYTHONPATH=../build/
    make SPHINXBUILD=sphinx-build-3 PYTHON=%{__python3} html
    rm -rf _build/html/.doctrees
    rm -rf _build/html/.buildinfo
popd
%endif

%install
%pyproject_install
%pyproject_save_files dipy

# Examples are installed in /usr/doc by the build backend. Let's fix that!
mkdir -p %{buildroot}%{_docdir}/%{name}-doc
mv %{buildroot}/usr/doc/dipy/examples %{buildroot}%{_docdir}/%{name}-doc/

%check
%if %{with tests}
# These tests appear to hang or are very slow
k="${k-}${k+ and }not test_peaksFromModelParallel"
k="${k-}${k+ and }not test_reconst_csa"
k="${k-}${k+ and }not test_reconst_rumba"
# Individual tests requiring network
k="${k-}${k+ and }not test_syn_registration"
k="${k-}${k+ and }not test_register_dwi_to_template"
k="${k-}${k+ and }not test_affine_registration"
k="${k-}${k+ and }not test_single_transforms"
k="${k-}${k+ and }not test_register_series"
k="${k-}${k+ and }not test_register_dwi_series_and_motion_correction"
k="${k-}${k+ and }not test_streamline_registration"
k="${k-}${k+ and }not test_register_dwi_series_multi_b0"
k="${k-}${k+ and }not test_ptt_tracking"
k="${k-}${k+ and }not test_io_fetch"
k="${k-}${k+ and }not test_concatenate"
k="${k-}${k+ and }not test_io_info"
k="${k-}${k+ and }not test_concatenate_flow"
k="${k-}${k+ and }not test_convert_tractogram_flow"
# Test fails with pytest >= 8
k="${k-}${k+ and }not test_shore_fitting_no_constrain_e0"
%ifarch s390x
# https://github.com/dipy/dipy/issues/2886#issuecomment-2003567594
k="${k-}${k+ and }not test_bundlewarp"
k="${k-}${k+ and }not test_bundlewarp_vector_filed"
k="${k-}${k+ and }not test_bundle_shape_profile"
%endif
# Mimic what upstream does for testing
mkdir test && pushd test
ln -s ../pyproject.toml .
# Ignore test scripts requiring network (for downloading test data)
%pytest -c pyproject.toml -v --pyargs dipy \
  --ignore=dipy/io/tests/test_stateful_tractogram.py \
  --ignore=dipy/io/tests/test_streamline.py \
  --ignore=dipy/io/tests/test_utils.py \
  "${k:+-k $k}"
%endif

%files -n python3-dipy -f %{pyproject_files}
%doc README.rst Changelog AUTHOR
%license LICENSE
%{_bindir}/dipy_align_affine
%{_bindir}/dipy_align_syn
%{_bindir}/dipy_apply_transform
%{_bindir}/dipy_buan_lmm
%{_bindir}/dipy_buan_profiles
%{_bindir}/dipy_buan_shapes
%{_bindir}/dipy_bundlewarp
%{_bindir}/dipy_concatenate_tractograms
%{_bindir}/dipy_convert_tensors
%{_bindir}/dipy_convert_tractogram
%{_bindir}/dipy_correct_motion
%{_bindir}/dipy_denoise_lpca
%{_bindir}/dipy_denoise_mppca
%{_bindir}/dipy_denoise_nlmeans
%{_bindir}/dipy_denoise_patch2self
%{_bindir}/dipy_evac_plus
%{_bindir}/dipy_fetch
%{_bindir}/dipy_fit_csa
%{_bindir}/dipy_fit_csd
%{_bindir}/dipy_fit_dki
%{_bindir}/dipy_fit_dsi
%{_bindir}/dipy_fit_dti
%{_bindir}/dipy_fit_ivim
%{_bindir}/dipy_fit_mapmri
%{_bindir}/dipy_gibbs_ringing
%{_bindir}/dipy_horizon
%{_bindir}/dipy_info
%{_bindir}/dipy_labelsbundles
%{_bindir}/dipy_mask
%{_bindir}/dipy_median_otsu
%{_bindir}/dipy_nifti2pam
%{_bindir}/dipy_pam2nifti
%{_bindir}/dipy_recobundles
%{_bindir}/dipy_reslice
%{_bindir}/dipy_sh_convert_mrtrix
%{_bindir}/dipy_slr
%{_bindir}/dipy_snr_in_cc
%{_bindir}/dipy_split
%{_bindir}/dipy_tensor2pam
%{_bindir}/dipy_track
%{_bindir}/dipy_track_pft

%files doc
%license LICENSE
# Installed by package
%{_docdir}/%{name}-doc
%if %{with docs}
%doc doc/_build/html
%endif

%changelog
## START: Generated by rpmautospec
* Thu Dec 12 2024 Packit <hello@packit.dev> - 1.10.0-1
- Update to 1.10.0 upstream release
- Resolves: rhbz#2332183

* Wed Oct 02 2024 Karolina Surma <ksurma@redhat.com> - 1.9.0-11
- Read the runtime depedencies from pyproject.toml

* Wed Sep 04 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.9.0-10
- Skip failing tests on s390x rather than excluding the architecture

* Wed Sep 04 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.9.0-9
- Backport a proposed Python 3.13 fix (close RHBZ#2280596)

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

* Sun Jun 09 2024 Python Maint <python-maint@redhat.com> - 1.9.0-7
- Rebuilt for Python 3.13

* Fri May 03 2024 Sandro <devel@penguinpee.nl> - 1.9.0-6
- Change the way tests are run
- Make tests work with pytest >= 8 (RHBZ#2278865)

* Thu May 02 2024 Sandro <devel@penguinpee.nl> - 1.9.0-5
- Fix compatability with Python 3.13
- Replace alias `warn` from logging (RHBZ#2278637)
- Account for dedented docstrings

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 1.9.0-4
- Amend files section

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 1.9.0-3
- Amend list of tests requiring network

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 1.9.0-2
- Fix path

* Mon Mar 18 2024 Packit <hello@packit.dev> - 1.9.0-1
- [packit] 1.9.0 upstream release
- Resolves rhbz#2254667

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 1.8.0-7
- Exclude s390x due to failing tests

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 1.8.0-6
- Fix Packit config

* Sun Feb 25 2024 Sandro <devel@penguinpee.nl> - 1.8.0-5
- Drop i686
- Move BRs to main package
- Only `python-mne` depends on it. That's already excluding i686.

* Sun Feb 25 2024 Sandro <devel@penguinpee.nl> - 1.8.0-4
- Add packit config

* Sun Feb 25 2024 Sandro <devel@penguinpee.nl> - 1.8.0-3
- Migrate to SPDX license

* Sun Feb 25 2024 Sandro <devel@penguinpee.nl> - 1.8.0-2
- Use human friendly bcond

* Sun Feb 25 2024 Sandro <devel@penguinpee.nl> - 1.8.0-1
- Update to 1.8.0 (RHBZ#2254667)

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

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

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

* Tue Jul 18 2023 Sandro <devel@penguinpee.nl> - 1.7.0-1
- Update to 1.7.0 (RHBZ#2161463)
- Rebuild for Python3.12 (RHBZ#2220191)

* Tue Jul 18 2023 Python Maint <python-maint@redhat.com> - 1.5.0-5
- Rebuilt for Python 3.12

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

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

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

* Wed May 11 2022 iztokf <iztok@iztok-jr-fister.eu> 1.5.0-1
- Update to the latest release

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

* Sat Oct 02 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.4.1-1
- feat: update to 1.4.1

* Tue Jul 27 2021 Fedora Release Engineering <releng@fedoraproject.org> 1.4.0-3
- Second attempt - Rebuilt for
  https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

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

* Sun Mar 28 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.4.0-1
- enh: update to 1.4.0

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

* Sat Nov 28 2020 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.3.0-1
- Update to 1.3.0

* Tue Oct 27 2020 Tomas Hrnciar <thrnciar@redhat.com> 1.2.0-2
- Replace Python version glob with macro (needed for Python 3.10+)

* Sun Sep 13 2020 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.2.0-1
- Update to 1.2.0

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

* Tue May 26 2020 Miro Hrončok <miro@hroncok.cz> 1.1.1-2
- Rebuilt for Python 3.9

* Sat Feb 01 2020 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.1.1-1
- Update to 1.1.1

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

* Thu Oct 03 2019 Miro Hrončok <miro@hroncok.cz> 1.0.0-2
- Rebuilt for Python 3.8.0rc1 (#1748018)

* Sat Aug 31 2019 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 1.0.0-1
- Update to 1.0.0

* Mon Aug 19 2019 Miro Hrončok <miro@hroncok.cz> 0.16.0-4
- Rebuilt for Python 3.8

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

* Thu Jul 04 2019 Miro Hrončok <miro@hroncok.cz> 0.16.0-2
- Remove .0 from (Build)Requires

* Mon Apr 08 2019 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.16.0-1
- Update to latest new release

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

* Tue Nov 27 2018 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.15.0-4
- Mention requires explicitly

* Mon Nov 19 2018 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.15.0-3
- Disable absent python3-vtk dep

* Mon Nov 19 2018 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.15.0-2
- Disable mistakenly enabled docs generation

* Mon Nov 19 2018 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 0.15.0-1
- Initial import

## END: Generated by rpmautospec