public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/krop] rawhide: spec cleanup and modernization, fixes rhbz#2377302
@ 2026-06-16  5:07 Filipe Rosset
  0 siblings, 0 replies; only message in thread
From: Filipe Rosset @ 2026-06-16  5:07 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/krop
            Branch : rawhide
            Commit : 1edafb7b19227979c146d87ba0435bf77e67a3a1
            Author : Filipe Rosset <filiperosset@fedoraproject.org>
            Date   : 2026-06-16T02:06:52-03:00
            Stats  : +138/-73 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/krop/c/1edafb7b19227979c146d87ba0435bf77e67a3a1?branch=rawhide

            Log:
            spec cleanup and modernization, fixes rhbz#2377302

Signed-off-by: Filipe Rosset <filiperosset@fedoraproject.org>

---
diff --git a/krop-0.5.1-pypdf.patch b/krop-0.5.1-pypdf.patch
new file mode 100644
index 0000000..ec858c0
--- /dev/null
+++ b/krop-0.5.1-pypdf.patch
@@ -0,0 +1,106 @@
+--- krop-0.5.1/krop/pdfcropper.py.orig	2026-06-16 01:54:43.733091604 -0300
++++ krop-0.5.1/krop/pdfcropper.py	2026-06-16 01:54:40.971167980 -0300
+@@ -16,22 +16,28 @@ the Free Software Foundation; either ver
+ import copy
+ import sys
+ 
+-# Unless specified otherwise, use PyPDF2 instead of pyPdf if available.
+-usepypdf2 = '--no-PyPDF2' not in sys.argv
+-if usepypdf2:
+-    try:
+-        from PyPDF2 import PdfFileReader, PdfFileWriter
+-    except ImportError:
+-        usepypdf2 = False
+-if not usepypdf2:
+-    try:
+-        from pyPdf import PdfFileReader, PdfFileWriter
+-    except ImportError:
+-        _msg = "Please install PyPDF2 (or its predecessor pyPdf) first."\
+-            "\n\tOn recent versions of Ubuntu, the following should do the trick:"\
+-            "\n\tsudo apt-get install python-pypdf2"\
+-            "\n\t(or, if using python3) sudo apt-get install python3-pypdf2"
+-        raise RuntimeError(_msg)
++# Try importing pypdf first, then PyPDF2, then pyPdf
++try:
++    from pypdf import PdfReader, PdfWriter
++except ImportError:
++    usepypdf2 = '--no-PyPDF2' not in sys.argv
++    if usepypdf2:
++        try:
++            from PyPDF2 import PdfReader, PdfWriter
++        except ImportError:
++            try:
++                from PyPDF2 import PdfFileReader as PdfReader, PdfFileWriter as PdfWriter
++            except ImportError:
++                usepypdf2 = False
++    if not usepypdf2:
++        try:
++            from pyPdf import PdfFileReader as PdfReader, PdfFileWriter as PdfWriter
++        except ImportError:
++            _msg = "Please install pypdf, PyPDF2 (or its predecessor pyPdf) first."\
++                "\n\tOn recent versions of Fedora, the following should do the trick:"\
++                "\n\tsudo dnf install python3-pypdf"
++            raise RuntimeError(_msg)
++
+ 
+ 
+ class AbstractPdfFile:
+@@ -60,17 +66,20 @@ class PyPdfFile(AbstractPdfFile):
+     def __init__(self):
+         self.reader = None
+     def loadFromStream(self, stream):
+-        if usepypdf2:
+-            self.reader = PdfFileReader(stream, strict=False)
+-        else:
+-            self.reader = PdfFileReader(stream)
++        try:
++            self.reader = PdfReader(stream, strict=False)
++        except TypeError:
++            self.reader = PdfReader(stream)
+     def getPage(self, nr):
+-        page = self.reader.getPage(nr-1)
++        if hasattr(self.reader, 'pages'):
++            return self.reader.pages[nr-1]
++        else:
++            return self.reader.getPage(nr-1)
+ 
+ class PyPdfCropper(AbstractPdfCropper):
+     """Implementation of PdfCropper using pyPdf"""
+     def __init__(self):
+-        self.output = PdfFileWriter()
++        self.output = PdfWriter()
+     def writeToStream(self, stream):
+         # For certain large pdf files, PdfFileWriter.write() causes the error:
+         #  maximum recursion depth exceeded while calling a Python object
+@@ -83,11 +92,17 @@ class PyPdfCropper(AbstractPdfCropper):
+     def addPageCropped(self, pdffile, pagenumber, croplist, rotate=0):
+         if not croplist:
+             return
+-        page = pdffile.reader.getPage(pagenumber)
++        if hasattr(pdffile.reader, 'pages'):
++            page = pdffile.reader.pages[pagenumber]
++        else:
++            page = pdffile.reader.getPage(pagenumber)
+         for c in croplist:
+             newpage = copy.copy(page)
+             self.cropPage(newpage, c, rotate)
+-            self.output.addPage(newpage)
++            if hasattr(self.output, 'add_page'):
++                self.output.add_page(newpage)
++            else:
++                self.output.addPage(newpage)
+     def cropPage(self, page, crop, rotate):
+         # Note that the coordinate system is up-side down compared with Qt.
+         x0, y0 = page.cropBox.lowerLeft
+@@ -100,7 +115,10 @@ class PyPdfCropper(AbstractPdfCropper):
+             box.lowerLeft = (x0, y0)
+             box.upperRight = (x1, y1)
+         if rotate != 0:
+-            page.rotateClockwise(rotate)
++            if hasattr(page, 'rotate'):
++                page.rotate(rotate)
++            else:
++                page.rotateClockwise(rotate)
+ 
+ def optimizePdfGhostscript(oldfilename, newfilename):
+     import subprocess

diff --git a/krop.spec b/krop.spec
index 0911557..d05b30b 100644
--- a/krop.spec
+++ b/krop.spec
@@ -1,114 +1,73 @@
-%global osname  %(cat /etc/redhat-release | awk '{sub(/ release.*/,""); print}')
-%global pkgmgr  dnf
-
-%bcond_without  python3
-
 Name:           krop
 Version:        0.5.1
-Release:        30%{?dist}
-Summary:        Tool to crop PDF files with an eye towards eReaders
-# Automatically converted from old format: GPLv3+ - review is highly recommended.
+Release:        31%{?dist}
+Summary:        Tool to crop PDF files with an eye towards e-readers
 License:        GPL-3.0-or-later
 URL:            http://arminstraub.com/software/krop
 Source0:        http://arminstraub.com/downloads/%{name}/%{name}-%{version}.tar.gz
 
 BuildArch:      noarch
 
-# upstreamable patch, see also
-# https://bugzilla.redhat.com/show_bug.cgi?id=1707034
-# https://github.com/arminstraub/krop/issues/23
-Patch1: krop-0.5.1-sip_namespace.patch
+Patch1:         krop-0.5.1-sip_namespace.patch
+Patch2:         krop-0.5.1-pypdf.patch
 
 BuildRequires:  desktop-file-utils
 BuildRequires:  libappstream-glib
-
-%if %without python3
-BuildRequires:  python2-devel
-BuildRequires:  python2-setuptools
-Requires:       python2-%{name} = %{version}-%{release}
-%else
 BuildRequires:  python3-devel
-BuildRequires:  python3-setuptools
-Requires:       python3-%{name} = %{version}-%{release}
-%endif
+BuildRequires:  python3-pypdf
+BuildRequires:  python3-qt5
+BuildRequires:  python3-poppler-qt5
 
+Requires:       python3-%{name} = %{version}-%{release}
 
 %description
 Krop is a simple graphical tool to crop the pages of PDF files. A unique feature
-of krop is its ability to automatically split pages into subpages to fit the
-limited screen size of devices such as eReaders. This is particularly useful, if
-your eReader does not support convenient scrolling.
-
-%if %without python3
-%package -n python2-%{name}
-Summary:    Python2 module for %{name}
-Requires:   python-PyPDF2 PyQt5 python-poppler-qt5
-%{?python_provide:%python_provide python2-%{name}}
-
-%description -n python2-%{name}
-%else
+of krop is its ability to automatically split pages into sub-pages to fit the
+limited screen size of devices such as e-readers. This is particularly useful if
+your e-reader does not support convenient scrolling.
+
 %package -n python3-%{name}
-Summary:    Python3 module for %{name}
-Requires:   python3-PyPDF2 python3-PyQt5 python3-poppler-qt5
-%{?python_provide:%python_provide python3-%{name}}
+Summary:        Python 3 module for %{name}
+Requires:       python3-pypdf
+Requires:       python3-qt5
+Requires:       python3-poppler-qt5
 
 %description -n python3-%{name}
-%endif
 %{summary}.
 
-
 %prep
-%setup -q
-# In terms of OS available on Koji. "of" is needed since Ubuntu appears as font.
-find . -type f -name '*.py' -exec sed -i -e 's/of ubuntu/of %{osname}/Ig' \
- -e 's|apt-get|%{pkgmgr}|g' -e 's|python-pypdf|pyPdf|g' '{}' +
+%autosetup -p1
+find . -type f -name '*.py' -exec sed -i -e 's/of ubuntu/of Fedora/Ig' \
+ -e 's|apt-get|dnf|g' -e 's|python-pypdf|pyPdf|g' '{}' +
 
-%patch -P1 -p1 -b .sip_namespace
+%generate_buildrequires
+%pyproject_buildrequires
 
 %build
-%if %without python3
-%py2_build
-%else
-%py3_build
-%endif
+%pyproject_wheel
 
 %install
-%if %without python3
-%py2_install
-%else
-%py3_install
-%endif
+%pyproject_install
+%pyproject_save_files -l %{name}
 desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{name}.desktop
-DESTDIR="%{buildroot}" appstream-util install %{name}.appdata.xml
-
+install -D -p -m 0644 %{name}.appdata.xml %{buildroot}%{_metainfodir}/%{name}.appdata.xml
 
 %check
-%if %without python3
-%{__python2} setup.py check
-%else
-%{__python3} setup.py check
-%endif
-appstream-util validate-relax --nonet %{buildroot}%{_datadir}/appdata/*.appdata.xml
+%pyproject_check_import -e krop.mainwindowui_qt4
+appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/%{name}.appdata.xml
 
 %files
 %doc ChangeLog
 %{_bindir}/%{name}
-%{_datadir}/appdata/%{name}.appdata.xml
+%{_metainfodir}/%{name}.appdata.xml
 %{_datadir}/applications/%{name}.desktop
 
-%if %without python3
-%files -n python2-%{name}
-%{python2_sitelib}/%{name}-%{version}-py%{python2_version}.egg-info
-%{python2_sitelib}/%{name}/
-%else
-%files -n python3-%{name}
-%{python3_sitelib}/%{name}-%{version}-py%{python3_version}.egg-info
-%{python3_sitelib}/%{name}/
-%endif
-%license LICENSE
-
+%files -n python3-%{name} -f %{pyproject_files}
 
 %changelog
+* Tue Jun 16 2026 Filipe Rosset <filiperosset@fedoraproject.org> - 0.5.1-31
+- spec cleanup and modernization, fixes rhbz#2377302
+
 * Wed Jun 03 2026 Python Maint <python-maint@redhat.com> - 0.5.1-30
 - Rebuilt for Python 3.15
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-16  5:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-16  5:07 [rpms/krop] rawhide: spec cleanup and modernization, fixes rhbz#2377302 Filipe Rosset

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox