comparison contrib/check-py3-compat.py @ 30117:b85fa6bf298b

py3: make check-py3-compat.py import importlib only if necessary importlib isn't available on Python 2.6, and it isn't necessary for Py2 checks.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 09 Oct 2016 17:02:34 +0200
parents e8aeeb28e35e
children 65cd7e705ff6
comparison
equal deleted inserted replaced
30116:1c01fa29630f 30117:b85fa6bf298b
8 # GNU General Public License version 2 or any later version. 8 # GNU General Public License version 2 or any later version.
9 9
10 from __future__ import absolute_import, print_function 10 from __future__ import absolute_import, print_function
11 11
12 import ast 12 import ast
13 import importlib
14 import os 13 import os
15 import sys 14 import sys
16 import traceback 15 import traceback
17 16
18 def check_compat_py2(f): 17 def check_compat_py2(f):
39 if haveprint and 'print_function' not in futures: 38 if haveprint and 'print_function' not in futures:
40 print('%s requires print_function' % f) 39 print('%s requires print_function' % f)
41 40
42 def check_compat_py3(f): 41 def check_compat_py3(f):
43 """Check Python 3 compatibility of a file with Python 3.""" 42 """Check Python 3 compatibility of a file with Python 3."""
43 import importlib # not available on Python 2.6
44 with open(f, 'rb') as fh: 44 with open(f, 'rb') as fh:
45 content = fh.read() 45 content = fh.read()
46 46
47 try: 47 try:
48 ast.parse(content) 48 ast.parse(content)