tests/check-perf-code.py
changeset 43076 2372284d9457
parent 42138 caebe5e7f4bd
child 45830 c102b704edb5
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
     7 import os
     7 import os
     8 import sys
     8 import sys
     9 
     9 
    10 # write static check patterns here
    10 # write static check patterns here
    11 perfpypats = [
    11 perfpypats = [
    12   [
    12     [
    13     (r'(branchmap|repoview|repoviewutil)\.subsettable',
    13         (
    14      "use getbranchmapsubsettable() for early Mercurial"),
    14             r'(branchmap|repoview|repoviewutil)\.subsettable',
    15     (r'\.(vfs|svfs|opener|sopener)',
    15             "use getbranchmapsubsettable() for early Mercurial",
    16      "use getvfs()/getsvfs() for early Mercurial"),
    16         ),
    17     (r'ui\.configint',
    17         (
    18      "use getint() instead of ui.configint() for early Mercurial"),
    18             r'\.(vfs|svfs|opener|sopener)',
    19   ],
    19             "use getvfs()/getsvfs() for early Mercurial",
    20   # warnings
    20         ),
    21   [
    21         (
    22   ]
    22             r'ui\.configint',
       
    23             "use getint() instead of ui.configint() for early Mercurial",
       
    24         ),
       
    25     ],
       
    26     # warnings
       
    27     [],
    23 ]
    28 ]
    24 
    29 
       
    30 
    25 def modulewhitelist(names):
    31 def modulewhitelist(names):
    26     replacement = [('.py', ''), ('.c', ''), # trim suffix
    32     replacement = [
    27                    ('mercurial%s' % ('/'), ''), # trim "mercurial/" path
    33         ('.py', ''),
    28                   ]
    34         ('.c', ''),  # trim suffix
       
    35         ('mercurial%s' % '/', ''),  # trim "mercurial/" path
       
    36     ]
    29     ignored = {'__init__'}
    37     ignored = {'__init__'}
    30     modules = {}
    38     modules = {}
    31 
    39 
    32     # convert from file name to module name, and count # of appearances
    40     # convert from file name to module name, and count # of appearances
    33     for name in names:
    41     for name in names:
    43         if count > 1:
    51         if count > 1:
    44             whitelist.append(name)
    52             whitelist.append(name)
    45 
    53 
    46     return whitelist
    54     return whitelist
    47 
    55 
       
    56 
    48 if __name__ == "__main__":
    57 if __name__ == "__main__":
    49     # in this case, it is assumed that result of "hg files" at
    58     # in this case, it is assumed that result of "hg files" at
    50     # multiple revisions is given via stdin
    59     # multiple revisions is given via stdin
    51     whitelist = modulewhitelist(sys.stdin)
    60     whitelist = modulewhitelist(sys.stdin)
    52     assert whitelist, "module whitelist is empty"
    61     assert whitelist, "module whitelist is empty"
    59         #    from mercurial import (
    68         #    from mercurial import (
    60         #        foo,
    69         #        foo,
    61         #        bar,
    70         #        bar,
    62         #        baz
    71         #        baz
    63         #    )
    72         #    )
    64         ((r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])'
    73         (
    65           % ',| *'.join(whitelist)),
    74             (
    66          "import newer module separately in try clause for early Mercurial"
    75                 r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])'
    67          ))
    76                 % ',| *'.join(whitelist)
       
    77             ),
       
    78             "import newer module separately in try clause for early Mercurial",
       
    79         )
       
    80     )
    68 
    81 
    69     # import contrib/check-code.py as checkcode
    82     # import contrib/check-code.py as checkcode
    70     assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script"
    83     assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script"
    71     contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib')
    84     contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib')
    72     sys.path.insert(0, contribpath)
    85     sys.path.insert(0, contribpath)
    73     checkcode = __import__('check-code')
    86     checkcode = __import__('check-code')
    74 
    87 
    75     # register perf.py specific entry with "checks" in check-code.py
    88     # register perf.py specific entry with "checks" in check-code.py
    76     checkcode.checks.append(('perf.py', r'contrib/perf.py$', '',
    89     checkcode.checks.append(
    77                              checkcode.pyfilters, perfpypats))
    90         ('perf.py', r'contrib/perf.py$', '', checkcode.pyfilters, perfpypats)
       
    91     )
    78 
    92 
    79     sys.exit(checkcode.main())
    93     sys.exit(checkcode.main())