Skip to contentSkip to conversation

oe/license: implement ast.NodeVisitor.visit_Constant

PATCH New Ross Burton 1 participant 2 messages Oct 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oe/license: implement ast.NodeVisitor.visit_Constant

Since Python 3.8 visit_Num(), visit_Str() and so on are all deprecated and replaced with visit_Constant. We can't yet remove the deprecated functions until we require 3.8, but we can implement visit_Constant to silence the deprecation warnings.

---
 meta/lib/oe/license.py | 6 ++++++
 1 file changed, 6 insertions(+)
meta/lib/oe/license.py +6 -0
index 665d32ecbb..b5d378a549 100644
@@ -74,6 +74,9 @@ class FlattenVisitor(LicenseVisitor):
     def visit_Str(self, node):
         self.licenses.append(node.s)
 
+    def visit_Constant(self, node):
+        self.licenses.append(node.value)
+
     def visit_BinOp(self, node):
         if isinstance(node.op, ast.BitOr):
             left = FlattenVisitor(self.choose_licenses)
@@ -227,6 +230,9 @@ class ListVisitor(LicenseVisitor):
     def visit_Str(self, node):
         self.licenses.add(node.s)
 
+    def visit_Constant(self, node):
+        self.licenses.add(node.value)
+
 def list_licenses(licensestr):
     """Simply get a list of all licenses mentioned in a license string.
        Binary operators are not applied or taken into account in any way"""
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 license.bbclass: implement ast.NodeVisitor.visit_Constant

Since Python 3.8 visit_Num(), visit_Str() and so on are all deprecated and replaced with visit_Constant. We can't yet remove the deprecated functions until we require 3.8, but we can implement visit_Constant to silence the deprecation warnings.

---
 meta/classes/license.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
meta/classes/license.bbclass +4 -0
index 45d912741d..7a34e185c7 100644
@@ -145,6 +145,10 @@ def find_license_files(d):
             find_license(node.s.replace("+", "").replace("*", ""))
             self.generic_visit(node)
 
+        def visit_Constant(self, node):
+            find_license(node.value.replace("+", "").replace("*", ""))
+            self.generic_visit(node)
+
     def find_license(license_type):
         try:
             bb.utils.mkdirhier(gen_lic_dest)
Signature · 1 line
2.25.1