##// END OF EJS Templates
check-code: use absolute_import and print_function
Pulkit Goyal -
r28509:9e3ecb6f default
parent child Browse files
Show More
@@ -19,9 +19,13 b' when a rule triggers wrong, do one of th'
19 * ONLY use no--check-code for skipping entire files from external sources
19 * ONLY use no--check-code for skipping entire files from external sources
20 """
20 """
21
21
22 import re, glob, os, sys
22 from __future__ import absolute_import, print_function
23 import glob
23 import keyword
24 import keyword
24 import optparse
25 import optparse
26 import os
27 import re
28 import sys
25 try:
29 try:
26 import re2
30 import re2
27 except ImportError:
31 except ImportError:
@@ -443,12 +447,12 b' class norepeatlogger(object):'
443 msgid = fname, lineno, line
447 msgid = fname, lineno, line
444 if msgid != self._lastseen:
448 if msgid != self._lastseen:
445 if blame:
449 if blame:
446 print "%s:%d (%s):" % (fname, lineno, blame)
450 print("%s:%d (%s):" % (fname, lineno, blame))
447 else:
451 else:
448 print "%s:%d:" % (fname, lineno)
452 print("%s:%d:" % (fname, lineno))
449 print " > %s" % line
453 print(" > %s" % line)
450 self._lastseen = msgid
454 self._lastseen = msgid
451 print " " + msg
455 print(" " + msg)
452
456
453 _defaultlogger = norepeatlogger()
457 _defaultlogger = norepeatlogger()
454
458
@@ -478,19 +482,19 b' def checkfile(f, logfunc=_defaultlogger.'
478 try:
482 try:
479 fp = open(f)
483 fp = open(f)
480 except IOError as e:
484 except IOError as e:
481 print "Skipping %s, %s" % (f, str(e).split(':', 1)[0])
485 print("Skipping %s, %s" % (f, str(e).split(':', 1)[0]))
482 return result
486 return result
483 pre = post = fp.read()
487 pre = post = fp.read()
484 fp.close()
488 fp.close()
485
489
486 for name, match, magic, filters, pats in checks:
490 for name, match, magic, filters, pats in checks:
487 if debug:
491 if debug:
488 print name, f
492 print(name, f)
489 fc = 0
493 fc = 0
490 if not (re.match(match, f) or (magic and re.search(magic, pre))):
494 if not (re.match(match, f) or (magic and re.search(magic, pre))):
491 if debug:
495 if debug:
492 print "Skipping %s for %s it doesn't match %s" % (
496 print("Skipping %s for %s it doesn't match %s" % (
493 name, match, f)
497 name, match, f))
494 continue
498 continue
495 if "no-" "check-code" in pre:
499 if "no-" "check-code" in pre:
496 # If you're looking at this line, it's because a file has:
500 # If you're looking at this line, it's because a file has:
@@ -499,7 +503,7 b' def checkfile(f, logfunc=_defaultlogger.'
499 # tests easier. So, instead of writing it with a normal
503 # tests easier. So, instead of writing it with a normal
500 # spelling, we write it with the expected spelling from
504 # spelling, we write it with the expected spelling from
501 # tests/test-check-code.t
505 # tests/test-check-code.t
502 print "Skipping %s it has no-che?k-code (glob)" % f
506 print("Skipping %s it has no-che?k-code (glob)" % f)
503 return "Skip" # skip checking this file
507 return "Skip" # skip checking this file
504 for p, r in filters:
508 for p, r in filters:
505 post = re.sub(p, r, post)
509 post = re.sub(p, r, post)
@@ -511,7 +515,7 b' def checkfile(f, logfunc=_defaultlogger.'
511 # print post # uncomment to show filtered version
515 # print post # uncomment to show filtered version
512
516
513 if debug:
517 if debug:
514 print "Checking %s for %s" % (name, f)
518 print("Checking %s for %s" % (name, f))
515
519
516 prelines = None
520 prelines = None
517 errors = []
521 errors = []
@@ -542,8 +546,8 b' def checkfile(f, logfunc=_defaultlogger.'
542
546
543 if ignore and re.search(ignore, l, re.MULTILINE):
547 if ignore and re.search(ignore, l, re.MULTILINE):
544 if debug:
548 if debug:
545 print "Skipping %s for %s:%s (ignore pattern)" % (
549 print("Skipping %s for %s:%s (ignore pattern)" % (
546 name, f, n)
550 name, f, n))
547 continue
551 continue
548 bd = ""
552 bd = ""
549 if blame:
553 if blame:
@@ -563,7 +567,7 b' def checkfile(f, logfunc=_defaultlogger.'
563 logfunc(*e)
567 logfunc(*e)
564 fc += 1
568 fc += 1
565 if maxerr and fc >= maxerr:
569 if maxerr and fc >= maxerr:
566 print " (too many errors, giving up)"
570 print(" (too many errors, giving up)")
567 break
571 break
568
572
569 return result
573 return result
@@ -3,8 +3,6 b''
3 $ cd "$TESTDIR"/..
3 $ cd "$TESTDIR"/..
4
4
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 contrib/check-code.py not using absolute_import
7 contrib/check-code.py requires print_function
8 contrib/import-checker.py not using absolute_import
6 contrib/import-checker.py not using absolute_import
9 contrib/import-checker.py requires print_function
7 contrib/import-checker.py requires print_function
10 contrib/memory.py not using absolute_import
8 contrib/memory.py not using absolute_import
General Comments 0
You need to be logged in to leave comments. Login now