%global         srcname         kivy
%global         forgeurl        https://github.com/kivy/kivy
Version:        2.3.0
%global         tag             v%{version}
%forgemeta

Name:           python-%{srcname}
Release:        1%{?dist}
Summary:        Open source UI framework

# Main code is MIT, components of UI based on Moblintouch are LGPL-2.1
# and CC-BY-SA-3.0
License:        MIT AND LGPL-2.1-only AND CC-BY-SA-3.0
URL:            %forgeurl
Source0:        %{forgeurl}/archive/%{version}/%{srcname}-%{version}.tar.gz

BuildRequires:  dbus-devel
BuildRequires:  gcc
BuildRequires:  glew-devel
BuildRequires:  gstreamer1-devel
BuildRequires:  libpng-devel
BuildRequires:  make
BuildRequires:  pango-devel
BuildRequires:  python3-devel
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3dist(sphinxcontrib-jquery)
BuildRequires:  SDL2-devel
BuildRequires:  SDL2_image-devel
BuildRequires:  SDL2_mixer-devel
BuildRequires:  SDL2_ttf-devel
BuildRequires:  xclip
# Needed for tests
BuildRequires:  mtdev-devel
BuildRequires:  python3dist(certifi)
BuildRequires:  python3dist(pytest)
BuildRequires:  python3dist(pytest-asyncio)
BuildRequires:  python3dist(pytest-timeout)
BuildRequires:  python3dist(pytest-xvfb)
BuildRequires:  python3dist(responses)
# Do not use Bundled fonts
BuildRequires:  dejavu-sans-fonts
BuildRequires:  google-roboto-fonts
BuildRequires:  google-roboto-mono-fonts
Requires:  xclip
Requires:  dejavu-sans-fonts
Requires:  google-roboto-fonts
Requires:  google-roboto-mono-fonts


%global _description %{expand:
Kivy is an open-source Python framework for developing GUI apps that work
cross-platform, including desktop, mobile and embedded platforms.

The aim is to allow for quick and easy interaction design and rapid prototyping
whilst making your code reusable and deployable: Innovative user interfaces made
easy.

Kivy is written in Python and Cython and is built on OpenGL ES 2.0. It supports
various input devices and has an extensive (and extensible) widget library. With
the same codebase, you can target Windows, macOS, Linux (including Raspberry Pi
OS), Android, and iOS. All Kivy widgets are built with multitouch support.

Kivy is MIT licensed, actively developed by a great community and is supported
by many projects managed by the Kivy Organization.}


%description %_description

%package -n python3-%{srcname}
Summary:        %{summary}
%{?python_provide:%python_provide python3-%{srcname}}

%description -n python3-%{srcname} %_description

%package    devel
Summary:    Development files
Requires:   %{name}%{?_isa} = %{version}-%{release}

%description devel
Development header files for using Kivy.


%prep
%autosetup -p1 -n %{srcname}-%{version}
# remove benchmark from tests
sed -i /addopts/d pyproject.toml
# Remove bundled font files and softlink to fonts in Fedora
rm kivy/data/fonts/DejaVuSans.ttf
rm kivy/data/fonts/Roboto-BoldItalic.ttf
rm kivy/data/fonts/Roboto-Bold.ttf
rm kivy/data/fonts/Roboto-Italic.ttf
rm kivy/data/fonts/RobotoMono-Regular.ttf
rm kivy/data/fonts/Roboto-Regular.ttf
ln -s %{_datadir}/fonts/dejavu-sans-fonts/DejaVuSans.ttf \
  kivy/data/fonts/DejaVuSans.ttf
ln -s %{_datadir}/fonts/google-roboto/Roboto-BoldItalic.ttf \
  kivy/data/fonts/Roboto-BoldItalic.ttf
ln -s %{_datadir}/fonts/google-roboto/Roboto-Bold.ttf \
  kivy/data/fonts/Roboto-Bold.ttf
ln -s %{_datadir}/fonts/google-roboto/Roboto-Italic.ttf \
  kivy/data/fonts/Roboto-Italic.ttf
ln -s %{_datadir}/fonts/google-roboto/RobotoMono-Regular.ttf \
  kivy/data/fonts/RobotoMono-Regular.ttf
ln -s %{_datadir}/fonts/google-roboto/Roboto-Regular.ttf \
  kivy/data/fonts/Roboto-Regular.ttf


%generate_buildrequires
%pyproject_buildrequires


%build
export KIVY_SPLIT_EXAMPLES=1
%pyproject_wheel

# Build documentation
pushd doc
PYTHONPATH=`ls -d ../build/lib*` make PYTHON=%{python3} man
popd

%install
%pyproject_install
%pyproject_save_files %{srcname}
# Get list of header files from main package
cat %{pyproject_files} \
| grep '.\.h' \
| sed 's|%{buildroot}||' > kivy-devel.files
# Remove header files from main package
sed --in-place '/.\+\.h/d' %{pyproject_files}

# fix shebangs
%py3_shebang_fix \
%{buildroot}%{python3_sitearch}/kivy/tools/pep8checker/pre-commit.githook
%py3_shebang_fix \
%{buildroot}%{python3_sitearch}/kivy/tools/image-testsuite/gimp28-testsuite.py
%py3_shebang_fix \
%{buildroot}%{python3_sitearch}/kivy/tools/kviewer.py
%py3_shebang_fix \
%{buildroot}%{python3_sitearch}/kivy/tools/pep8checker/pep8.py
# Give correct permissions
chmod +x %{buildroot}%{python3_sitearch}/kivy/tools/kviewer.py
chmod +x %{buildroot}%{python3_sitearch}/kivy/tools/pep8checker/pep8.py

# Install documenation
mkdir -p %{buildroot}/%{_mandir}/man1
cp doc/build/man/kivy.1 %{buildroot}/%{_mandir}/man1/

%check
pushd examples
# Do not run GUI tests. Font tests also fail for some reason.
env KIVY_NO_ARGS=1 %pytest --pyargs kivy \
-k "test_clock or test_compat or test_config or test_doc_gallery or test_environ_cli or test_garden or test_invalid_lang or test_kivy_init or test_logger or test_multistroke or test_resourcees or test_rst_replace or test_storage or test_uix_layout or test_utils or test_vector or test_weakmethod"
popd

%files -n python3-%{srcname} -f %{pyproject_files}
%doc README.md
%doc CONTACT.md
%doc AUTHORS
%license LICENSE
%{_mandir}/man1/kivy.1*
%dir %{python3_sitearch}/kivy/
%dir %{python3_sitearch}/kivy/tools
%dir %{python3_sitearch}/kivy/tools/gles_compat

%files devel -f kivy-devel.files
%doc doc/sources/changelog.rst
%dir %{python3_sitearch}/kivy/include

%changelog
* Tue Jan 16 2024 Benson Muite <benson_muite@emailplus.org> - 2.3.0-1
- Initial import based on openSUSE spec file