-
Notifications
You must be signed in to change notification settings - Fork 143
/
setup.py
138 lines (115 loc) · 4.12 KB
/
setup.py
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
#!/usr/bin/env python
from distutils.core import setup, Extension
from distutils import log
import os
import subprocess
import sipdistutils
import sipconfig
cfg = sipconfig.Configuration()
pyqt_sip_dir = cfg.default_sip_dir
for p in (os.path.join(pyqt_sip_dir, "PyQt5"),
os.path.join(pyqt_sip_dir, "PyQt5-3"),
os.path.join(pyqt_sip_dir, "PyQt4"),
pyqt_sip_dir,
os.path.join(cfg.default_mod_dir, "PyQt5", "bindings")):
if os.path.exists(os.path.join(p, "QtCore", "QtCoremod.sip")):
pyqt_sip_dir = p
break
try:
import PyQt5
PyQt_Version = 'PyQt5'
except:
PyQt_Version = 'PyQt4'
include_dirs = ['src']
class build_pyqt_ext(sipdistutils.build_ext):
description = "Build a qhexedit PyQt extension."
user_options = sipdistutils.build_ext.user_options + [(
"required",
None,
"qhexedit is required (failure to build will raise an error)"
)]
boolean_options = sipdistutils.build_ext.boolean_options + ["required"]
def initialize_options(self):
sipdistutils.build_ext.initialize_options(self)
self.required = False
def finalize_options(self):
if PyQt_Version == 'PyQt5':
from PyQt5.QtCore import PYQT_CONFIGURATION
else:
from PyQt4.QtCore import PYQT_CONFIGURATION
sipdistutils.build_ext.finalize_options(self)
self.sip_opts = self.sip_opts + PYQT_CONFIGURATION['sip_flags'].split()
self.sip_opts.append('-I%s/%s' % (pyqt_sip_dir, PyQt_Version))
if self.required is not None:
self.required = True
def build_extension(self, ext):
cppsources = (s for s in ext.sources if s.endswith(".cpp"))
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
for source in cppsources:
header = source.replace(".cpp", ".h")
if os.path.exists(header):
moc_file = os.path.basename(header).replace(".h", ".moc")
call_arg = (
"moc",
"-o",
os.path.join(self.build_temp, moc_file),
header
)
log.info("Calling: " + " ".join(call_arg))
try:
subprocess.call(call_arg)
except OSError:
raise OSError(
"Could not locate 'moc' executable."
)
sipdistutils.build_ext.build_extension(self, ext)
def run(self):
try:
sipdistutils.build_ext.run(self)
except Exception as ex:
if self.required:
raise
else:
log.info("Could not build qhexedit extension (%r)\n"
"Skipping." % ex)
# For sipdistutils to find PyQt's .sip files
def _sip_sipfiles_dir(self):
return pyqt_sip_dir
# Used Qt libs
if PyQt_Version == 'PyQt5':
qt_libs = ["QtCore", "QtGui", "QtWidgets"]
else:
qt_libs = ["QtCore", "QtGui"]
if cfg.qt_framework:
for lib in qt_libs:
include_dirs += [os.path.join(cfg.qt_lib_dir,
lib + ".framework", "Headers")]
else:
if PyQt_Version == 'PyQt5':
for qt_inc_dir in ('/usr/include/qt', '/usr/include/x86_64-linux-gnu/qt5'):
include_dirs.append(qt_inc_dir)
include_dirs += [os.path.join(qt_inc_dir, lib) for lib in qt_libs]
libraries = ["Qt5" + lib[2:] for lib in qt_libs]
else:
for qt_inc_dir in ('/usr/include/qt', '/usr/include/qt4'):
include_dirs.append(qt_inc_dir)
include_dirs += [os.path.join(qt_inc_dir, lib) for lib in qt_libs]
libraries = ["Qt" + lib[2:] for lib in qt_libs]
libraries.append("qhexedit")
dirname = os.path.dirname(__file__)
setup(
name='QHexEdit',
version='0.8.9',
ext_modules=[
Extension(
"qhexedit",
sources=[
os.path.join(dirname, "src/qhexedit.sip"),
],
include_dirs=include_dirs,
libraries=libraries,
)
],
cmdclass={"build_ext": build_pyqt_ext},
)