Skip to content

Instantly share code, notes, and snippets.

@yoavram
Created October 8, 2015 21:58
Show Gist options
  • Select an option

  • Save yoavram/4eb7318b45ce996f1caf to your computer and use it in GitHub Desktop.

Select an option

Save yoavram/4eb7318b45ce996f1caf to your computer and use it in GitHub Desktop.
walks through a folder, collects python files, calls futurize
from __future__ import print_function
import glob
import os
import subprocess
blacklist = [__file__, 'venv', 'venv3', 'build', 'dist']
def walker(path):
"""Folder walker that collects .py files
"""
files = []
for fn in glob.glob(os.path.join(path, "*")):
if fn in [os.path.join(path, x) for x in blacklist]:
continue
if os.path.isdir(fn):
files.extend(walker(fn))
elif os.path.splitext(fn)[-1] == '.py':
files.append(fn)
return files
def future(path):
"""Runs futurize on python files
See: http://python-future.org/automatic_conversion.html
"""
print(path)
print(subprocess.check_output(['futurize', '--stage1', path])) # '-w', '--unicode-literals'
print()
if __name__ == '__main__':
for fn in walker('.'):
future(fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment