~ubuntu-branches/debian/sid/python-poppler-qt4/sid

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Package Import Robot
  • Author(s): Ryan Kavanagh
  • Date: 2012-01-01 18:16:27 UTC
  • Revision ID: package-import@ubuntu.com-20120101181627-nnjj7ff3akhry43s
Tags: upstream-0.16.2
ImportĀ upstreamĀ versionĀ 0.16.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! python
 
2
 
 
3
project = dict(
 
4
    name = 'python-poppler-qt4',
 
5
    version = '0.16.2',
 
6
    description = 'A Python binding to Poppler-Qt4',
 
7
    long_description = \
 
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/',
 
13
    license = 'LGPL',
 
14
    classifiers = [
 
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',
 
23
    ],
 
24
)
 
25
 
 
26
import os
 
27
import re
 
28
import shlex
 
29
import subprocess
 
30
import sys
 
31
 
 
32
from distutils.core import setup, Extension
 
33
import sipdistutils
 
34
 
 
35
import PyQt4.pyqtconfig
 
36
config = PyQt4.pyqtconfig.Configuration()
 
37
 
 
38
pyqt_sip_dir = config.pyqt_sip_dir
 
39
pyqt_sip_flags = config.pyqt_sip_flags
 
40
qt_inc_dir = config.qt_inc_dir
 
41
 
 
42
 
 
43
def pkg_config(package, attrs=None, include_only=False):
 
44
    """parse the output of pkg-config for a package.
 
45
    
 
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.
 
49
    
 
50
    """
 
51
    if attrs is None:
 
52
        attrs = {}
 
53
    cmd = ['pkg-config']
 
54
    if include_only:
 
55
        cmd += ['--cflags-only-I']
 
56
    else:
 
57
        cmd += ['--cflags', '--libs']
 
58
    cmd.append(package)
 
59
    try:
 
60
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
61
    except OSError:
 
62
        return attrs
 
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], [])
 
68
            if path not in l:
 
69
                l.append(path)
 
70
    return attrs
 
71
 
 
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]
 
75
    try:
 
76
        output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
 
77
        return tuple(map(int, re.findall(r'\d+', output)))
 
78
    except OSError:
 
79
        sys.stderr.write("Can't determine version of %s\n" % package)
 
80
        
 
81
 
 
82
ext_args = {
 
83
    'include_dirs': [
 
84
        qt_inc_dir,
 
85
        os.path.join(qt_inc_dir, 'QtCore'),
 
86
        os.path.join(qt_inc_dir, 'QtGui'),
 
87
        os.path.join(qt_inc_dir, 'QtXml'),
 
88
    ],
 
89
}
 
90
 
 
91
pkg_config('poppler-qt4', ext_args)
 
92
 
 
93
if 'libraries' not in ext_args:
 
94
    ext_args['libraries'] = ['poppler-qt4']
 
95
 
 
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):
 
99
    
 
100
    description = "Builds the popplerqt4 module."
 
101
    
 
102
    user_options = build_ext_base.user_options + [
 
103
        ('poppler-version=', None, "version of the poppler library"),
 
104
    ]
 
105
    
 
106
    def initialize_options (self):
 
107
        build_ext_base.initialize_options(self)
 
108
        self.poppler_version = None
 
109
 
 
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)))
 
114
 
 
115
    def _sip_compile(self, sip_bin, source, sbf):
 
116
        
 
117
        # Disable features if older poppler-qt4 version is found.
 
118
        # See the defined tags in %Timeline{} in poppler-qt4.sip.
 
119
        
 
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'
 
128
        else:
 
129
            tag = 'POPPLER_V0_16_0'
 
130
        
 
131
        cmd = [sip_bin]
 
132
        if hasattr(self, 'sip_opts'):
 
133
            cmd += self.sip_opts
 
134
        if hasattr(self, '_sip_sipfiles_dir'):
 
135
            cmd += ['-I', self._sip_sipfiles_dir()]
 
136
        if tag:
 
137
            cmd += ['-t', tag]
 
138
        cmd += [
 
139
            "-c", self.build_temp,
 
140
            "-b", sbf,
 
141
            "-I", pyqt_sip_dir]             # find the PyQt4 stuff
 
142
        cmd += shlex.split(pyqt_sip_flags)  # use same SIP flags as for PyQt4
 
143
        cmd.append(source)
 
144
        self.spawn(cmd)
 
145
 
 
146
 
 
147
setup(
 
148
    cmdclass = {'build_ext': build_ext},
 
149
    ext_modules = [Extension("popplerqt4", ["poppler-qt4.sip"], **ext_args)],
 
150
    **project
 
151
)