1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
From: Dmitry Shachnev <mitya57@debian.org>
Date: Mon, 28 Sep 2020 14:39:47 +0300
Subject: Add support for building with SIP v5
Forwarded: https://github.com/frescobaldi/python-poppler-qt5/pull/41
---
project.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pyproject.toml | 37 ++++++++++++++++++++++++
version.sip.in | 21 ++++++++++++++
3 files changed, 146 insertions(+)
create mode 100644 project.py
create mode 100644 pyproject.toml
create mode 100644 version.sip.in
diff --git a/project.py b/project.py
new file mode 100644
index 0000000..17df8da
--- /dev/null
+++ b/project.py
@@ -0,0 +1,88 @@
+"""The build configuration file for Python-Poppler-Qt5, used by sip."""
+
+from os.path import join
+import re
+import subprocess
+from pyqtbuild import PyQtBindings, PyQtProject
+from sipbuild import Option
+import PyQt5
+
+
+class PythonPopplerQt5(PyQtProject):
+ """The Project class."""
+
+ def __init__(self):
+ super().__init__()
+ self.bindings_factories = [PopplerQt5Bindings]
+
+ def update(self, tool):
+ """Allows SIP to find PyQt5 .sip files."""
+ super().update(tool)
+ self.sip_include_dirs.append(join(PyQt5.__path__[0], 'bindings'))
+
+
+class PopplerQt5Bindings(PyQtBindings):
+ """The Poppler-Qt5 Bindings class."""
+
+ def __init__(self, project):
+ super().__init__(project, name='Poppler-Qt5',
+ sip_file='poppler-qt5.sip',
+ qmake_QT=['xml'])
+
+ def get_options(self):
+ """Our custom options that a user can pass to sip-build."""
+ options = super().get_options()
+ options.append(
+ Option('poppler_version',
+ help='version of the poppler library',
+ metavar='VERSION'))
+ return options
+
+ @staticmethod
+ def run_pkg_config(option):
+ output = subprocess.check_output(
+ ['pkg-config', option, 'poppler-qt5'],
+ text=True)
+ return output.rstrip()
+
+ def apply_user_defaults(self, tool):
+ # Set include_dirs, library_dirs and libraries based on pkg-config data
+ cflags = self.run_pkg_config('--cflags-only-I').split()
+ libs = self.run_pkg_config('--libs').split()
+ self.include_dirs.extend(
+ flag[2:] for flag in cflags if flag.startswith('-I'))
+ self.library_dirs.extend(
+ flag[2:] for flag in libs if flag.startswith('-L'))
+ self.libraries.extend(
+ flag[2:] for flag in libs if flag.startswith('-l'))
+
+ # Generate version.sip file
+ if self.poppler_version is not None:
+ poppler_qt5_version = self.poppler_version
+ else:
+ poppler_qt5_version = self.run_pkg_config('--modversion')
+ poppler_qt5_version = tuple(map(int, poppler_qt5_version.split('.')))
+ python_poppler_qt5_version = self.project.version_str.split('.')
+ format_dict = {
+ 'vlen': 'i' * len(python_poppler_qt5_version),
+ 'vargs': ', '.join(python_poppler_qt5_version),
+ 'pvlen': 'i' * len(poppler_qt5_version),
+ 'pvargs': ', '.join(map(str, poppler_qt5_version)),
+ }
+ with open('version.sip.in') as template_file:
+ version_sip_template = template_file.read()
+ with open('version.sip', 'w') as version_file:
+ version_file.write(version_sip_template.format(**format_dict))
+
+ # Add Poppler version tag
+ if poppler_qt5_version:
+ with open('timeline.sip') as timeline_file:
+ timeline = timeline_file.read()
+ for match in re.finditer(r'POPPLER_V(\d+)_(\d+)_(\d+)', timeline):
+ if poppler_qt5_version < tuple(map(int, match.group(1, 2, 3))):
+ break
+ tag = match.group()
+ else:
+ tag = 'POPPLER_V0_20_0'
+ self.tags.append(tag)
+ super().apply_user_defaults(tool)
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..5950d37
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,37 @@
+[build-system]
+requires = ["sip >=5", "PyQt-builder", "PyQt5"]
+build-backend = "sipbuild.api"
+
+[tool.sip.metadata]
+name = "python-poppler-qt5"
+version = "0.75.0"
+summary = "A Python binding to Poppler-Qt5"
+description-file = "README.rst"
+home-page = "https://github.com/frescobaldi/python-poppler-qt5"
+maintainer = "Wilbert Berendsen"
+maintainer-email = "wbsoft@xs4all.nl"
+license = "LGPL"
+classifier = [
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
+ "Operating System :: MacOS :: MacOS X",
+ "Operating System :: Microsoft :: Windows",
+ "Operating System :: POSIX",
+ "Programming Language :: Python :: 3",
+ "Topic :: Multimedia :: Graphics :: Viewers"
+]
+requires-dist = "PyQt5"
+
+[tool.sip.project]
+sip-files-dir = "."
+sdist-excludes = [
+ "version.sip",
+ ".git/*",
+ ".git/*/*",
+ ".git/*/*/*",
+ ".git/*/*/*/*",
+ ".git/*/*/*/*/*",
+ ".git/*/*/*/*/*/*",
+ ".git/*/*/*/*/*/*/*"
+]
diff --git a/version.sip.in b/version.sip.in
new file mode 100644
index 0000000..9d27c97
--- /dev/null
+++ b/version.sip.in
@@ -0,0 +1,21 @@
+// Generated by project.py -- Do not edit
+
+PyObject *version();
+%Docstring
+The version of the popplerqt5 python module.
+%End
+
+PyObject *poppler_version();
+%Docstring
+The version of the Poppler library it was built with.
+%End
+
+%ModuleCode
+
+PyObject *version()
+{{ return Py_BuildValue("({vlen})", {vargs}); }};
+
+PyObject *poppler_version()
+{{ return Py_BuildValue("({pvlen})", {pvargs}); }};
+
+%End
|