Skip to contentSkip to conversation

bitbake: enable python warnings at the first opportunity

PATCH New Alexander Kanavin 1 participant 7 messages Sep 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 bitbake: enable python warnings at the first opportunity

We really do want to see those, as they tend to turn into hard errors eventually, as what happened with collections vs collections.abc in python 3.10.

---
 bitbake/bin/bitbake             | 2 ++
 bitbake/bin/bitbake-diffsigs    | 1 +
 bitbake/bin/bitbake-getvar      | 2 ++
 bitbake/bin/bitbake-hashclient  | 2 ++
 bitbake/bin/bitbake-hashserv    | 2 ++
 bitbake/bin/bitbake-layers      | 2 ++
 bitbake/bin/bitbake-prserv      | 2 ++
 bitbake/bin/bitbake-selftest    | 2 ++
 bitbake/bin/bitbake-server      | 1 +
 bitbake/bin/bitbake-worker      | 1 +
 bitbake/bin/git-make-shallow    | 2 ++
 bitbake/bin/toaster-eventreplay | 2 ++
 12 files changed, 21 insertions(+)
bitbake/bin/bitbake +2 -0
index dc1873af69c..d3ee8e9464b 100755
@@ -12,6 +12,8 @@
 
 import os
 import sys
+import warnings
+warnings.simplefilter("default")
 
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                 'lib'))
bitbake/bin/bitbake-diffsigs +1 -0
index 19420a2df69..6646dccdfa2 100755
@@ -11,6 +11,7 @@
 import os
 import sys
 import warnings
+warnings.simplefilter("default")
 import argparse
 import logging
 import pickle
bitbake/bin/bitbake-getvar +2 -0
index 94232192531..5435a8d7978 100755
@@ -9,6 +9,8 @@ import argparse
 import io
 import os
 import sys
+import warnings
+warnings.simplefilter("default")
 
 bindir = os.path.dirname(__file__)
 topdir = os.path.dirname(bindir)
bitbake/bin/bitbake-hashclient +2 -0
index a89290217b0..494f17592ac 100755
@@ -13,6 +13,8 @@ import pprint
 import sys
 import threading
 import time
+import warnings
+warnings.simplefilter("default")
 
 try:
     import tqdm
bitbake/bin/bitbake-hashserv +2 -0
index 153f65a3787..00af76b2d11 100755
@@ -10,6 +10,8 @@ import sys
 import logging
 import argparse
 import sqlite3
+import warnings
+warnings.simplefilter("default")
 
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
 
bitbake/bin/bitbake-layers +2 -0
index ff085d67442..449434d468e 100755
@@ -14,6 +14,8 @@ import logging
 import os
 import sys
 import argparse
+import warnings
+warnings.simplefilter("default")
 
 bindir = os.path.dirname(__file__)
 topdir = os.path.dirname(bindir)
bitbake/bin/bitbake-prserv +2 -0
index bef5ef68978..323df66dd06 100755
@@ -6,6 +6,8 @@
 import os
 import sys,logging
 import optparse
+import warnings
+warnings.simplefilter("default")
 
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib'))
 
bitbake/bin/bitbake-selftest +2 -0
index aec47069216..f25f23b1ae7 100755
@@ -7,6 +7,8 @@
 
 import os
 import sys, logging
+import warnings
+warnings.simplefilter("default")
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
 
 import unittest
bitbake/bin/bitbake-server +1 -0
index 8e539473614..f53f88b6b0d 100755
@@ -8,6 +8,7 @@
 import os
 import sys
 import warnings
+warnings.simplefilter("default")
 import logging
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
 
bitbake/bin/bitbake-worker +1 -0
index 3ca8c1853bb..6ead2da6d1e 100755
@@ -6,6 +6,7 @@
 import os
 import sys
 import warnings
+warnings.simplefilter("default")
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
 from bb import fetch2
 import logging
bitbake/bin/git-make-shallow +2 -0
index 57069f7edf7..1d00fbf1838 100755
@@ -16,6 +16,8 @@ import itertools
 import os
 import subprocess
 import sys
+import warnings
+warnings.simplefilter("default")
 
 version = 1.0
 
bitbake/bin/toaster-eventreplay +2 -0
index 8fa4ab7116b..404b61f5162 100755
@@ -19,6 +19,8 @@ import sys
 import json
 import pickle
 import codecs
+import warnings
+warnings.simplefilter("default")
 
 from collections import namedtuple
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/7 bitbake: drop old rules for python warnings

These no longer even work, and it's much better to just see all warnings and fix them as they happen.

---
 bitbake/lib/bb/main.py | 7 -------
 1 file changed, 7 deletions(-)
bitbake/lib/bb/main.py +0 -7
index 06bad495acf..639fc1885db 100755
@@ -112,13 +112,6 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
         warnlog.warning(s)
 
 warnings.showwarning = _showwarning
-warnings.filterwarnings("ignore")
-warnings.filterwarnings("default", module="(<string>$|(oe|bb)\.)")
-warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
-warnings.filterwarnings("ignore", category=ImportWarning)
-warnings.filterwarnings("ignore", category=DeprecationWarning, module="<string>$")
-warnings.filterwarnings("ignore", message="With-statements now directly support multiple context managers")
-
 
 def create_bitbake_parser():
     parser = optparse.OptionParser(
Signature · 1 line
2.20.1
#2 lore raw

PATCH 3/7 bitbake: correct the collections vs collections.abc deprecation

In reply to Alexander Kanavin

This becomes a hard error in python 3.10.

---
 bitbake/lib/bb/cache.py        | 3 ++-
 bitbake/lib/bb/data_smart.py   | 2 +-
 bitbake/lib/bb/persist_data.py | 5 +++--
 3 files changed, 6 insertions(+), 4 deletions(-)
bitbake/lib/bb/cache.py +2 -1
index 73bc6e96656..4e08c100ab2 100644
@@ -19,7 +19,8 @@
 import os
 import logging
 import pickle
-from collections import defaultdict, Mapping
+from collections import defaultdict
+from collections.abc import Mapping
 import bb.utils
 from bb import PrefixLoggerAdapter
 import re
bitbake/lib/bb/data_smart.py +1 -1
index e4afac64b20..73e33ee10ec 100644
@@ -17,7 +17,7 @@ BitBake build tools.
 # Based on functions from the base bb module, Copyright 2003 Holger Schurig
 
 import copy, re, sys, traceback
-from collections import MutableMapping
+from collections.abc import MutableMapping
 import logging
 import hashlib
 import bb, bb.codeparser
bitbake/lib/bb/persist_data.py +3 -2
index 286cc0a99d1..49c9a0d5109 100644
@@ -12,13 +12,14 @@ currently, providing a key/value store accessed by 'domain'.
 #
 
 import collections
+import collections.abc
 import contextlib
 import functools
 import logging
 import os.path
 import sqlite3
 import sys
-from collections import Mapping
+from collections.abc import Mapping
 
 sqlversion = sqlite3.sqlite_version_info
 if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3):
@@ -28,7 +29,7 @@ if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3):
 logger = logging.getLogger("BitBake.PersistData")
 
 @functools.total_ordering
-class SQLTable(collections.MutableMapping):
+class SQLTable(collections.abc.MutableMapping):
     class _Decorators(object):
         @staticmethod
         def retry(*, reconnect=True):
Signature · 1 line
2.20.1
#3 lore raw

PATCH 4/7 bitbake: fix regexp deprecation warnings

In reply to Alexander Kanavin

See here for details:
https://docs.python.org/3/library/re.html

---
 bitbake/lib/bblayers/query.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
bitbake/lib/bblayers/query.py +3 -3
index 6e94c83076c..525d4f0d476 100644
@@ -441,10 +441,10 @@ NOTE: .bbappend files can impact the dependencies.
                     line = fnfile.readline()
 
         # The "require/include xxx" in conf/machine/*.conf, .inc and .bbclass
-        conf_re = re.compile(".*/conf/machine/[^\/]*\.conf$")
-        inc_re = re.compile(".*\.inc$")
+        conf_re = re.compile(r".*/conf/machine/[^\/]*\.conf$")
+        inc_re = re.compile(r".*\.inc$")
         # The "inherit xxx" in .bbclass
-        bbclass_re = re.compile(".*\.bbclass$")
+        bbclass_re = re.compile(r".*\.bbclass$")
         for layerdir in self.bblayers:
             layername = self.get_layer_name(layerdir)
             for dirpath, dirnames, filenames in os.walk(layerdir):
Signature · 1 line
2.20.1
#4 lore raw

PATCH 5/7 bitbake: do not import imp in layerindexlib

In reply to Alexander Kanavin

The module is deprecated and unused.

---
 bitbake/lib/layerindexlib/__init__.py | 1 -
 1 file changed, 1 deletion(-)
bitbake/lib/layerindexlib/__init__.py +0 -1
index 9ca127b9df0..3159bf2f668 100644
@@ -6,7 +6,6 @@
 import datetime
 
 import logging
-import imp
 import os
 
 from collections import OrderedDict
Signature · 1 line
2.20.1
#5 lore raw

PATCH 6/7 bitbake: adjust parser error check for python 3.10 compatibility

In reply to Alexander Kanavin

The change was introduced in
https://github.com/python/cpython/commit/a698d52c3975c80b45b139b2f08402ec514dce75

---
 bitbake/lib/bb/data_smart.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/data_smart.py +1 -1
index 73e33ee10ec..ec7bb561ccd 100644
@@ -409,7 +409,7 @@ class DataSmart(MutableMapping):
                     s = __expand_python_regexp__.sub(varparse.python_sub, s)
                 except SyntaxError as e:
                     # Likely unmatched brackets, just don't expand the expression
-                    if e.msg != "EOL while scanning string literal":
+                    if e.msg != "EOL while scanning string literal" and not e.msg.startswith("unterminated string literal"):
                         raise
                 if s == olds:
                     break
Signature · 1 line
2.20.1
#6 lore raw

PATCH 7/7 bitbake: correct deprecation warning in process.py

In reply to Alexander Kanavin
---
 bitbake/lib/bb/server/process.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/server/process.py +1 -1
index b593830cc74..8fdcc66dc77 100644
@@ -661,7 +661,7 @@ class BBUIEventQueue:
         self.reader = ConnectionReader(readfd)
 
         self.t = threading.Thread()
-        self.t.setDaemon(True)
+        self.t.daemon = True
         self.t.run = self.startCallbackHandler
         self.t.start()
 
Signature · 1 line
2.20.1