Coverage for self-hosting-plugins/debputy_self_hosting.py: 73%
13 statements
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
1import textwrap
3from debputy.plugin.api import (
4 DebputyPluginInitializer,
5 VirtualPath,
6 BinaryCtrlAccessor,
7 PackageProcessingContext,
8)
9from debputy.util import POSTINST_DEFAULT_CONDITION
12def _maintscript_generator(
13 _path: VirtualPath,
14 ctrl: BinaryCtrlAccessor,
15 context: PackageProcessingContext,
16) -> None:
17 maintscript = ctrl.maintscript
19 # When `debputy` becomes a stand-alone package, it should have these maintscripts instead of dh-debputy
20 # Admittedly, I hope to get rid of this plugin before then, but ...
21 assert context.binary_package.name != "debputy", "Update the self-hosting plugin"
22 dirname = "/usr/share/debputy"
24 if context.binary_package.name == "dh-debputy": 24 ↛ 25line 24 didn't jump to line 25 because the condition on line 24 was never true
25 ctrl.dpkg_trigger("interest-noawait", dirname)
26 maintscript.unconditionally_in_script(
27 "postinst",
28 textwrap.dedent(
29 f"""\
30 \
31 if {POSTINST_DEFAULT_CONDITION} || [ "$1" = "triggered" ] ; then
32 # Ensure all plugins are byte-compiled (plus uninstalled plugins are cleaned up)
33 py3clean {dirname}
34 if command -v py3compile >/dev/null 2>&1; then
35 py3compile {dirname}
36 fi
37 if command -v pypy3compile >/dev/null 2>&1; then
38 pypy3compile {dirname} || true
39 fi
40 fi
41 """
42 ),
43 )
44 maintscript.unconditionally_in_script(
45 "prerm",
46 textwrap.dedent(
47 f"""\
48 \
49 if command -v py3clean >/dev/null 2>&1; then
50 py3clean {dirname}
51 else
52 find {dirname}/ -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
53 fi
54 """
55 ),
56 )
59def initializer(api: DebputyPluginInitializer) -> None:
60 api.metadata_or_maintscript_detector(
61 "debputy-self-hosting",
62 _maintscript_generator,
63 )