forked from openstenoproject/plover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·291 lines (226 loc) · 7.55 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python3
# Copyright (c) 2010 Joshua Harlan Lifton.
# See LICENSE.txt for details.
import os
import re
import subprocess
import sys
from setuptools import setup
try:
from setuptools.extern.packaging.version import Version
except ImportError:
# Handle broken unvendored version of setuptools...
from packaging.version import Version
sys.path.insert(0, os.path.dirname(__file__))
__software_name__ = 'plover'
with open(os.path.join(__software_name__, '__init__.py')) as fp:
exec(fp.read())
from plover_build_utils.setup import (
BuildPy, BuildUi, Command, Develop, babel_options
)
BuildPy.build_dependencies.append('build_ui')
Develop.build_dependencies.append('build_py')
cmdclass = {
'build_py': BuildPy,
'build_ui': BuildUi,
'develop': Develop,
}
options = {}
PACKAGE = '%s-%s' % (
__software_name__,
__version__,
)
# Helpers. {{{
def get_version():
if not os.path.exists('.git'):
return None
version = subprocess.check_output('git describe --tags --match=v[0-9]*'.split()).strip().decode()
m = re.match(r'^v(\d[\d.]*(?:(?:\.dev|rc)\d+)?)(-\d+-g[a-f0-9]*)?$', version)
assert m is not None, version
version = m.group(1)
if m.group(2) is not None:
version += '+' + m.group(2)[1:].replace('-', '.')
return version
# }}}
# `bdist_win` command. {{{
class BinaryDistWin(Command):
description = 'create distribution(s) for MS Windows'
user_options = [
('trim', 't',
'trim the resulting distribution to reduce size'),
('zipdir', 'z',
'create a zip of the resulting directory'),
('installer', 'i',
'create an executable installer for the resulting distribution'),
('bash=', None,
'bash executable to use for running the build script'),
]
boolean_options = ['installer', 'trim', 'zipdir']
extra_args = []
def initialize_options(self):
self.bash = None
self.installer = False
self.trim = False
self.zipdir = False
def finalize_options(self):
pass
def run(self):
cmd = [self.bash or 'bash', 'windows/dist_build.sh']
if self.installer:
cmd.append('--installer')
if self.trim:
cmd.append('--trim')
if self.zipdir:
cmd.append('--zipdir')
cmd.extend((__software_name__, __version__, self.bdist_wheel()))
if self.verbose:
print('running', ' '.join(cmd))
subprocess.check_call(cmd)
if sys.platform.startswith('win32'):
cmdclass['bdist_win'] = BinaryDistWin
# }}}
# `launch` command. {{{
class Launch(Command):
description = 'run %s from source' % __software_name__.capitalize()
command_consumes_arguments = True
user_options = []
def initialize_options(self):
self.args = None
def finalize_options(self):
pass
def run(self):
with self.project_on_sys_path():
python_path = os.environ.get('PYTHONPATH', '').split(os.pathsep)
python_path.insert(0, sys.path[0])
os.environ['PYTHONPATH'] = os.pathsep.join(python_path)
cmd = [sys.executable, '-m', 'plover.scripts.main'] + self.args
if sys.platform.startswith('win32'):
# Workaround https://bugs.python.org/issue19066
subprocess.Popen(cmd, cwd=os.getcwd())
sys.exit(0)
os.execv(cmd[0], cmd)
cmdclass['launch'] = Launch
# }}}
# `patch_version` command. {{{
class PatchVersion(Command):
description = 'patch package version from VCS'
command_consumes_arguments = True
user_options = []
def initialize_options(self):
self.args = []
def finalize_options(self):
assert 0 <= len(self.args) <= 1
def run(self):
if self.args:
version = self.args[0]
# Ensure it's valid.
Version(version)
else:
version = get_version()
if version is None:
sys.exit(1)
if self.verbose:
print('patching version to', version)
version_file = os.path.join('plover', '__init__.py')
with open(version_file, 'r') as fp:
contents = fp.read().split('\n')
contents = [re.sub(r'^__version__ = .*$', "__version__ = '%s'" % version, line)
for line in contents]
with open(version_file, 'w') as fp:
fp.write('\n'.join(contents))
cmdclass['patch_version'] = PatchVersion
# }}}
# `bdist_app` and `bdist_dmg` commands. {{{
class BinaryDistApp(Command):
description = 'create an application bundle for Mac'
user_options = []
extra_args = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
cmd = ['bash', 'osx/make_app.sh', self.bdist_wheel()]
if self.verbose:
print('running', ' '.join(cmd))
subprocess.check_call(cmd)
class BinaryDistDmg(Command):
user_options = []
extra_args = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.run_command('bdist_app')
# Encode targeted macOS plaftorm in the filename.
from wheel.bdist_wheel import get_platform
platform = get_platform('dist/Plover.app')
args = '{out!r}, {name!r}, {settings!r}, lookForHiDPI=True'.format(
out='dist/%s-%s.dmg' % (PACKAGE, platform),
name=__software_name__.capitalize(),
settings='osx/dmg_resources/settings.py',
)
if self.verbose:
print('running dmgbuild(%s)' % args)
script = "__import__('dmgbuild').build_dmg(" + args + ')'
subprocess.check_call((sys.executable, '-u', '-c', script))
if sys.platform.startswith('darwin'):
cmdclass['bdist_app'] = BinaryDistApp
cmdclass['bdist_dmg'] = BinaryDistDmg
# }}}
# `bdist_appimage` command. {{{
class BinaryDistAppImage(Command):
description = 'create AppImage distribution for Linux'
user_options = [
('docker', None,
'use docker to run the build script'),
('no-update-tools', None,
'don\'t try to update AppImage tools, only fetch missing ones'),
]
boolean_options = ['docker', 'no-update-tools']
def initialize_options(self):
self.docker = False
self.no_update_tools = False
def finalize_options(self):
pass
def run(self):
cmd = ['./linux/appimage/build.sh']
if self.docker:
cmd.append('--docker')
else:
cmd.extend(('--python', sys.executable))
if self.no_update_tools:
cmd.append('--no-update-tools')
cmd.extend(('--wheel', self.bdist_wheel()))
if self.verbose:
print('running', ' '.join(cmd))
subprocess.check_call(cmd)
if sys.platform.startswith('linux'):
cmdclass['bdist_appimage'] = BinaryDistAppImage
# }}}
# i18n support. {{{
options.update(babel_options(__software_name__))
BuildPy.build_dependencies.append('compile_catalog')
BuildUi.hooks.append('plover_build_utils.pyqt:gettext')
# }}}
def reqs(name):
with open(os.path.join('reqs', name + '.txt')) as fp:
return fp.read()
setup(
name=__software_name__,
version=__version__,
description=__description__,
url=__url__,
download_url=__download_url__,
license=__license__,
options=options,
cmdclass=cmdclass,
install_requires=reqs('dist'),
extras_require={
'gui_qt': reqs('dist_extra_gui_qt'),
'log': reqs('dist_extra_log'),
},
tests_require=reqs('test'),
)
# vim: foldmethod=marker