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

# build order for fsleyes packages:
# 1. fsleyes-widgets
# 2. fslpy
# 3. fsleyes-props
# 4. fsleyes

%global desc \
FSLeyes, the FSL image viewer

# PyPi tar does not include tests
# Upstream says the tests, since they use xvfb etc., may not always pass on all
# platforms.
%bcond_with xvfb_tests

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

Name:           python-fsleyes
Version:        1.7.0
Release:        %autorelease
Summary:        FSLeyes, the FSL image viewer

%global tag %{version}
%forgemeta

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

BuildArch:      noarch

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

%description
%{desc}

%package -n python3-fsleyes
Summary:        %{summary}
BuildRequires:  python3-devel
BuildRequires:  /usr/bin/desktop-file-install
BuildRequires:  /usr/bin/appstream-util
Requires:       hicolor-icon-theme
# from requirements-dev.txt

%if %{with xvfb_tests}
BuildRequires:  graphviz
BuildRequires:  %{py3_dist mock}
BuildRequires:  %{py3_dist pytest}
BuildRequires:  %{py3_dist pytest-cov}
BuildRequires:  %{py3_dist wxpython}
BuildRequires:  freeglut-devel
BuildRequires:  xorg-x11-server-Xvfb
BuildRequires:  python3-matplotlib-wx
%endif

Requires:       dcm2niix
Requires:       python3-matplotlib-wx

Provides:       fsleyes = %{version}-%{release}

%description -n python3-fsleyes
%{desc}

%prep
%forgesetup

# remove jinja version fix
# https://github.com/pauldmccarthy/fsleyes/issues/82
sed -i 's/jinja2.*/jinja2/' requirements.txt
# relax required pyparsing version
sed -i 's/pyparsing==2.\*/pyparsing/' requirements.txt
# extras: not yet packaged in Fedora
sed -i '/file-tree/ d' requirements-extra.txt
# Add extra requirements for autogenerator
cat requirements-extra.txt >> requirements.txt
cat requirements-notebook.txt >> requirements.txt

# Remove unnecessary upper limit on Pillow:
# https://github.com/pauldmccarthy/fsleyes/issues/7
# sed -i 's/\(Pillow>=3.2.0\),.*/\1/' requirements.txt

# remove unneeded shebangs
find . -name "*py" -exec sed -i '/#!\/usr\/bin\/env python/ d' '{}' \;

%generate_buildrequires
%pyproject_buildrequires -r requirements.txt requirements-dev.txt

%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files fsleyes

# install desktop file in correct location
desktop-file-install --dir=%{buildroot}%{_datadir}/applications fsleyes/assets/linux/uk.ac.ox.fmrib.FSLeyes.desktop
rm -f %{python3_sitelib}/fsleyes/assets/linux/uk.ac.ox.fmrib.FSLeyes.desktop

# install appdata file
install -p -m 0644 -D -t %{buildroot}%{_metainfodir} fsleyes/assets/linux/uk.ac.ox.fmrib.FSLeyes.appdata.xml
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*FSLeyes*xml

rm -f %{python3_sitelib}/fsleyes/assets/linux/uk.ac.ox.fmrib.FSLeyes.appdata.xml

# install icons to the right place
pushd fsleyes/assets/icons/app_icon/fsleyes.iconset/
for size in 16 32 128 256 512
do
install -p -m 0755 -D -T "icon_${size}x${size}.png" %{buildroot}%{_datadir}/icons/hicolor/"${size}x${size}"/apps/fsleyes.png
done
# do these manually
install -p -m 0755 -D -T icon_32x32@2x.png %{buildroot}%{_datadir}/icons/hicolor/64x64/apps/fsleyes.png
install -p -m 0755 -D -T icon_512x512@2x.png %{buildroot}%{_datadir}/icons/hicolor/1024x1024/apps/fsleyes.png
popd
# 48x58 is in a different place than the others
install -p -m 0755 -D -t %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/ fsleyes/assets/linux/hicolor/48x48/apps/fsleyes.png


%check
export MPLBACKEND=wxagg
%if %{with xvfb_tests}
# https://github.com/pauldmccarthy/fsleyes/blob/master/.ci/test_template.sh
export FSLEYES_TEST_GL=2.1
xvfb-run -s "-screen 0 640x480x24" pytest-%{python3_version}
sleep 10
# test overlay types for GL14 as well
export FSLEYES_TEST_GL=1.4
xvfb-run -s "-screen 0 640x480x24" pytest-%{python3_version}
%endif

%files -n python3-fsleyes  -f %{pyproject_files}
%doc README.rst
%{_bindir}/fsleyes
%{_bindir}/render
%{_bindir}/fsleyes_unfiltered
%{_metainfodir}/uk.ac.ox.fmrib.FSLeyes.appdata.xml
%{_datadir}/icons/hicolor/*/apps/fsleyes.png
%{_datadir}/applications/uk.ac.ox.fmrib.FSLeyes.desktop

%changelog
* Sat Jul 22 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 1.7.0-1
- feat: update to 1.7.0 (fixes rhbz#2214584, rhbz#2220241)

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

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

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

* Wed Dec 21 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 1.5.0-2
- Leaf package: remove i686 support

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

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

* Tue Jul 19 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 1.4.1-4
- Relax required pyparsing version

* Tue Jul 19 2022 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 1.4.1-3
- Rebuilt for pyparsing-3.0.9

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

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

* Mon Jan 24 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 1.3.3-3
- feat: install icons and appdata file

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

* Sun Jan 16 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 1.3.3-1
- feat: update to latest patch release

* Mon Aug 09 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 1.1.0-2
- Drop extra deps not yet in Fedora
- fix Jinja2 version fix

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

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

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

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

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

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

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

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

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

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

* Sun Feb 16 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.32.0-3
- Fix requirements to remove * since autogenerator doesnt like it

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

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

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

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

* Sat Aug 31 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.30.1-1
- Update to 0.30.1

* Thu Aug 29 2019 Scott Talbert <swt@techie.net> - 0.30.0-5
- Remove sed patches for sip and revert to wx.siplib (#1739469)

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

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

* Wed Jul 10 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.30.0-2
- Add new bin file

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

* Mon May 27 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.29.0-1
- Update to 0.29.0

* Thu Apr 18 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.28.3-1
- Update to latest release
- Rely on automatic generator (enable for F<30)

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

* Sat Feb 16 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.27.3-1
- Update to latest upstream release

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

* Tue Nov 27 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.26.4-3
- Remove unnecessary pillow version limit
- Use wxpython4 and sip correctly from system

* Mon Nov 26 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.26.4-2
- Fix requires
- Enable available requires

* Fri Nov 09 2018 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.26.4-1
- Initial build