summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Kohler <bkohler@gentoo.org>2022-12-28 12:00:24 -0600
committerBen Kohler <bkohler@gentoo.org>2022-12-28 12:01:13 -0600
commitba04da63dc74a4c63775e26e8917559447279698 (patch)
treebb42b3ec772b90339bfd439b8a95faedf5fa7cb2 /dev-python/stapler
parentdev-python/stapler: revbump for changed RDEPEND (diff)
downloadgentoo-ba04da63dc74a4c63775e26e8917559447279698.tar.gz
gentoo-ba04da63dc74a4c63775e26e8917559447279698.tar.bz2
gentoo-ba04da63dc74a4c63775e26e8917559447279698.zip
dev-python/stapler: support PyPDF2-3.0.0 & misc fixes
Signed-off-by: Ben Kohler <bkohler@gentoo.org>
Diffstat (limited to 'dev-python/stapler')
-rw-r--r--dev-python/stapler/files/stapler-1.0.0_p20220330-fix-tests-for-PyPDF2-2.x.patch13
-rw-r--r--dev-python/stapler/files/stapler-1.0.0_p20220330-port-to-PyPDF2-3.0.0.patch302
-rw-r--r--dev-python/stapler/files/stapler-1.0.0_p20220330-use-poetry-core-backend-for-PEP517.patch32
-rw-r--r--dev-python/stapler/stapler-1.0.0_p20220330-r2.ebuild29
4 files changed, 376 insertions, 0 deletions
diff --git a/dev-python/stapler/files/stapler-1.0.0_p20220330-fix-tests-for-PyPDF2-2.x.patch b/dev-python/stapler/files/stapler-1.0.0_p20220330-fix-tests-for-PyPDF2-2.x.patch
new file mode 100644
index 000000000000..125b06a7735a
--- /dev/null
+++ b/dev-python/stapler/files/stapler-1.0.0_p20220330-fix-tests-for-PyPDF2-2.x.patch
@@ -0,0 +1,13 @@
+diff --git a/staplelib/tests.py b/staplelib/tests.py
+index 4d59153..447d48a 100755
+--- a/staplelib/tests.py
++++ b/staplelib/tests.py
+@@ -5,7 +5,7 @@ import shutil
+ import tempfile
+ import unittest
+
+-from PyPDF2.pdf import PdfFileReader
++from PyPDF2 import PdfFileReader
+
+ from staplelib import main, CommandError
+
diff --git a/dev-python/stapler/files/stapler-1.0.0_p20220330-port-to-PyPDF2-3.0.0.patch b/dev-python/stapler/files/stapler-1.0.0_p20220330-port-to-PyPDF2-3.0.0.patch
new file mode 100644
index 000000000000..91eea95ae217
--- /dev/null
+++ b/dev-python/stapler/files/stapler-1.0.0_p20220330-port-to-PyPDF2-3.0.0.patch
@@ -0,0 +1,302 @@
+From 48d6ab21369f1e71dc57890f9bf78fff66c00a90 Mon Sep 17 00:00:00 2001
+From: Ben Kohler <bkohler@gentoo.org>
+Date: Wed, 28 Dec 2022 10:08:30 -0600
+Subject: [PATCH 2/2] Port to PyPDF2-3.0.0
+
+Lots of functions got renamed in the recent PyPDF2-3.0.0 release
+
+Signed-off-by: Ben Kohler <bkohler@gentoo.org>
+---
+ staplelib/commands.py | 46 +++++++++++++++++++++----------------------
+ staplelib/iohelper.py | 12 +++++------
+ staplelib/tests.py | 34 ++++++++++++++++----------------
+ 3 files changed, 46 insertions(+), 46 deletions(-)
+
+diff --git a/staplelib/commands.py b/staplelib/commands.py
+index d37bfa7..caf75f9 100644
+--- a/staplelib/commands.py
++++ b/staplelib/commands.py
+@@ -4,9 +4,9 @@ import math
+ import os
+
+ try:
+- from PyPDF2 import PdfFileWriter, PdfFileReader
++ from PyPDF2 import PdfWriter, PdfReader
+ except:
+- from pyPdf import PdfFileWriter, PdfFileReader
++ from pyPdf import PdfWriter, PdfReader
+
+ from . import CommandError, iohelper
+ import staplelib
+@@ -33,7 +33,7 @@ def select(args, inverse=False):
+ if not filesandranges or not outputfilename:
+ raise CommandError("Both input and output filenames are required.")
+
+- output = PdfFileWriter()
++ output = PdfWriter()
+ try:
+ for input in filesandranges:
+ pdf = input['pdf']
+@@ -44,21 +44,21 @@ def select(args, inverse=False):
+ if not inverse:
+ pagerange = input['pages'] or [
+ (p, iohelper.ROTATION_NONE) for p in
+- range(1, pdf.getNumPages() + 1)]
++ range(1, len(pdf.pages) + 1)]
+ else:
+ excluded = [p for p, r in input['pages']]
+ pagerange = [(p, iohelper.ROTATION_NONE) for p in
+- range(1, pdf.getNumPages() + 1) if
++ range(1, len(pdf.pages) + 1) if
+ p not in excluded]
+
+ for pageno, rotate in pagerange:
+- if 1 <= pageno <= pdf.getNumPages():
++ if 1 <= pageno <= len(pdf.pages):
+ if verbose:
+ print("Using page: {} (rotation: {} deg.)".format(
+ pageno, rotate))
+
+- output.addPage(pdf.getPage(pageno-1)
+- .rotateClockwise(rotate))
++ output.add_page(pdf.pages[pageno-1]
++ .rotate(rotate))
+ else:
+ raise CommandError("Page {} not found in {}.".format(
+ pageno, input['name']))
+@@ -98,14 +98,14 @@ def split(args):
+ base,
+ '_',
+ '%0',
+- str(math.ceil(math.log10(input.getNumPages()))),
++ str(math.ceil(math.log10(len(input.pages)))),
+ 'd',
+ ext
+ ])
+
+- for pageno in range(input.getNumPages()):
+- output = PdfFileWriter()
+- output.addPage(input.getPage(pageno))
++ for pageno in range(len(input.pages)):
++ output = PdfWriter()
++ output.add_page(input.pages[pageno])
+
+ outputname = output_template % (pageno + 1)
+ if verbose:
+@@ -150,17 +150,17 @@ def zip_pdf_pages(filesandranges, verbose):
+ # empty range means "include all pages"
+ pagerange = input['pages'] or [
+ (p, iohelper.ROTATION_NONE) for p in
+- range(1, pdf.getNumPages() + 1)]
++ range(1, len(pdf.pages) + 1)]
+
+ pagestozip = []
+ for pageno, rotate in pagerange:
+- if 1 <= pageno <= pdf.getNumPages():
++ if 1 <= pageno <= len(pdf.pages):
+ if verbose:
+ print("Using page: {} (rotation: {} deg.)".format(
+ pageno, rotate))
+
+- pagestozip.append(pdf.getPage(pageno-1)
+- .rotateClockwise(rotate))
++ pagestozip.append(pdf.pages[pageno-1]
++ .rotate(rotate))
+ else:
+ raise CommandError("Page {} not found in {}.".format(
+ pageno, input['name']))
+@@ -181,7 +181,7 @@ def background(args):
+ try:
+ filestozip = zip_pdf_pages(filesandranges, verbose)
+
+- output = PdfFileWriter()
++ output = PdfWriter()
+ for pageno in range(max(map(len, filestozip))):
+ page = None
+ for listno in range(len(filestozip)):
+@@ -190,8 +190,8 @@ def background(args):
+ if not page:
+ page = p
+ else:
+- page.mergePage(p)
+- output.addPage(page)
++ page.merge_page(p)
++ output.add_page(page)
+
+ except Exception as e:
+ import sys
+@@ -213,11 +213,11 @@ def zip(args):
+ filestozip = zip_pdf_pages(filesandranges, verbose)
+
+ # Interweave pages.
+- output = PdfFileWriter()
++ output = PdfWriter()
+ for pageno in range(max(map(len, filestozip))):
+ for listno in range(len(filestozip)):
+ if pageno < len(filestozip[listno]):
+- output.addPage(filestozip[listno][pageno])
++ output.add_page(filestozip[listno][pageno])
+
+ _write_output(output, outputfilename)
+
+@@ -266,7 +266,7 @@ def pdf_page_enumeration(pdf):
+ pagelabels = pdf.trailer["/Root"]["/PageLabels"]
+ except:
+ # ("No /Root/PageLabels object"), so infer the list.
+- return range(1, pdf.getNumPages() + 1)
++ return range(1, len(pdf.pages) + 1)
+
+ # """Select the item that is most likely to contain the information you desire; e.g.
+ # {'/Nums': [0, IndirectObject(42, 0)]}
+@@ -292,7 +292,7 @@ def pdf_page_enumeration(pdf):
+ style = '/D'
+ prefix = ''
+ next_pageno = 1
+- for i in range(0, pdf.getNumPages()):
++ for i in range(0, len(pdf.pages)):
+ if len(pagelabels_nums_list) > 0 and i >= pagelabels_nums_list[0]:
+ pagelabels_nums_list.pop(0) # discard index
+ pnle = pagelabels_nums_list.pop(0)
+diff --git a/staplelib/iohelper.py b/staplelib/iohelper.py
+index 959e900..8df365c 100644
+--- a/staplelib/iohelper.py
++++ b/staplelib/iohelper.py
+@@ -7,9 +7,9 @@ import re
+ import sys
+
+ try:
+- from PyPDF2 import PdfFileWriter, PdfFileReader
++ from PyPDF2 import PdfWriter, PdfReader
+ except ImportError:
+- from pyPdf import PdfFileWriter, PdfFileReader
++ from pyPdf import PdfWriter, PdfReader
+
+
+ from . import CommandError
+@@ -31,8 +31,8 @@ def read_pdf(filename):
+ """Open a PDF file with PyPDF2."""
+ if not os.path.exists(filename):
+ raise CommandError("{} does not exist".format(filename))
+- pdf = PdfFileReader(open(filename, "rb"))
+- if pdf.isEncrypted:
++ pdf = PdfReader(open(filename, "rb"))
++ if pdf.is_encrypted:
+ while True:
+ pw = prompt_for_pw(filename)
+ matched = pdf.decrypt(pw)
+@@ -46,7 +46,7 @@ def read_pdf(filename):
+ def write_pdf(pdf, filename):
+ force = staplelib.OPTIONS.force
+
+- """Write the content of a PdfFileWriter object to a file."""
++ """Write the content of a PdfWriter object to a file."""
+ if os.path.exists(filename) and not force:
+ raise CommandError("File already exists: {}".format(filename))
+
+@@ -123,7 +123,7 @@ def parse_ranges(handles_files_and_ranges):
+ "page range '{}'".format(handle_key, inputname))
+
+ current = operations[-1]
+- max_page = current['pdf'].getNumPages()
++ max_page = len(current['pdf'].pages)
+ # allow "end" as alias for the last page
+ replace_end = lambda page: (
+ max_page if page.lower() == 'end' else int(page))
+diff --git a/staplelib/tests.py b/staplelib/tests.py
+index 4d59153..3350dfc 100755
+--- a/staplelib/tests.py
++++ b/staplelib/tests.py
+@@ -5,7 +5,7 @@ import shutil
+ import tempfile
+ import unittest
+
+-from PyPDF2 import PdfFileReader
++from PyPDF2 import PdfReader
+
+ from staplelib import main, CommandError
+
+@@ -38,40 +38,40 @@ class TestStapler(unittest.TestCase):
+ self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 6)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 6)
+
+ def test_sel_one_page(self):
+ """Test select of a one page from a PDF file."""
+ run_stapler(['sel', 'A=' + FIVEPAGE_PDF, 'A2', self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 1)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 1)
+
+ def test_sel_range(self):
+ """Test select of more pages from a PDF file."""
+ run_stapler(['cat', 'A=' + FIVEPAGE_PDF, 'A2-4', self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 3)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 3)
+
+ def test_del_one_page(self):
+ """Test del command for inverse select of one page."""
+ run_stapler(['del', 'A=' + FIVEPAGE_PDF, 'A1', self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 4)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 4)
+
+ def test_del_range(self):
+ """Test del command for inverse select multiple pages."""
+ run_stapler(['del', 'A=' + FIVEPAGE_PDF, 'A2-4', self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 2)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 2)
+
+ def test_split(self):
+ """Make sure a file is properly split into pages."""
+@@ -81,24 +81,24 @@ class TestStapler(unittest.TestCase):
+ self.assertEqual(len(filelist), 5)
+ for f in os.listdir(self.tmpdir):
+ with open(os.path.join(self.tmpdir, f), 'rb') as pdf_file:
+- pdf = PdfFileReader(pdf_file)
+- self.assertEqual(pdf.getNumPages(), 1)
++ pdf = PdfReader(pdf_file)
++ self.assertEqual(len(pdf.pages), 1)
+
+ def test_background(self):
+ """Test background."""
+ run_stapler(['background', ONEPAGE_PDF, FIVEPAGE_PDF, self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 5)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 5)
+
+ def test_zip(self):
+ """Test zip."""
+ run_stapler(['zip', ONEPAGE_PDF, FIVEPAGE_PDF, self.outputfile])
+ self.assertTrue(os.path.isfile(self.outputfile))
+ with open(self.outputfile, 'rb') as outputfile:
+- pdf = PdfFileReader(outputfile)
+- self.assertEqual(pdf.getNumPages(), 6)
++ pdf = PdfReader(outputfile)
++ self.assertEqual(len(pdf.pages), 6)
+
+ def test_output_file_already_exists(self):
+ """Test zip."""
+--
+2.39.0
+
diff --git a/dev-python/stapler/files/stapler-1.0.0_p20220330-use-poetry-core-backend-for-PEP517.patch b/dev-python/stapler/files/stapler-1.0.0_p20220330-use-poetry-core-backend-for-PEP517.patch
new file mode 100644
index 000000000000..276df746791f
--- /dev/null
+++ b/dev-python/stapler/files/stapler-1.0.0_p20220330-use-poetry-core-backend-for-PEP517.patch
@@ -0,0 +1,32 @@
+From 3907d86f515ff0e9f042df7111515205e9abaa11 Mon Sep 17 00:00:00 2001
+From: Ben Kohler <bkohler@gentoo.org>
+Date: Thu, 26 May 2022 13:33:38 -0500
+Subject: [PATCH 1/2] pyproject.toml: use poetry-core backend for PEP517
+
+Per poetry upstream, "If your pyproject.toml file still references
+poetry directly as a build backend, you should update it to reference
+poetry-core instead."
+
+https://python-poetry.org/docs/pyproject/#poetry-and-pep-517
+https://projects.gentoo.org/python/guide/distutils.html#deprecated-pep-517-backends
+
+Signed-off-by: Ben Kohler <bkohler@gentoo.org>
+---
+ pyproject.toml | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/pyproject.toml b/pyproject.toml
+index efa98ea..d34823e 100644
+--- a/pyproject.toml
++++ b/pyproject.toml
+@@ -28,5 +28,5 @@ pdf-stapler = 'staplelib:main'
+
+ # this section is for PEP517 compliance. It is technically unnecessary if using Poetry
+ [build-system]
+-requires = ["poetry>=1.0"]
+-build-backend = "poetry.masonry.api"
++requires = ["poetry-core>=1.0.0"]
++build-backend = "poetry.core.masonry.api"
+--
+2.39.0
+
diff --git a/dev-python/stapler/stapler-1.0.0_p20220330-r2.ebuild b/dev-python/stapler/stapler-1.0.0_p20220330-r2.ebuild
new file mode 100644
index 000000000000..93ca68b5fcee
--- /dev/null
+++ b/dev-python/stapler/stapler-1.0.0_p20220330-r2.ebuild
@@ -0,0 +1,29 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PYTHON_COMPAT=( python3_{9..11} )
+DISTUTILS_USE_PEP517=poetry
+
+inherit distutils-r1
+
+COMMIT="382f1edc62296e071093a5419811a2fca9d78d93"
+
+DESCRIPTION="Suite of tools for PDF files manipulation written in Python"
+HOMEPAGE="https://github.com/hellerbarde/stapler"
+SRC_URI="https://github.com/hellerbarde/${PN}/archive/${COMMIT}.tar.gz -> ${P}.tar.gz"
+S="${WORKDIR}/${PN}-${COMMIT}"
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+
+DEPEND="test? ( >=dev-python/PyPDF2-3.0.0[${PYTHON_USEDEP}] )"
+RDEPEND=">=dev-python/PyPDF2-3.0.0[${PYTHON_USEDEP}]"
+
+distutils_enable_tests unittest
+
+PATCHES=( "${FILESDIR}"/${P}-fix-tests-for-PyPDF2-2.x.patch
+ "${FILESDIR}"/${P}-port-to-PyPDF2-3.0.0.patch
+ "${FILESDIR}"/${P}-use-poetry-core-backend-for-PEP517.patch )