changeset 40259:5519697b71b3

contrib: fix up output in check-config.py to use strs to avoid b prefixes Differential Revision: https://phab.mercurial-scm.org/D5059
author Augie Fackler <augie@google.com>
date Sat, 13 Oct 2018 05:14:21 -0400
parents 2f47703c5489
children b54d93fc3ba8
files contrib/check-config.py contrib/python3-whitelist
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-config.py	Sat Oct 13 08:54:31 2018 -0400
+++ b/contrib/check-config.py	Sat Oct 13 05:14:21 2018 -0400
@@ -42,6 +42,14 @@
     config:\s(?P<config>\S+\.\S+)$
     ''', re.VERBOSE | re.MULTILINE)
 
+if sys.version_info[0] > 2:
+    def mkstr(b):
+        if isinstance(b, str):
+            return b
+        return b.decode('utf8')
+else:
+    mkstr = lambda x: x
+
 def main(args):
     for f in args:
         sect = b''
@@ -92,7 +100,7 @@
             # look for ignore markers
             m = ignorere.search(l)
             if m:
-                if m.group('reason') == 'inconsistent':
+                if m.group('reason') == b'inconsistent':
                     allowinconsistent.add(m.group('config'))
                 else:
                     documented[m.group('config')] = 1
@@ -106,16 +114,20 @@
                     ctype = 'str'
                 name = m.group('section') + b"." + m.group('option')
                 default = m.group('default')
-                if default in (None, 'False', 'None', '0', '[]', '""', "''"):
+                if default in (
+                        None, b'False', b'None', b'0', b'[]', b'""', b"''"):
                     default = b''
                 if re.match(b'[a-z.]+$', default):
                     default = b'<variable>'
                 if (name in foundopts and (ctype, default) != foundopts[name]
                     and name not in allowinconsistent):
-                    print(l.rstrip())
-                    print("conflict on %s: %r != %r" % (name, (ctype, default),
-                                                        foundopts[name]))
-                    print("at %s:%d:" % (f, linenum))
+                    print(mkstr(l.rstrip()))
+                    fctype, fdefault = foundopts[name]
+                    print("conflict on %s: %r != %r" % (
+                        mkstr(name),
+                        (mkstr(ctype), mkstr(default)),
+                        (mkstr(fctype), mkstr(fdefault))))
+                    print("at %s:%d:" % (mkstr(f), linenum))
                 foundopts[name] = (ctype, default)
                 carryover = b''
             else:
@@ -132,8 +144,13 @@
                     name.startswith(b"debug.")):
                 ctype, default = foundopts[name]
                 if default:
+                    if isinstance(default, bytes):
+                        default = mkstr(default)
                     default = ' [%s]' % default
-                print("undocumented: %s (%s)%s" % (name, ctype, default))
+                elif isinstance(default, bytes):
+                    default = mkstr(default)
+                print("undocumented: %s (%s)%s" % (
+                    mkstr(name), mkstr(ctype), default))
 
 if __name__ == "__main__":
     if len(sys.argv) > 1:
--- a/contrib/python3-whitelist	Sat Oct 13 08:54:31 2018 -0400
+++ b/contrib/python3-whitelist	Sat Oct 13 05:14:21 2018 -0400
@@ -59,6 +59,7 @@
 test-changelog-exec.t
 test-check-code.t
 test-check-commit.t
+test-check-config.py
 test-check-execute.t
 test-check-interfaces.py
 test-check-module-imports.t