pycodestyle.py 975 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. Code style cleanups done after yapf
  3. """
  4. import argparse
  5. import codecs
  6. import os
  7. from extras import fixdictsformatting
  8. CLEANUPS = [
  9. fixdictsformatting,
  10. ]
  11. def walk_directory(root, dirs, files):
  12. for filename in files:
  13. if filename.lower().endswith('.py'):
  14. with codecs.open(os.path.join(root, filename), 'r', 'utf-8') as f:
  15. filesource = f.read()
  16. org_source = filesource
  17. for cleanup in CLEANUPS:
  18. filesource = cleanup.fix_formatting(filesource)
  19. if org_source != filesource:
  20. print 'afterclean: %s' % os.path.join(root, filename)
  21. with codecs.open(os.path.join(root, filename), 'w', 'utf-8') as f:
  22. f.write(filesource)
  23. if __name__ == '__main__':
  24. parser = argparse.ArgumentParser()
  25. parser.add_argument('path', nargs='?', default='./')
  26. for args in os.walk(parser.parse_args().path):
  27. walk_directory(*args)