Skip to content

Instantly share code, notes, and snippets.

@aaltat
Last active March 2, 2020 00:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaltat/5e7806d6ddf802054829b89d5eb33846 to your computer and use it in GitHub Desktop.
Save aaltat/5e7806d6ddf802054829b89d5eb33846 to your computer and use it in GitHub Desktop.
Find files which are not Python 3 compatible
import argparse
import subprocess
from pathlib import Path
def find_files(src_root: Path, python3: Path):
not_py3_compatible = []
for file in src_root.rglob('*.py'):
print(file.resolve())
args3 = [str(python3), '-m', 'py_compile', str(file)]
try:
py3_returncode = subprocess.run(args3).returncode
except Exception:
py3_returncode = 1
if py3_returncode != 0:
not_py3_compatible.append(file.resolve())
print(f'Found {len(not_py3_compatible)} files which are not Python 3 compatible.' )
for py2_file in not_py3_compatible:
print(py2_file)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Find files which are not compatible with Python 3.')
parser.add_argument('python', help='Path to Python 3 binary.')
parser.add_argument('src', help='Path to source code root folder.')
argments = parser.parse_args()
src_root = Path(argments.src)
python3 = Path(argments.python)
find_files(src_root, python3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment