##
##  python-pdf.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_python        3.14
%define       V_reportlab     4.4.2
%define       V_pypdf         1.13
%define       V_pypdf2        3.0.1
%define       V_papersize     1.6.0
%define       V_pdfrw         0.4
%define       V_pymupdf       1.26.0

#   package information
Name:         python-pdf
Summary:      Python Modules for PDF Generation
URL:          http://www.python.org/
Vendor:       Python Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Language
License:      GPL
Version:      %{V_python}
Release:      20251008

#   list of sources
Source0:      https://files.pythonhosted.org/packages/source/r/reportlab/reportlab-%{V_reportlab}.tar.gz
Source1:      http://pybrary.net/pyPdf/pyPdf-%{V_pypdf}.tar.gz
Source2:      https://files.pythonhosted.org/packages/source/P/PyPDF2/PyPDF2-%{V_pypdf2}.tar.gz
Source3:      https://files.pythonhosted.org/packages/source/p/papersize/papersize-%{V_papersize}.tar.gz
Source4:      https://files.pythonhosted.org/packages/source/p/pdfrw/pdfrw-%{V_pdfrw}.tar.gz
Source5:      https://files.pythonhosted.org/packages/source/P/PyMuPDF/pymupdf-%{V_pymupdf}.tar.gz
Patch0:       python-pdf.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, python >= %{V_python}
PreReq:       OpenPKG, openpkg >= 20160101, python >= %{V_python}
BuildPreReq:  mupdf, freetype
PreReq:       mupdf, freetype

%description
    This is a set of Python extension modules for PDF generation.

%track
    prog python-pdf:reportlab = {
        version   = %{V_reportlab}
        url       = https://pypi.python.org/pypi/reportlab/
        regex     = reportlab-(__VER__)\.tar\.gz
    }
    prog python-pdf:pypdf = {
        version   = %{V_pypdf}
        url       = http://pybrary.net/pyPdf/
        regex     = pyPdf-(__VER__)\.tar\.gz
    }
    prog python-pdf:pypdf2 = {
        version   = %{V_pypdf2}
        url       = https://pypi.org/project/PyPDF2/
        regex     = PyPDF2-(__VER__)\.tar\.gz
    }
    prog python-pdf:papersize = {
        version   = %{V_papersize}
        url       = https://pypi.org/project/papersize/
        regex     = papersize-(__VER__)\.tar\.gz
    }
    prog python-pdf:pdfrw = {
        version   = %{V_pdfrw}
        url       = https://pypi.org/project/pdfrw/
        regex     = pdfrw-(__VER__)\.tar\.gz
    }
    prog python-pdf:pymupdf = {
        version   = %{V_pymupdf}
        url       = https://pypi.org/project/PyMuPDF/
        regex     = pymupdf-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %patch -p0

%build
    %{l_shtool} subst %{l_value -s -a} pymupdf-*/setup.py

%install
    export PYTHONPATH=$RPM_BUILD_ROOT%{l_prefix}/lib/python%{V_python}/site-packages
    ( cd reportlab-%{V_reportlab}
      %{l_prefix}/bin/python \
          setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd pyPdf-%{V_pypdf}
      HOME=`pwd` %{l_prefix}/bin/python \
          -m pip install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix} \
          --ignore-installed \
          --no-deps \
          .
    ) || exit $?
    ( cd PyPDF2-%{V_pypdf2}
      HOME=`pwd` %{l_prefix}/bin/python \
          -m pip install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix} \
          --ignore-installed \
          --no-deps \
          .
    ) || exit $?
    ( cd papersize-%{V_papersize}
      HOME=`pwd` %{l_prefix}/bin/python \
          -m pip install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix} \
          --ignore-installed \
          --no-deps \
          .
    ) || exit $?
    ( cd pdfrw-%{V_pdfrw}
      %{l_prefix}/bin/python \
          setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    #   (   cd pymupdf-%{V_pymupdf}
    #       CFLAGS="%{l_cflags -O} %{l_cppflags freetype .}" \
    #       CXXFLAGS="%{l_cxxflags -O} %{l_cppflags freetype .}" \
    #       LDFLAGS="%{l_ldflags} -lmupdf -lopenjp2" \
    #       PYMUPDF_INCLUDES="%{l_prefix}/include" \
    #       PYMUPDF_MUPDF_LIB="%{l_prefix}/lib" \
    #       PYMUPDF_SETUP_MUPDF_CLEAN=0 \
    #       PYMUPDF_SETUP_MUPDF_THIRD=0 \
    #       PYMUPDF_SETUP_MUPDF_BUILD="" \
    #       PYMUPDF_SETUP_MUPDF_TGZ="" \
    #       PYMUPDF_SETUP_MUPDF_REBUILD=0 \
    #       PYMUPDF_SETUP_IMPLEMENTATIONS=a \
    #       HOME=`pwd` %{l_prefix}/bin/python \
    #           -m pip install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix} \
    #           --ignore-installed \
    #           --no-deps \
    #           .
    #   ) || exit $?
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

