]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Override sys.excepthook when calling main
authorGeorges Discry <georges@discry.be>
Thu, 20 Apr 2023 20:31:45 +0000 (22:31 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 21 Apr 2023 08:24:59 +0000 (10:24 +0200)
Overriding `sys.excepthook` with `mkosi.run.excepthook` has to happen
when calling `mkosi.__main__.main()`, otherwise it is not applied when
`main` is simply imported and then called (by using a zipapp or a
console script entry point).

mkosi/__main__.py

index 69c524f1109198fe3a82f2caf9aac1a2bd0698c4..9e4d1394c853bd4c39e42f3a075ebe2cb78ef789 100644 (file)
@@ -15,6 +15,8 @@ from mkosi.run import excepthook
 
 @contextlib.contextmanager
 def propagate_failed_return() -> Iterator[None]:
+    sys.excepthook = excepthook
+
     try:
         yield
     except SystemExit as e:
@@ -58,5 +60,4 @@ def main() -> None:
 
 
 if __name__ == "__main__":
-    sys.excepthook = excepthook
     main()