Repository navigation
Expand file tree
/
Copy pathfile_init.py
More file actions
768 lines (676 loc) · 26.3 KB
/
Copy pathfile_init.py
File metadata and controls
768 lines (676 loc) · 26.3 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
"""Plugin __init__.py file generation
"""
# Copyright (C) 2026 Bob Swift (rdswift)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <https://www.gnu.org/licenses/>.
# Code examples for the generated __init__.py file are based on the
# playgound / testing plugin by Philipp Wolfer.
#
# See https://git.sr.ht/~phw/picard-plugin-playground
from collections import (
OrderedDict,
namedtuple,
)
from picard.plugin3.api import (
PluginApi,
t_,
)
Include = namedtuple('Include', ['module', 'name'])
class CodeTemplate:
i18n_support: bool = False
includes: set[Include] = set()
def __init__(self) -> None:
pass
@classmethod
def i18n_block(cls) -> str:
return ''
@classmethod
def code_block(cls) -> str:
return ''
@classmethod
def registration_block(cls) -> str:
return ''
@classmethod
def set_i18n_support(cls, i18n_support: bool) -> None:
cls.i18n_support = i18n_support
class CodeMetadata(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='Album'),
Include(module='picard.plugin3.api', name='Metadata'),
Include(module='picard.plugin3.api', name='Track'),
Include(module='PyQt6', name='QtCore'),
}
@classmethod
def registration_block(cls) -> str:
return (
'\n'
' # Metadata processors\n'
' api.register_album_metadata_processor(album_metadata_processor)\n'
' api.register_track_metadata_processor(track_metadata_processor)\n'
)
@classmethod
def code_block(cls) -> str:
return (
'\n\n'
'def album_metadata_processor(\n'
' api: PluginApi,\n'
' album: Album,\n'
' metadata: Metadata,\n'
' release_node: dict,\n'
'):\n'
' logger = api.logger\n'
' logger.info("Album metadata processor called:")\n'
' logger.info(f"album: {album}")\n'
' logger.info(f"metadata: {metadata}")\n'
' logger.info(f"release_node: {release_node}")\n'
'\n'
" # Let's fake some work by artificially delaying the request\n"
' api.add_album_task(album, "playground_delay", "playground fake task")\n'
'\n'
' def callback() -> None:\n'
' logger.info(f"Album task finished for {album}.")\n'
'\n'
' QtCore.QTimer.singleShot(2000, callback)\n'
'\n\n'
'def track_metadata_processor(\n'
' api: PluginApi,\n'
' track: Track,\n'
' metadata: Metadata,\n'
' track_node: dict,\n'
' release_node: dict | None,\n'
'):\n'
' logger = api.logger\n'
' logger.info("Track metadata processor called:")\n'
' logger.info(f"track: {track}")\n'
' logger.info(f"metadata: {metadata}")\n'
' logger.info(f"track_node: {track_node}")\n'
' logger.info(f"release_node: {release_node}")\n'
)
class CodeAction(CodeTemplate):
includes = {
Include(module='PyQt6.QtWidgets', name='QMessageBox'),
Include(module='picard.plugin3.api', name='BaseAction'),
}
@classmethod
def registration_block(cls) -> str:
return (
'\n'
' # Menu actions\n'
' api.register_album_action(MyAction)\n'
' api.register_cluster_action(MyAction)\n'
' api.register_clusterlist_action(MyAction)\n'
' api.register_file_action(MyAction)\n'
' api.register_track_action(MyAction)\n'
' api.register_tools_menu_action(MyAction)\n'
)
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'class MyAction(BaseAction):\n'
)
if cls.i18n_support:
text += ' TITLE = t_("action.title", "Plugin action")\n'
else:
text += ' TITLE = "Plugin action"\n'
text += (
'\n'
' def callback(self, objs):\n'
' self.api.logger.info(f"Action called with {len(objs)} objects")\n'
' for obj in objs:\n'
' self.api.logger.info(str(obj))\n'
'\n'
' QMessageBox.information(\n'
' None,\n'
)
if cls.i18n_support:
text += (
' self.api.tr("action.dialog.title", "Plugin action"),\n'
' self.api.tr("action.dialog.text", "Action triggered"),\n'
)
else:
text += (
' "Plugin action",\n'
' "Action triggered",\n'
)
text += ' )\n'
return text
class CodeAlbumPostRemoval(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='Album'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # Album post-removal processor\n'
' api.register_album_post_removal_processor(album_post_removal_processor)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def album_post_removal_processor(api: PluginApi, album: Album):\n'
' api.logger.info(f"Album post removal processor: {album}")\n'
)
return text
class CodeFilePostLoad(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File post-load processor\n'
' api.register_file_post_load_processor(file_post_load_processor)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def file_post_load_processor(api: PluginApi, file: File):\n'
' api.logger.info(f"File post load processor: {file}")\n'
)
return text
class CodeFilePostAddToTrack(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
Include(module='picard.plugin3.api', name='Track'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File post add to track processor\n'
' api.register_file_post_addition_to_track_processor(\n'
' file_post_addition_to_track_processor\n'
' )\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def file_post_addition_to_track_processor(api: PluginApi, track: Track, file: File):\n'
' api.logger.info(f"File post addition to track processor: {track} <- {file}")\n'
)
return text
class CodeFilePostRemoveFromTrack(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
Include(module='picard.plugin3.api', name='Track'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File post remove from track processor\n'
' api.register_file_post_removal_from_track_processor(\n'
' file_post_removal_from_track_processor\n'
' )\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def file_post_removal_from_track_processor(api: PluginApi, track: Track, file: File):\n'
' api.logger.info(f"File post removal from track processor: {track} -> {file}")\n'
)
return text
class CodeFilePreSave(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File pre-save processor\n'
' api.register_file_pre_save_processor(file_pre_save_processor)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def file_pre_save_processor(api: PluginApi, file: File):\n'
' api.logger.info(f"File pre save processor: {file}")\n'
)
return text
class CodeFilePostSave(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File post-save processor\n'
' api.register_file_post_save_processor(file_post_save_processor)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def file_post_save_processor(api: PluginApi, file: File):\n'
' api.logger.info(f"File post save processor: {file}")\n'
)
return text
class CodeScriptFunctions(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='ScriptParser'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # Scripting functions\n'
' api.register_script_function(func_playground_version, "playground_version")\n'
' api.register_script_function(func_playground_one_arg, "playground_one_arg")\n'
' api.register_script_function(func_playground_two_args, "playground_two_args")\n'
' api.register_script_function(func_playground_variadic, "playground_variadic")\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'def func_playground_version(parser: ScriptParser) -> str:\n'
' api = PluginApi.get_api()\n'
' api.logger.info("Executed $playground_version()")\n'
' return f"{api.manifest.name()}: {api.manifest.version}"\n'
'\n\n'
'def func_playground_one_arg(parser: ScriptParser, arg1: str) -> str:\n'
' api = PluginApi.get_api()\n'
' api.logger.info(f"Executed $playground_test({arg1})")\n'
' return arg1.upper()\n'
'\n\n'
'def func_playground_two_args(parser: ScriptParser, arg1: str, arg2: str) -> str:\n'
' api = PluginApi.get_api()\n'
' api.logger.info(f"Executed $playground_test({arg1})")\n'
' return f"{arg1.upper()} & {arg2.lower()}"\n'
'\n\n'
'def func_playground_variadic(parser: ScriptParser, *args: str) -> str:\n'
' api = PluginApi.get_api()\n'
' api.logger.info(f"Executed $playground_test({\', \'.join(args)})")\n'
' return " & ".join(args)\n'
)
return text
class CodeScriptVariables(CodeTemplate):
includes = set()
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # Scripting variables\n'
' api.register_script_variable("playground", "Just a test tag / variable")\n'
' api.register_script_variable("_playground", "Just a test variable")\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = ''
return text
class CodeFileFormat(CodeTemplate):
includes = {
Include(module='picard.plugin3.api', name='File'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # File formats\n'
' api.register_format(MyFileFormat)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'class MyFileFormat(File):\n'
' EXTENSIONS = [".txt"]\n'
' NAME = "Text"\n'
'\n'
' @classmethod\n'
' def supports_tag(cls, name: str) -> bool:\n'
' return False\n'
'\n'
' def _load(self, filename: str) -> Metadata:\n'
' PluginApi.get_api().logger.info("Loading metadata from file %r", filename)\n'
' metadata = Metadata()\n'
' metadata["~format"] = self.NAME\n'
' return metadata\n'
'\n'
' def _save(self, filename: str, metadata: Metadata) -> None:\n'
' PluginApi.get_api().logger.info("Saving metadata to file %r", filename)\n'
)
return text
class CodeOptionsPage(CodeTemplate):
includes = {
Include(module='enum', name='Enum'),
Include(module='enum', name='auto'),
Include(module='picard.plugin3.api', name='OptionsPage'),
Include(module='.ui_options', name='Ui_PlaygroundOptionsPage'),
}
@classmethod
def registration_block(cls) -> str:
text = (
'\n'
' # Settings\n'
)
if cls.i18n_support:
text += (
' api.plugin_config.register_option(\n'
' "run_image_processor",\n'
' False,\n'
' title=api.tr("opt.title.run_image_processor", "Run image processor"),\n'
' in_profile=True,\n'
' )\n'
)
else:
text += (
' api.plugin_config.register_option("run_image_processor", False, title="Run image processor", in_profile=True)\n'
)
text += (
' api.plugin_config.register_option("my_choice", MyChoices.OPT2)\n'
'\n'
' api.logger.info(f"my_choice == {api.plugin_config[\'my_choice\']!r}")\n'
'\n'
' # Option page\n'
' api.register_options_page(MyOptionsPage)\n'
)
return text
@classmethod
def code_block(cls) -> str:
text = (
'\n\n'
'class MyChoices(Enum):\n'
' OPT1 = auto()\n'
' OPT2 = auto()\n'
' OPT3 = auto()\n'
'\n\n'
'class MyOptionsPage(OptionsPage):\n'
' # Identify the options managed by profiles, and the corresponding widgets to highlight.\n'
' OPTIONS = {\n'
' "run_image_processor": {"widgets": ["run_image_processor"]},\n'
' }\n'
'\n'
' def __init__(self, parent=None):\n'
' super().__init__(parent)\n'
' self.ui = Ui_PlaygroundOptionsPage()\n'
' self.ui.setupUi(self)\n'
'\n'
' def load(self):\n'
' self.ui.run_image_processor.setChecked(\n'
' bool(self.api.plugin_config["run_image_processor"])\n'
' )\n'
'\n'
' def save(self):\n'
' self.api.plugin_config["run_image_processor"] = (\n'
' self.ui.run_image_processor.isChecked()\n'
' )\n'
)
return text
CODE_BLOCKS = OrderedDict(
[
('metadata', {
'name': t_("code_block.metadata", "Album/Track metadata processing"),
'code_generator': CodeMetadata,
'tooltip': t_(
'ui.tooltip.code_template.metadata',
'Code template for the MusicBrainz metadata post-processor hook, including both Album and Track processing examples.',
),
}),
('action', {
'name': t_("code_block.action", "Menu item"),
'code_generator': CodeAction,
'tooltip': t_(
'ui.tooltip.code_template.action',
(
'Code template for the hook used to add right-click context menu actions for albums, tracks and files in '
"'Unmatched Files', 'Clusters' and the 'ClusterList' (parent folder of Clusters). Actions can also "
'be added to the main Picard menu bar.'
),
),
}),
('options', {
'name': t_("code_block.options", "Options page and settings"),
'code_generator': CodeOptionsPage,
'tooltip': t_(
'ui.tooltip.code_template.options',
'Code template for adding plugin-specific user settings and an options page for managing the settings.',
),
}),
('album_post_removal', {
'name': t_("code_block.album_post_removal", "Album post-removal processing"),
'code_generator': CodeAlbumPostRemoval,
'tooltip': t_(
'ui.tooltip.code_template.album_post_removal',
'Code template for the hook called after an album has been removed from Picard.',
),
}),
('file_post_load', {
'name': t_("code_block.file_post_load", "File post-load processing"),
'code_generator': CodeFilePostLoad,
'tooltip': t_(
'ui.tooltip.code_template.file_post_load',
(
'Code template for the hook called after a file has been loaded into Picard. This could for example '
'be used to load additional data for a file.'
),
),
}),
('file_post_add_track', {
'name': t_("code_block.file_post_add_track", "File post add to track processing"),
'code_generator': CodeFilePostAddToTrack,
'tooltip': t_(
'ui.tooltip.code_template.file_post_add_track',
'Code template for the hook called after a file has been added to a track (on the right-hand pane of Picard).',
),
}),
('file_post_remove_track', {
'name': t_("code_block.file_post_remove_track", "File post remove from track processing"),
'code_generator': CodeFilePostRemoveFromTrack,
'tooltip': t_(
'ui.tooltip.code_template.file_post_remove_track',
'Code template for the hook called after a file has been removed from a track (on the right-hand pane of Picard).',
),
}),
('file_pre_save', {
'name': t_("code_block.file_pre_save", "File pre-save processing"),
'code_generator': CodeFilePreSave,
'tooltip': t_(
'ui.tooltip.code_template.file_pre_save',
(
'Code template for the hook called before a file has been saved. This can for example be '
'used to run additional pre-processing on the file.'
),
),
}),
('file_post_save', {
'name': t_("code_block.file_post_save", "File post-save processing"),
'code_generator': CodeFilePostSave,
'tooltip': t_(
'ui.tooltip.code_template.file_post_save',
(
'Code template for the hook called after a file has been saved. This can for example be used '
"to run additional post-processing on the file or write extra data. Note that the file's "
'metadata is already the newly saved metadata.'
),
),
}),
('script_functions', {
'name': t_("code_block.script_functions", "Scripting functions"),
'code_generator': CodeScriptFunctions,
'tooltip': t_(
'ui.tooltip.code_template.script_functions',
(
'Code template for adding new scripting functions to Picard, including examples with varying '
'numbers of arguments. This provides the descriptions used in the scripting auto-completion '
'and documentation.'
),
),
}),
('script_variables', {
'name': t_("code_block.script_variables", "Scripting variables"),
'code_generator': CodeScriptVariables,
'tooltip': t_(
'ui.tooltip.code_template.script_variables',
(
'Code template for adding new scripting variables to Picard, used to describe the variables in '
'the scripting auto-completion and documentation. This is often used in conjunction with '
'metadata processors that create new variables.'
),
),
}),
('file_format', {
'name': t_("code_block.format", "File format"),
'code_generator': CodeFileFormat,
'tooltip': t_(
'ui.tooltip.code_template.file_format',
(
'Code template to extend Picard with support for additional file formats. See the existing file '
'format implementations for details on how to implement the _load and _save methods.'
),
),
}),
]
)
def generate_init(title: str, code_blocks: set[str], i18n_support: bool = False) -> str:
"""Generate the content for the __init__.py file.
Args:
title (str): Title of the plugin
code_blocks (set[str]): Code blocks to include.
i18n_support (bool, optional): Whether to include translation support in the template. Defaults to False.
Returns:
str: Content for the __init__.py file.
"""
includes = {'picard.plugin3.api': {'PluginApi'}} # PluginApi is always included
code_block = ""
registration_block = (
'\n\n'
'def enable(api: PluginApi) -> None:\n'
' """Called when the plugin is enabled.\n'
'\n'
' Use api to register plugin hooks and access essential Picard APIs.\n'
' """\n'
)
code_blocks_text = ""
api = PluginApi.get_api()
if i18n_support:
includes['picard.plugin3.api'].add('t_')
for block in sorted(code_blocks):
if block not in CODE_BLOCKS:
return f"Code block template '{block}' not found"
for key in CODE_BLOCKS.keys():
if key not in code_blocks:
continue
if not code_blocks_text:
code_blocks_text = "# Includes example code blocks:\n"
code_blocks_text += f"# * {api.tr(CODE_BLOCKS[key]['name'])}\n"
generator: CodeTemplate = CODE_BLOCKS[key]['code_generator']
generator.set_i18n_support(i18n_support)
code_block += generator.code_block()
registration_block += generator.registration_block()
for include in generator.includes:
if include.module not in includes:
includes[include.module] = set()
includes[include.module].add(include.name)
if not code_blocks_text:
code_blocks_text = "# Base template only. No specific code examples included.\n"
else:
code_blocks_text += (
'#\n'
"# Code examples provided by Philipp Wolfer\n"
"# See https://git.sr.ht/~phw/picard-plugin-playground\n"
)
if not code_block:
if i18n_support:
code_block = (
'\n'
'# Module-level translatable strings (resolved at runtime via api.tr)\n'
'GREETING = t_("message.greeting", "Hello from the plugin!")\n'
)
registration_block += (
'\n'
' # Translate a string at runtime\n'
' greeting = api.tr(GREETING, "Hello from the plugin!")\n'
)
else:
registration_block += (
'\n'
' greeting = "Hello from the plugin!"\n'
)
registration_block += ' api.logger.info(greeting)\n'
content = (
'"""Picard 3 Plugin Framework"""\n\n'
'# Automatically generated using "{title}"\n\n'
).format(title=title)
content += code_blocks_text + '\n' + _make_includes_block(includes) + code_block + registration_block
content += (
'\n\n'
'def disable() -> None:\n'
' """Called when the plugin is disabled."""\n'
' pass\n'
)
return content
def _make_includes_block(includes: dict[str, set[str]]) -> str:
"""Creates the 'includes' text block based on the items in the dictionary provided.
The output attempts to group and sort the included items by module name providing
the item to include. Multiple items from the same module are shown sorted in a
tuple, with each item on a separate line.
Args:
includes (dict[str, set[str]]): Dictionary of items to include. The key is the
module providing the included item, and the value is a set of the items to
include from the module.
Returns:
str: Text block of the includes for the plugin.
"""
includes_block = ''
old_module = ''
for key in sorted(includes.keys(), key=lambda x: import_level_sorter(x) + x):
if key:
first_module = key.split('.')[0]
if first_module != old_module:
includes_block += '\n'
old_module = first_module
includes_block += f"from {key} "
includes_block += "import "
names = sorted(includes[key])
if len(names) < 2:
includes_block += f"{names[0]}\n"
else:
includes_block += "(\n"
for name in names:
includes_block += f" {name},\n"
includes_block += ")\n"
return includes_block
def import_level_sorter(source_module: str) -> str:
"""Provides the block level for sorting the import modules.
Args:
source_module (str): The module name to sort.
Returns:
str: The block level.
"""
if source_module.startswith('.'):
return '9'
if source_module.startswith('picard'):
return '3'
if source_module.startswith('PyQt'):
return '2'
return '1'