entrypoints.py
7.1 KB
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
292
293
294
295
import os
import pathlib
import shutil
import subprocess
import sys
import sysconfig
import click
import dotenv
from . import _import_it
from . import major
PyQt = _import_it('PyQt')
qt_tools = _import_it('qt_tools')
pyqt_plugins = _import_it('pyqt_plugins')
_import_it('pyqt_plugins', 'utilities')
_import_it('pyqt_plugins', 'badplugin')
_import_it('pyqt_plugins', 'examplebuttonplugin')
_import_it('pyqt_plugins', 'examples')
_import_it('pyqt_plugins', 'examples', 'exampleqmlitem')
_import_it('pyqt_plugins', 'tests', 'testbutton')
here = pathlib.Path(__file__).parent
example_path = str(
pathlib.Path(pyqt_plugins.examplebuttonplugin.__file__).parent,
)
bad_path = str(
pathlib.Path(pyqt_plugins.badplugin.__file__).parent,
)
pyqt_root = pathlib.Path(PyQt.__file__).parent
maybe_extension = {
'linux': lambda name: name,
'win32': lambda name: '{}.exe'.format(name),
'darwin': lambda name: name,
}[sys.platform]
def load_dotenv():
env_path = dotenv.find_dotenv(usecwd=True)
if len(env_path) == 0:
return
os.environ['DOT_ENV_DIRECTORY'] = pyqt_plugins.utilities.fspath(
pathlib.Path(env_path).parent,
)
os.environ['SITE_PACKAGES'] = sysconfig.get_path('platlib')
dotenv.load_dotenv(dotenv_path=env_path, interpolate=True, override=True)
@click.group()
def main():
pass
@main.command()
def installuic():
destination = qt_tools.bin_path()
scripts_path = pathlib.Path(sysconfig.get_path("scripts"))
shutil.copy(
src=pyqt_plugins.utilities.fspath(
scripts_path.joinpath(maybe_extension('pyuic{}'.format(major))),
),
dst=pyqt_plugins.utilities.fspath(
destination.joinpath(maybe_extension('uic')),
),
)
qt_debug_plugins_option = click.option(
'--qt-debug-plugins/--no-qt-debug-plugins',
help='Set QT_DEBUG_PLUGINS=1',
)
@main.command(
context_settings={
'ignore_unknown_options': True,
'allow_extra_args': True,
},
)
@click.pass_context
@click.option(
'--widget-path',
'-p',
'widget_paths',
help='Paths to be combined with PYQTDESIGNERPATH',
type=click.Path(exists=True, file_okay=False, resolve_path=True),
multiple=True,
)
@click.option(
'--example-widget-path',
help='Include the path for the pyqt{major}-tools example button ({path})'.format(
major=major,
path=example_path,
),
is_flag=True,
)
@click.option(
'--designer-help',
help='Pass through to get Designer\'s --help',
is_flag=True,
)
@click.option(
'--test-exception-dialog',
help='Raise an exception to check the exception dialog functionality.',
is_flag=True,
)
@qt_debug_plugins_option
def designer(
ctx,
widget_paths,
designer_help,
example_widget_path,
test_exception_dialog,
qt_debug_plugins
):
# here for now at least since it still mutates
load_dotenv()
env = pyqt_plugins.create_environment(reference=os.environ)
extras = []
widget_paths = list(widget_paths)
if designer_help:
extras.append('--help')
if example_widget_path:
widget_paths.append(example_path)
if test_exception_dialog:
widget_paths.append(bad_path)
env.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=env,
name='PYQTDESIGNERPATH',
before=widget_paths,
after=[''],
))
if qt_debug_plugins:
env['QT_DEBUG_PLUGINS'] = '1'
pyqt_plugins.utilities.print_environment_variables(
env,
*pyqt_plugins.utilities.diagnostic_variables_to_print,
)
command_elements = qt_tools.create_command_elements(
name='designer',
sys_platform=sys.platform,
)
command = [*command_elements, *extras, *ctx.args]
return subprocess.call(command, env=env)
qml2_import_path_option = click.option(
'--qml2-import-path',
'-p',
'qml2_import_paths',
help='Paths to be combined with QML2_IMPORT_PATH',
type=click.Path(exists=True, file_okay=False, resolve_path=True),
multiple=True,
)
@main.command(
context_settings={
'ignore_unknown_options': True,
'allow_extra_args': True,
},
)
@click.pass_context
@qml2_import_path_option
@click.option(
'--qmlscene-help',
help='Pass through to get QML scene\'s --help',
is_flag=True,
)
@qt_debug_plugins_option
@click.option(
'--run-qml-example',
help='Run the pyqt{major}-tools QML example'.format(major=major),
is_flag=True,
)
def qmlscene(
ctx,
qml2_import_paths,
qmlscene_help,
qt_debug_plugins,
run_qml_example,
):
# here for now at least since it still mutates
load_dotenv()
env = pyqt_plugins.create_environment(os.environ)
extras = []
if qmlscene_help:
extras.append('--help')
if run_qml_example:
qml2_import_paths = qml2_import_paths + (pyqt_plugins.utilities.fspath(here),)
extras.append(pyqt_plugins.utilities.fspath(
pathlib.Path(pyqt_plugins.examples.__file__).parent / 'qmlapp.qml'
))
pyqt_plugins.utilities.mutate_qml_path(env, paths=qml2_import_paths)
if qt_debug_plugins:
env['QT_DEBUG_PLUGINS'] = '1'
pyqt_plugins.utilities.print_environment_variables(
env,
*pyqt_plugins.utilities.diagnostic_variables_to_print,
)
command_elements = qt_tools.create_command_elements(
name='qmlscene',
sys_platform=sys.platform,
)
command = [*command_elements, *extras, *ctx.args]
return subprocess.call(command, env=env)
@main.command(
context_settings={
'ignore_unknown_options': True,
'allow_extra_args': True,
},
)
@click.pass_context
@qml2_import_path_option
@click.option(
'--qmltestrunner-help',
help='Pass through to get QML test runner\'s --help',
is_flag=True,
)
@qt_debug_plugins_option
@click.option(
'--test-qml-example',
help='Test the pyqt{major}-tools QML example'.format(major=major),
is_flag=True,
)
def qmltestrunner(
ctx,
qml2_import_paths,
qmltestrunner_help,
qt_debug_plugins,
test_qml_example,
):
# here for now at least since it still mutates
load_dotenv()
env = pyqt_plugins.create_environment(os.environ)
extras = []
if qmltestrunner_help:
extras.append('--help')
if test_qml_example:
qml2_import_paths = qml2_import_paths + (pyqt_plugins.utilities.fspath(here),)
extras.extend([
'-input',
pyqt_plugins.utilities.fspath(
pathlib.Path(pyqt_plugins.examples.__file__).parent / 'qmltest.qml'
),
])
pyqt_plugins.utilities.mutate_qml_path(env, paths=qml2_import_paths)
if qt_debug_plugins:
env['QT_DEBUG_PLUGINS'] = '1'
pyqt_plugins.utilities.print_environment_variables(
env,
*pyqt_plugins.utilities.diagnostic_variables_to_print,
)
command_elements = qt_tools.create_command_elements(
name='qmltestrunner',
sys_platform=sys.platform,
)
command = [*command_elements, *extras, *ctx.args]
return subprocess.call(command, env=env)