contrib/check-config.py
changeset 43076 2372284d9457
parent 41541 595a67a301ee
child 45830 c102b704edb5
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    13 
    13 
    14 foundopts = {}
    14 foundopts = {}
    15 documented = {}
    15 documented = {}
    16 allowinconsistent = set()
    16 allowinconsistent = set()
    17 
    17 
    18 configre = re.compile(br'''
    18 configre = re.compile(
       
    19     br'''
    19     # Function call
    20     # Function call
    20     ui\.config(?P<ctype>|int|bool|list)\(
    21     ui\.config(?P<ctype>|int|bool|list)\(
    21         # First argument.
    22         # First argument.
    22         ['"](?P<section>\S+)['"],\s*
    23         ['"](?P<section>\S+)['"],\s*
    23         # Second argument
    24         # Second argument
    24         ['"](?P<option>\S+)['"](,\s+
    25         ['"](?P<option>\S+)['"](,\s+
    25         (?:default=)?(?P<default>\S+?))?
    26         (?:default=)?(?P<default>\S+?))?
    26     \)''', re.VERBOSE | re.MULTILINE)
    27     \)''',
       
    28     re.VERBOSE | re.MULTILINE,
       
    29 )
    27 
    30 
    28 configwithre = re.compile(br'''
    31 configwithre = re.compile(
       
    32     br'''
    29     ui\.config(?P<ctype>with)\(
    33     ui\.config(?P<ctype>with)\(
    30         # First argument is callback function. This doesn't parse robustly
    34         # First argument is callback function. This doesn't parse robustly
    31         # if it is e.g. a function call.
    35         # if it is e.g. a function call.
    32         [^,]+,\s*
    36         [^,]+,\s*
    33         ['"](?P<section>\S+)['"],\s*
    37         ['"](?P<section>\S+)['"],\s*
    34         ['"](?P<option>\S+)['"](,\s+
    38         ['"](?P<option>\S+)['"](,\s+
    35         (?:default=)?(?P<default>\S+?))?
    39         (?:default=)?(?P<default>\S+?))?
    36     \)''', re.VERBOSE | re.MULTILINE)
    40     \)''',
       
    41     re.VERBOSE | re.MULTILINE,
       
    42 )
    37 
    43 
    38 configpartialre = (br"""ui\.config""")
    44 configpartialre = br"""ui\.config"""
    39 
    45 
    40 ignorere = re.compile(br'''
    46 ignorere = re.compile(
       
    47     br'''
    41     \#\s(?P<reason>internal|experimental|deprecated|developer|inconsistent)\s
    48     \#\s(?P<reason>internal|experimental|deprecated|developer|inconsistent)\s
    42     config:\s(?P<config>\S+\.\S+)$
    49     config:\s(?P<config>\S+\.\S+)$
    43     ''', re.VERBOSE | re.MULTILINE)
    50     ''',
       
    51     re.VERBOSE | re.MULTILINE,
       
    52 )
    44 
    53 
    45 if sys.version_info[0] > 2:
    54 if sys.version_info[0] > 2:
       
    55 
    46     def mkstr(b):
    56     def mkstr(b):
    47         if isinstance(b, str):
    57         if isinstance(b, str):
    48             return b
    58             return b
    49         return b.decode('utf8')
    59         return b.decode('utf8')
       
    60 
       
    61 
    50 else:
    62 else:
    51     mkstr = lambda x: x
    63     mkstr = lambda x: x
       
    64 
    52 
    65 
    53 def main(args):
    66 def main(args):
    54     for f in args:
    67     for f in args:
    55         sect = b''
    68         sect = b''
    56         prevname = b''
    69         prevname = b''
   113                 if not ctype:
   126                 if not ctype:
   114                     ctype = 'str'
   127                     ctype = 'str'
   115                 name = m.group('section') + b"." + m.group('option')
   128                 name = m.group('section') + b"." + m.group('option')
   116                 default = m.group('default')
   129                 default = m.group('default')
   117                 if default in (
   130                 if default in (
   118                         None, b'False', b'None', b'0', b'[]', b'""', b"''"):
   131                     None,
       
   132                     b'False',
       
   133                     b'None',
       
   134                     b'0',
       
   135                     b'[]',
       
   136                     b'""',
       
   137                     b"''",
       
   138                 ):
   119                     default = b''
   139                     default = b''
   120                 if re.match(b'[a-z.]+$', default):
   140                 if re.match(b'[a-z.]+$', default):
   121                     default = b'<variable>'
   141                     default = b'<variable>'
   122                 if (name in foundopts and (ctype, default) != foundopts[name]
   142                 if (
   123                     and name not in allowinconsistent):
   143                     name in foundopts
       
   144                     and (ctype, default) != foundopts[name]
       
   145                     and name not in allowinconsistent
       
   146                 ):
   124                     print(mkstr(l.rstrip()))
   147                     print(mkstr(l.rstrip()))
   125                     fctype, fdefault = foundopts[name]
   148                     fctype, fdefault = foundopts[name]
   126                     print("conflict on %s: %r != %r" % (
   149                     print(
   127                         mkstr(name),
   150                         "conflict on %s: %r != %r"
   128                         (mkstr(ctype), mkstr(default)),
   151                         % (
   129                         (mkstr(fctype), mkstr(fdefault))))
   152                             mkstr(name),
       
   153                             (mkstr(ctype), mkstr(default)),
       
   154                             (mkstr(fctype), mkstr(fdefault)),
       
   155                         )
       
   156                     )
   130                     print("at %s:%d:" % (mkstr(f), linenum))
   157                     print("at %s:%d:" % (mkstr(f), linenum))
   131                 foundopts[name] = (ctype, default)
   158                 foundopts[name] = (ctype, default)
   132                 carryover = b''
   159                 carryover = b''
   133             else:
   160             else:
   134                 m = re.search(configpartialre, line)
   161                 m = re.search(configpartialre, line)
   137                 else:
   164                 else:
   138                     carryover = b''
   165                     carryover = b''
   139 
   166 
   140     for name in sorted(foundopts):
   167     for name in sorted(foundopts):
   141         if name not in documented:
   168         if name not in documented:
   142             if not (name.startswith(b"devel.") or
   169             if not (
   143                     name.startswith(b"experimental.") or
   170                 name.startswith(b"devel.")
   144                     name.startswith(b"debug.")):
   171                 or name.startswith(b"experimental.")
       
   172                 or name.startswith(b"debug.")
       
   173             ):
   145                 ctype, default = foundopts[name]
   174                 ctype, default = foundopts[name]
   146                 if default:
   175                 if default:
   147                     if isinstance(default, bytes):
   176                     if isinstance(default, bytes):
   148                         default = mkstr(default)
   177                         default = mkstr(default)
   149                     default = ' [%s]' % default
   178                     default = ' [%s]' % default
   150                 elif isinstance(default, bytes):
   179                 elif isinstance(default, bytes):
   151                     default = mkstr(default)
   180                     default = mkstr(default)
   152                 print("undocumented: %s (%s)%s" % (
   181                 print(
   153                     mkstr(name), mkstr(ctype), default))
   182                     "undocumented: %s (%s)%s"
       
   183                     % (mkstr(name), mkstr(ctype), default)
       
   184                 )
       
   185 
   154 
   186 
   155 if __name__ == "__main__":
   187 if __name__ == "__main__":
   156     if len(sys.argv) > 1:
   188     if len(sys.argv) > 1:
   157         sys.exit(main(sys.argv[1:]))
   189         sys.exit(main(sys.argv[1:]))
   158     else:
   190     else: