comparison contrib/check-code.py @ 41827:55ae5cd31f76

contrib: refactor preparation logic for patterns of check-code.py This is a part of preparation to apply checking with check-code.py on code fragments embedded in *.t test scripts. Before this patch, preparation logic in _preparepats() of check-code.py is not reusable. It can handle only module global list "checks". This patch splits preparation logic into small internal functions, and add the loop to invoke them, in order to increase reusability of the logic. "c[-2]" is equivalent to "c[3]" for "checks". This patch uses the former, because it will be more reusable for subsequent patch than the latter.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 01 Mar 2019 02:53:09 +0900
parents 14e8d042993a
children 7a139fc60eb0
comparison
equal deleted inserted replaced
41826:14e8d042993a 41827:55ae5cd31f76
559 ('all except for .po', r'.*(?<!\.po)$', '', 559 ('all except for .po', r'.*(?<!\.po)$', '',
560 allfilesfilters, allfilespats), 560 allfilesfilters, allfilespats),
561 ] 561 ]
562 562
563 def _preparepats(): 563 def _preparepats():
564 for c in checks: 564 def preparefailandwarn(failandwarn):
565 failandwarn = c[-1]
566 for pats in failandwarn: 565 for pats in failandwarn:
567 for i, pseq in enumerate(pats): 566 for i, pseq in enumerate(pats):
568 # fix-up regexes for multi-line searches 567 # fix-up regexes for multi-line searches
569 p = pseq[0] 568 p = pseq[0]
570 # \s doesn't match \n (done in two steps) 569 # \s doesn't match \n (done in two steps)
574 p = re.sub(r'(?<!(\\|\[))\\s', r'[ \\t]', p) 573 p = re.sub(r'(?<!(\\|\[))\\s', r'[ \\t]', p)
575 # [^...] doesn't match newline 574 # [^...] doesn't match newline
576 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) 575 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
577 576
578 pats[i] = (re.compile(p, re.MULTILINE),) + pseq[1:] 577 pats[i] = (re.compile(p, re.MULTILINE),) + pseq[1:]
579 filters = c[3] 578
579 def preparefilters(filters):
580 for i, flt in enumerate(filters): 580 for i, flt in enumerate(filters):
581 filters[i] = re.compile(flt[0]), flt[1] 581 filters[i] = re.compile(flt[0]), flt[1]
582
583 for cs in (checks,):
584 for c in cs:
585 failandwarn = c[-1]
586 preparefailandwarn(failandwarn)
587
588 filters = c[-2]
589 preparefilters(filters)
582 590
583 class norepeatlogger(object): 591 class norepeatlogger(object):
584 def __init__(self): 592 def __init__(self):
585 self._lastseen = None 593 self._lastseen = None
586 594