File python-PyMuPDF.spec of Package python-PyMuPDF

#
# spec file for package python-PyMuPDF
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


# Python 2 build fails always
%define skip_python2 1
%define pypi_name PyMuPDF
%define mupdf_version 1.25.2
# use python version that has Clang bindings
%define pythons python3
Name:           python-%{pypi_name}
Version:        1.25.1
Release:        0
Summary:        Python binding for MuPDF, a PDF and XPS viewer
License:        AGPL-3.0-only
Group:          Development/Libraries/Python
URL:            https://github.com/pymupdf/%{pypi_name}
Source0:        https://files.pythonhosted.org/packages/source/P/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
Source1:        https://mupdf.com/downloads/archive/mupdf-%{mupdf_version}-source.tar.gz#/mupdf-%{mupdf_version}-source.tar.gz
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module wheel}
BuildRequires:  fdupes
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  openSUSE-release
BuildRequires:  pkgconfig
BuildRequires:  python-rpm-macros
BuildRequires:  python3-clang
BuildRequires:  swig
BuildRequires:  cmake(Clang)
BuildRequires:  pkgconfig(freetype2)
BuildRequires:  pkgconfig(harfbuzz)
BuildRequires:  pkgconfig(jbig2dec)
BuildRequires:  pkgconfig(lept)
BuildRequires:  pkgconfig(libarchive)
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(libopenjp2)
BuildRequires:  pkgconfig(libpng16)
BuildRequires:  pkgconfig(tesseract)
BuildRequires:  pkgconfig(zlib)
Provides:       bundled(glut)
Provides:       bundled(gumbo-parser)
Provides:       bundled(libturbojpeg)
Provides:       bundled(mupdf) = %{mupdf_version}
# mupdf has bundled() on its own, too, so kinda bad
%python_subpackages

%description
This is PyMuPDF, a Python binding for MuPDF, a PDF and XPS viewer.
MuPDF can access files in PDF, XPS, OpenXPS, epub, comic and fiction
book formats. PyMuPDF can also access files with extensions *.pdf,
*.xps, *.oxps, *.epub, *.cbz or *.fb2 from Python scripts.

%prep
%autosetup -p1 -n %{pypi_name}-%{version} -a1

# disable google analytics for installed doc
sed -i -e "s/,'sphinxcontrib.googleanalytics'//" docs/conf.py

pushd $PWD/mupdf-%{mupdf_version}-source
for d in $(ls thirdparty | grep -v -e extract -e lcms2 -e mujs -e libjpeg -e glut -e gumbo-parser)
do
    rm -rf thirdparty/$d
done

echo > user.make "\
USE_SYSTEM_FREETYPE := yes
USE_SYSTEM_HARFBUZZ := yes
USE_SYSTEM_JBIG2DEC := yes
USE_SYSTEM_OPENJPEG := yes
USE_SYSTEM_ZLIB := yes
USE_SYSTEM_CURL := yes
USE_SYSTEM_LEPTONICA := yes
USE_SYSTEM_TESSERACT := yes
# bundled packages
USE_SYSTEM_GUMBO := no
USE_SYSTEM_GLUT := no # uses a custom fork
USE_SYSTEM_LIBJPEG := no # libjpeg8a not available
USE_SYSTEM_MUJS := no # build needs source anyways
USE_TESSERACT := yes
VENV_FLAG :=
build := debug
shared := yes
verbose := yes
"

# c++ and python install targets rebuild unconditionally. Avoid multiple rebuilds:
sed -i -e '/^install-shared-c++:/s/ c++//' Makefile
sed -i -e '/^install-shared-python:/s/ python//' Makefile
popd
# rm -rf $PWD/mupdf-%%{mupdf_version}-source/thirdparty/{freetype,harfbuzz,jbig2dec,leptonica,openjpeg,tesseract,zlib}

%build
#INCLUDES="$(pkgconf --cflags-only-I freetype2) $(pkgconf --cflags-only-I harfbuzz) $(pkgconf --cflags-only-I libopenjp2) $(pkgconf --cflags-only-I lept)"
export CFLAGS="%{optflags} $(pkgconf --cflags-only-I freetype2) -DNDEBUG"
# generate debug symbols
export PYMUPDF_SETUP_MUPDF_BUILD_TYPE='debug'
# path tp mupdf source dir
export PYMUPDF_SETUP_MUPDF_BUILD=$PWD/mupdf-%{mupdf_version}-source/
# don't download the sources
export PYMUPDF_SETUP_MUPDF_TGZ=
# clean rebuild
export PYMUPDF_SETUP_MUPDF_CLEAN=1
# include bundled mupdf libs
export PYMUPDF_SETUP_FLAVOUR=pb
# building for a fixed minor python version
export PYMUPDF_SETUP_PY_LIMITED_API=0

export ARCHFLAGS="%{optflags}"

%pyproject_wheel

%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitearch}

%check
cd /tmp
%python_expand PYTHONPATH=%{buildroot}%{$python_sitearch} $python -c 'import fitz'

%files %{python_files}
%license COPYING
%doc README.md
%{python_sitearch}/[Pp]y[Mm]u[Pp][Dd][Ff]/
%{python_sitearch}/[Pp]y[Mm]u[Pp][Dd][Ff]-%{version}*info
%{python_sitearch}/fitz/
%{_bindir}/pymupdf

%changelog
openSUSE Build Service is sponsored by