4
name = 'python-poppler-qt4',
6
description = 'A Python binding to Poppler-Qt4',
8
'A Python binding to Poppler-Qt4 that aims for ' \
9
'completeness and for being actively maintained.',
10
maintainer = 'Wilbert Berendsen',
11
maintainer_email = 'wbsoft@xs4all.nl',
12
url = 'http://python-poppler-qt4.googlecode.com/',
15
'Development Status :: 4 - Beta',
16
'Intended Audience :: Developers',
17
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
18
'Operating System :: MacOS :: MacOS X',
19
'Operating System :: Microsoft :: Windows',
20
'Operating System :: POSIX',
21
'Programming Language :: Python',
22
'Topic :: Multimedia :: Graphics :: Viewers',
32
from distutils.core import setup, Extension
35
import PyQt4.pyqtconfig
36
config = PyQt4.pyqtconfig.Configuration()
38
pyqt_sip_dir = config.pyqt_sip_dir
39
pyqt_sip_flags = config.pyqt_sip_flags
40
qt_inc_dir = config.qt_inc_dir
43
def pkg_config(package, attrs=None, include_only=False):
44
"""parse the output of pkg-config for a package.
46
returns the given or a new dictionary with one or more of these keys
47
'include_dirs', 'library_dirs', 'libraries'. Every key is a list of paths,
48
so that it can be used with distutils Extension objects.
55
cmd += ['--cflags-only-I']
57
cmd += ['--cflags', '--libs']
60
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
63
flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
64
for flag in shlex.split(output):
65
option, path = flag[:2], flag[2:]
66
if option in flag_map:
67
l = attrs.setdefault(flag_map[option], [])
72
def pkg_config_version(package):
73
"""Returns the version of the given package as a tuple of ints."""
74
cmd = ['pkg-config', '--modversion', package]
76
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
77
return tuple(map(int, re.findall(r'\d+', output)))
79
sys.stderr.write("Can't determine version of %s\n" % package)
85
os.path.join(qt_inc_dir, 'QtCore'),
86
os.path.join(qt_inc_dir, 'QtGui'),
87
os.path.join(qt_inc_dir, 'QtXml'),
91
pkg_config('poppler-qt4', ext_args)
93
if 'libraries' not in ext_args:
94
ext_args['libraries'] = ['poppler-qt4']
96
# hack to provide our options to sip on its invocation:
97
build_ext_base = sipdistutils.build_ext
98
class build_ext(build_ext_base):
100
description = "Builds the popplerqt4 module."
102
user_options = build_ext_base.user_options + [
103
('poppler-version=', None, "version of the poppler library"),
106
def initialize_options (self):
107
build_ext_base.initialize_options(self)
108
self.poppler_version = None
110
def finalize_options (self):
111
build_ext_base.finalize_options(self)
112
if self.poppler_version is not None:
113
self.poppler_version = tuple(map(int, re.findall(r'\d+', self.poppler_version)))
115
def _sip_compile(self, sip_bin, source, sbf):
117
# Disable features if older poppler-qt4 version is found.
118
# See the defined tags in %Timeline{} in poppler-qt4.sip.
120
# First check manually specified poppler version
121
ver = self.poppler_version or pkg_config_version('poppler-qt4')
122
if not ver or ver < (0, 12, 1):
123
tag = 'POPPLER_V0_12_0'
124
elif ver < (0, 14, 0):
125
tag = 'POPPLER_V0_12_1'
126
elif ver < (0, 16, 0):
127
tag = 'POPPLER_V0_14_0'
129
tag = 'POPPLER_V0_16_0'
132
if hasattr(self, 'sip_opts'):
134
if hasattr(self, '_sip_sipfiles_dir'):
135
cmd += ['-I', self._sip_sipfiles_dir()]
139
"-c", self.build_temp,
141
"-I", pyqt_sip_dir] # find the PyQt4 stuff
142
cmd += shlex.split(pyqt_sip_flags) # use same SIP flags as for PyQt4
148
cmdclass = {'build_ext': build_ext},
149
ext_modules = [Extension("popplerqt4", ["poppler-qt4.sip"], **ext_args)],