[elbe-devel] [PATCH] elbepack: don't transform all warnings into exceptions

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Feb 12 14:09:51 CET 2024


The calls to warnings.simplefilter() modify the global warning
configuration. Doing it at import-time and without
warnings.catch_warnings() means that this configuration is changed in
essentially unpredictable ways.

The call to `warnings.simplefilter('error')` transforms *all*
warnings for *all* modules into exceptions.
This breaks the initvm on bookworm as the six library used by the spyne
library triggers a warning on python3 which then crashes the
application [0].
The emitted warning however is completely harmless and even ignored in
the default configuration.

Instead change the configuration only in the narrow scope it is
necessary in.

[0] https://github.com/arskom/spyne/pull/704

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/licencexml.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/elbepack/licencexml.py b/elbepack/licencexml.py
index cd58bb231179..237c098aea8e 100644
--- a/elbepack/licencexml.py
+++ b/elbepack/licencexml.py
@@ -18,8 +18,6 @@ from debian.copyright import (
 
 from elbepack.treeutils import etree
 
-warnings.simplefilter('error')
-
 remove_re = re.compile('[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]')
 
 
@@ -69,13 +67,16 @@ class copyright_xml:
                                              .decode(encoding='utf-8',
                                                      errors='replace'))
         try:
-            c = Copyright(bytesio, strict=True)
+            with warnings.catch_warnings():
+                warnings.simplefilter('error')
+
+                c = Copyright(bytesio, strict=True)
 
-            files = []
+                files = []
 
-            # Note!  Getters of cc can throw nasty exceptions!
-            for cc in c.all_files_paragraphs():
-                files.append((cc.files, cc.license.synopsis, cc.copyright))
+                # Note!  Getters of cc can throw nasty exceptions!
+                for cc in c.all_files_paragraphs():
+                    files.append((cc.files, cc.license.synopsis, cc.copyright))
 
         except (NotMachineReadableError, MachineReadableFormatError, ValueError) as E:
             logging.warning("Error in copyright of package '%s': %s", pkg_name, E)
-- 
2.43.1



More information about the elbe-devel mailing list