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

# These are problematic, sometimes they randomly fail or hang
%bcond_with xvfb_tests

%global desc \
The fslpy project is a FSL programming library written in Python. It is used by \
FSLeyes.

%global forgeurl https://github.com/pauldmccarthy/fslpy

Name:           python-fslpy
Version:        3.18.2
Release:        %autorelease
Summary:        The FSL Python Library

%global tag %{version}

%forgemeta


License:        Apache-2.0
URL:            %forgeurl
Source0:        %forgesource

BuildArch:      noarch
# fsleyes dropped it already, so this is a leaf package
# F40+
ExcludeArch:    %{ix86}

BuildRequires:  python3-devel
BuildRequires:  help2man

BuildRequires:  dcm2niix
BuildRequires:  %{py3_dist pytest}
%if %{with xvfb_tests}
BuildRequires:  xorg-x11-server-Xvfb
%endif


%description
%{desc}

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

%description -n python3-fslpy
%{desc}

%pyproject_extras_subpkg -n python3-fslpy extra

%prep
%forgesetup

# Don't run coverage when calling `pytest`
sed -i 's/--cov=fsl //' pyproject.toml

# remove unneeded shebangs
find . -type f -name "*.py" -exec sed -i '/^#![  ]*\/usr\/bin\/env python$/ d' {} 2>/dev/null ';'
sed -i '/^#![  ]*\/usr\/bin\/env python3$/ d' fsl/wrappers/tbss.py
# some scripts have the shebang, so we correct these
find . -type f -name "*.py" -exec sed -i 's/#![  ]*\/usr\/bin\/env python$/#!\/usr\/bin\/python3/' {} 2>/dev/null ';'

%generate_buildrequires
%pyproject_buildrequires -x extra

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files -l fsl

# generate man pages
# imglob does not have a --help
for binary in "atlasq" "atlasquery" "fsl_apply_x5" "fsl_ents" "fsl_convert_x5" "imcp" "immv" "resample_image" "Text2Vest" "Vest2Text" "fsl_abspath" "imln" "imtest" "remove_ext"
do
    echo "Generating man page for ${binary// /-/}"
    PYTHONPATH="$PYTHONPATH:%{buildroot}/%{python3_sitelib}/" PATH="$PATH:%{buildroot}/%{_bindir}/" help2man --no-info --no-discard-stderr --name="${binary}" --version-string="${binary} %{version}" --output="${binary// /-}.1" "${binary}"
    cat "${binary// /-}.1"
    install -t '%{buildroot}%{_mandir}/man1' -p -m 0644 -D "${binary// /-}.1"
done

# do not have a --help
for binary in "imglob" "imrm"
do
    echo "Generating man page for ${binary// /-/}"
    PYTHONPATH="$PYTHONPATH:%{buildroot}/%{python3_sitelib}/" PATH="$PATH:%{buildroot}/%{_bindir}/" help2man --help-option=" " --no-info --no-discard-stderr --name="${binary}" --version-string="${binary} %{version}" --output="${binary// /-}.1" "${binary}"
    cat "${binary// /-}.1"
    install -t '%{buildroot}%{_mandir}/man1' -p -m 0644 -D "${binary// /-}.1"
done

%check
%if %{with xvfb_tests}
# From https://git.fmrib.ox.ac.uk/fsl/fslpy/blob/master/.ci/test_template.sh
xvfb-run pytest-3 tests/test_idle.py
sleep 10
# Sometimes fails, sometimes passes
xvfb-run pytest-3 tests/test_platform.py || exit 0
%endif

# Disable tests we cannot run using markers as per
# https://github.com/pauldmccarthy/fslpy/issues/17
m="${m-}${m+ and }not fsltest"
m="${m-}${m+ and }not dcm2niix"
m="${m-}${m+ and }not wxtest"
m="${m-}${m+ and }not noroottest"
# Exclude tests requiring network (URLError)
k="${k-}${k+ and }not test_installedVersion"
k="${k-}${k+ and }not test_enabled"
k="${k-}${k+ and }not test_scanDir"
k="${k-}${k+ and }not test_loadSeries"
# requires an FSL installation
k="${k-}${k+ and }not test_cluster"

# Ignore tests we've already run
# Set import-mode according to upstream's `pyproject.toml`
%{pytest} ${k+-k }"${k-}" ${m+-m }"${m-}" \
  --ignore=fsl/tests/test_idle.py \
  --ignore=fsl/tests/test_platform.py

# Remove test packages that are installed in site packages
# We do that here, since above tests require the installed tests and data
rm -rvf %{buildroot}%{python3_sitelib}/fsl/tests
sed -r -i '/\bfsl\/tests\b/d' %{pyproject_files}


%files -n python3-fslpy -f %{pyproject_files}
%doc README.rst
%{_bindir}/atlasq
%{_bindir}/atlasquery
%{_bindir}/fsl_apply_x5
%{_bindir}/fsl_ents
%{_bindir}/fsl_convert_x5
%{_bindir}/imcp
%{_bindir}/imglob
%{_bindir}/immv
%{_bindir}/resample_image
%{_bindir}/Text2Vest
%{_bindir}/Vest2Text
%{_bindir}/fsl_abspath
%{_bindir}/imln
%{_bindir}/imrm
%{_bindir}/imtest
%{_bindir}/remove_ext
%{_mandir}/man1/*.*

%changelog
## START: Generated by rpmautospec
* Wed Apr 03 2024 Packit <hello@packit.dev> - 3.18.2-1
- Update to 3.18.2 upstream release
- Resolves: rhbz#2272993

* Tue Mar 05 2024 Packit <hello@packit.dev> - 3.18.1-1
- [packit] 3.18.1 upstream release
- Resolves rhbz#2267966

* Thu Feb 22 2024 Packit <hello@packit.dev> - 3.18.0-1
- [packit] 3.18.0 upstream release
- Resolves rhbz#2265551

* Mon Feb 12 2024 Sandro <devel@penguinpee.nl> - 3.17.0-4
- Assert existence of license file

* Mon Feb 12 2024 Sandro <devel@penguinpee.nl> - 3.17.0-3
- Fix remaining tests and the way we run them
- Drop `-x tests` from %%pyproject_buidrequires. It is not needed since we
  had `pytest` as an explicit BR already.
- Keep `addopts` in `pytest.ini_options` table. It's actually useful for
  running the tests as upstream intended.
- Simplify %%pytest no we have a usable `addopts`.
- Enable some more tests that work using `--import-mode=importlib`.
- Remove `tests` from installation after testing (e.g. in %%check instead
  of %%install). This is a bug in upstreams `pyproject.toml`. Due to the
  flat layout the `exclude` statement becomes meaningless (conflicts the
  `include` statement, which prevails). I'll report that upstream.

* Sun Feb 11 2024 Sandro <devel@penguinpee.nl> - 3.17.0-2
- Re-assert disabled tests

* Fri Feb 09 2024 Packit <hello@packit.dev> - 3.17.0-1
- [packit] 3.17.0 upstream release
- Resolves rhbz#2263539

* Tue Feb 06 2024 František Zatloukal <fzatlouk@redhat.com> - 3.16.1-4
- Rebuilt for turbojpeg 3.0.2

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

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

* Thu Jan 18 2024 Packit <hello@packit.dev> - 3.16.1-1
- [packit] 3.16.1 upstream release
- Resolves rhbz#2258961

* Thu Dec 21 2023 Packit <hello@packit.dev> - 3.16.0-1
- [packit] 3.16.0 upstream release
- Resolves rhbz#2250059

* Wed Oct 25 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.15.2-2
- fix: drop i686, add extras package, remove test files (fixes rh#2236184)

* Wed Oct 25 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.15.2-1
- feat: update to 3.15.2 (fixes rh#2236184)

* Wed Oct 25 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.13.3-2
- chore: add packit

* Sat Jul 22 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.13.3-1
- feat: update to 3.13.3 (fixes rhbz#2220243, rhbz#2214516)

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

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

* Mon Jun 12 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.12.1-1
- feat: update to 3.12.1
- use spdx licence
- generate man pages for scripts

* Mon Feb 27 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.11.1-1
- feat: update to 3.11.1 (fixes rhbz#2172011)

* Tue Feb 07 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.10.0-3
- fix: backport fixes for nibabel 5x and numpy 1.23+ (fixes rhbz#2167346)

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

* Sun Oct 16 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.10.0-1
- feat: update to 3.10.0 (fixes rhbz#2086116)

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

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

* Fri May 06 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.9.0-1
- feat: update to 3.9.0 (fixes rhbz#2074516)

* Sat Feb 19 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.8.2-1
- feat: update to 3.8.2 (fixes rhbz#2054629)

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

* Sat Aug 07 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.6.4-1
- Update to 3.6.4

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

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

* Sun Mar 28 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.5.3-1
- Update to latest release

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

* Sat Nov 28 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.4.0-1
- Update to 3.4.0

* Sun Oct 18 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.3.3-1
- Update to latest patch release

* Thu Oct 01 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.3.0-2
- Disable tests to make it build on F32 ppc

* Thu Oct 01 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.3.0-1
- Update to latest release

* Mon Sep 07 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.2-3
- Use quotes

* Mon Sep 07 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.2-2
- Add workaround to fix tests

* Fri Sep 04 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.2-1
- Update to new release

* Mon Jul 06 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.0-4
- Include patch to dump data

* Fri Jul 03 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.0-3
- Remove dataclasses that is part of Python 3.7+
- rhbz#1851358

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

* Sun Jun 21 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.0-1
- Update to 3.2.0

* Fri May 01 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.0.1-1
- Update to 3.0.1

* Fri Feb 21 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.8.1-1
- Update to 2.8.1

* Thu Jan 30 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.8.0-2
- Temporarily patch requirements to work around dep-generator-bug
- https://bugzilla.redhat.com/show_bug.cgi?id=1758141

* Thu Jan 30 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.8.0-1
- Update to 2.8.0
- drops rtree=0.8.3 requirement (#1794617)
- enable fixed tests

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

* Thu Nov 14 2019 Aniket Pradhan <major AT fedoraproject DOT org> - 2.7.0-1
- Update to 2.7.0

* Mon Oct 28 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.6.2-1
- Update to 2.6.2

* Mon Sep 23 2019 Aniket Pradhan <major AT fedoraproject DOT org> - 2.6.1-1
- Update to 2.6.1

* Sat Aug 31 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.5.0-2
- Disable failing test on f32

* Sat Aug 31 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.5.0-1
- Update to 2.5.0
- Disable failing tests

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

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

* Fri Jul 5 2019 Luis M. Segundo <blackfile@fedoraproject.org> - 2.3.1-1
- Update to 2.3.1

* Mon May 27 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.2.0-2
- Disable failing test for F29
- https://github.com/pauldmccarthy/fslpy/issues/4
- Update all branches to ensure update path is correct

* Mon May 27 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.2.0-1
- Update to 2.2.0
- Use dep generator
- Update ignored test locations

* Sun Apr 14 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.1.0-1
- Update to 2.1.0

* Sun Apr 14 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.0.1-2
- Add BR to build docs correctly

* Wed Apr 10 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 2.0.1-1
- Update to 2.0.1

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

* Thu Nov 08 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 1.12.0-3
- Fix doc build on < F30
- Fix test by requiring higher nibabel

* Thu Nov 08 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 1.12.0-2
- Correct shebangs
- Move Requires to the sub package

* Thu Nov 01 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 1.12.0-1
- Initial build


## END: Generated by rpmautospec