%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
License:        MIT AND LGPL-2.1-only
URL:            %forgeurl
Source0:        %forgesource

BuildRequires:  dbus-devel
BuildRequires:  gcc
BuildRequires:  glew-devel
BuildRequires:  gstreamer1-devel
BuildRequires:  libpng-devel
BuildRequires:  pango-devel
BuildRequires:  python3-devel
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

%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

%install
%pyproject_install
%pyproject_save_files %{srcname}

# 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

%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


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