comparison contrib/check-py3-compat.py @ 28475:ae522fb493d4

test: make check-py3-compat.py ignore empty code more reliably It couldn't exclude an empty file containing comments. That's why hgext/__init__.py had been listed in test-check-py3-compat.t before "hgext: officially turn 'hgext' into a namespace package".
author Yuya Nishihara <yuya@tcha.org>
date Fri, 11 Mar 2016 10:26:58 +0900
parents 35e69407b1ac
children 260ce2eed951
comparison
equal deleted inserted replaced
28474:00e6e0d0bfeb 28475:ae522fb493d4
14 14
15 def check_compat(f): 15 def check_compat(f):
16 """Check Python 3 compatibility for a file.""" 16 """Check Python 3 compatibility for a file."""
17 with open(f, 'rb') as fh: 17 with open(f, 'rb') as fh:
18 content = fh.read() 18 content = fh.read()
19 root = ast.parse(content)
19 20
20 # Ignore empty files. 21 # Ignore empty files.
21 if not content.strip(): 22 if not root.body:
22 return 23 return
23 24
24 root = ast.parse(content)
25 futures = set() 25 futures = set()
26 haveprint = False 26 haveprint = False
27 for node in ast.walk(root): 27 for node in ast.walk(root):
28 if isinstance(node, ast.ImportFrom): 28 if isinstance(node, ast.ImportFrom):
29 if node.module == '__future__': 29 if node.module == '__future__':