Skip to content

Instantly share code, notes, and snippets.

@hugovk
Forked from aaltat/py_finder.py
Last active February 28, 2020 17:56
Show Gist options
  • Save hugovk/7a9b683358beba9e9a117243fa60250e to your computer and use it in GitHub Desktop.
Save hugovk/7a9b683358beba9e9a117243fa60250e to your computer and use it in GitHub Desktop.
Find files which are not Python 3 compatible
import argparse
import subprocess
import sys
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)
return len(not_py3_compatible)
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)
ret = find_files(src_root, python3)
sys.exit(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment