-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
init_env.py
194 lines (166 loc) · 5.04 KB
/
init_env.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import print_function
import json
import os
import re
import subprocess
import sys
from bypy.constants import (
LIBDIR, PREFIX, PYTHON, SRC as CALIBRE_DIR, build_dir, islinux, ismacos,
iswindows, worker_env
)
from bypy.utils import run_shell
dlls = [
'Core',
'Concurrent',
'Gui',
'Network',
# 'NetworkAuth',
'Location',
'PrintSupport',
'WebChannel',
# 'WebSockets',
# 'WebView',
'Positioning',
'PositioningQuick',
'Sensors',
'Sql',
'Svg',
'WebEngineCore',
'WebEngine',
'WebEngineWidgets',
'Widgets',
# 'Multimedia',
'OpenGL',
'Quick',
'QuickWidgets',
'Qml',
# 'MultimediaWidgets',
'Xml',
# 'XmlPatterns',
]
if islinux:
dlls += ['X11Extras', 'XcbQpa', 'WaylandClient', 'DBus']
elif ismacos:
dlls += ['MacExtras', 'DBus']
elif iswindows:
dlls += ['WinExtras']
QT_DLLS = frozenset(
'Qt5' + x for x in dlls
)
QT_PLUGINS = [
'imageformats',
'iconengines',
# 'mediaservice',
'platforms',
'platformthemes',
# 'playlistformats',
'sqldrivers',
# 'webview',
# 'audio', 'printsupport', 'bearer', 'position',
]
if islinux:
QT_PLUGINS += [
'platforminputcontexts',
'wayland-decoration-client',
'wayland-graphics-integration-client',
'wayland-shell-integration',
'xcbglintegrations',
]
else:
QT_PLUGINS.append('styles')
PYQT_MODULES = (
'Qt',
'QtCore',
'QtGui',
'QtNetwork',
# 'QtMultimedia', 'QtMultimediaWidgets',
'QtPrintSupport',
'QtSensors',
'QtSvg',
'QtWidgets',
'QtWebEngine',
'QtWebEngineCore',
'QtWebEngineWidgets',
'QtWebChannel',
)
del dlls
if iswindows:
PYQT_MODULES += ('QtWinExtras',)
def read_cal_file(name):
with open(os.path.join(CALIBRE_DIR, 'src', 'calibre', name), 'rb') as f:
return f.read().decode('utf-8')
def initialize_constants():
calibre_constants = {}
src = read_cal_file('constants.py')
nv = re.search(r'numeric_version\s+=\s+\((\d+), (\d+), (\d+)\)', src)
calibre_constants['version'
] = '%s.%s.%s' % (nv.group(1), nv.group(2), nv.group(3))
calibre_constants['appname'] = re.search(
r'__appname__\s+=\s+(u{0,1})[\'"]([^\'"]+)[\'"]', src
).group(2)
epsrc = re.compile(r'entry_points = (\{.*?\})',
re.DOTALL).search(read_cal_file('linux.py')).group(1)
entry_points = eval(epsrc, {'__appname__': calibre_constants['appname']})
def e2b(ep):
return re.search(r'\s*(.*?)\s*=', ep).group(1).strip()
def e2s(ep, base='src'):
return (
base + os.path.sep +
re.search(r'.*=\s*(.*?):', ep).group(1).replace('.', '/') + '.py'
).strip()
def e2m(ep):
return re.search(r'.*=\s*(.*?)\s*:', ep).group(1).strip()
def e2f(ep):
return ep[ep.rindex(':') + 1:].strip()
calibre_constants['basenames'] = basenames = {}
calibre_constants['functions'] = functions = {}
calibre_constants['modules'] = modules = {}
calibre_constants['scripts'] = scripts = {}
for x in ('console', 'gui'):
y = x + '_scripts'
basenames[x] = list(map(e2b, entry_points[y]))
functions[x] = list(map(e2f, entry_points[y]))
modules[x] = list(map(e2m, entry_points[y]))
scripts[x] = list(map(e2s, entry_points[y]))
src = read_cal_file('ebooks/__init__.py')
be = re.search(
r'^BOOK_EXTENSIONS\s*=\s*(\[.+?\])', src, flags=re.DOTALL | re.MULTILINE
).group(1)
calibre_constants['book_extensions'] = json.loads(be.replace("'", '"'))
return calibre_constants
def run(*args, **extra_env):
env = os.environ.copy()
env.update(worker_env)
env.update(extra_env)
env['SW'] = PREFIX
env['LD_LIBRARY_PATH'] = LIBDIR
env['SIP_BIN'] = os.path.join(PREFIX, 'bin', 'sip')
env['QMAKE'] = os.path.join(PREFIX, 'qt', 'bin', 'qmake')
return subprocess.call(list(args), env=env, cwd=CALIBRE_DIR)
def build_c_extensions(ext_dir, args):
bdir = os.path.join(build_dir(), 'calibre-extension-objects')
cmd = [
PYTHON, 'setup.py', 'build',
'--output-dir', ext_dir, '--build-dir', bdir,
]
if args.build_only:
cmd.extend(('--only', args.build_only))
if run(*cmd, COMPILER_CWD=bdir) != 0:
print('Building of calibre C extensions failed', file=sys.stderr)
os.chdir(CALIBRE_DIR)
run_shell()
raise SystemExit('Building of calibre C extensions failed')
return ext_dir
def run_tests(path_to_calibre_debug, cwd_on_failure):
ret = run(path_to_calibre_debug, '--test-build')
if ret != 0:
os.chdir(cwd_on_failure)
print(
'running calibre build tests failed with return code:', ret, 'and exe:', path_to_calibre_debug, file=sys.stderr)
run_shell()
raise SystemExit('running calibre build tests failed')
if __name__ == 'program':
calibre_constants = initialize_constants()