Update check_include_guards.py

Fixed the Py3 checker issue during import. Use print() instead of print and add "from __future__ import print_function" for py2 and py3 compatibility.
pull/23721/head
nanahpang 4 years ago committed by GitHub
parent 61620a0963
commit 997e6a7910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      tools/distrib/check_include_guards.py

@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import argparse import argparse
import os import os
import os.path import os.path
@ -62,22 +63,22 @@ class GuardValidator(object):
'...\n') + ('#endif /* {2} */' '...\n') + ('#endif /* {2} */'
if c_core_header else '#endif // {2}') if c_core_header else '#endif // {2}')
if not match_txt: if not match_txt:
print invalid_guards_msg_template.format(fpath, regexp.pattern, print(invalid_guards_msg_template.format(fpath, regexp.pattern,
build_valid_guard(fpath)) build_valid_guard(fpath)))
return fcontents return fcontents
print( print((
'{}: Wrong preprocessor guards (RE {}):' '{}: Wrong preprocessor guards (RE {}):'
'\n\tFound {}, expected {}').format(fpath, regexp.pattern, '\n\tFound {}, expected {}').format(fpath, regexp.pattern,
match_txt, correct) match_txt, correct))
if fix: if fix:
print 'Fixing {}...\n'.format(fpath) print('Fixing {}...\n'.format(fpath))
fixed_fcontents = re.sub(match_txt, correct, fcontents) fixed_fcontents = re.sub(match_txt, correct, fcontents)
if fixed_fcontents: if fixed_fcontents:
self.failed = False self.failed = False
return fixed_fcontents return fixed_fcontents
else: else:
print print()
return fcontents return fcontents
def check(self, fpath, fix): def check(self, fpath, fix):
@ -89,7 +90,7 @@ class GuardValidator(object):
match = self.ifndef_re.search(fcontents) match = self.ifndef_re.search(fcontents)
if not match: if not match:
print 'something drastically wrong with: %s' % fpath print('something drastically wrong with: %s' % fpath)
return False # failed return False # failed
if match.lastindex is None: if match.lastindex is None:
# No ifndef. Request manual addition with hints # No ifndef. Request manual addition with hints

Loading…
Cancel
Save