Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
547 B

4 years ago
  1. """Glue for the "autopep8" library.
  2. """
  3. from elpy.rpc import Fault
  4. import os
  5. try:
  6. import autopep8
  7. except ImportError: # pragma: no cover
  8. autopep8 = None
  9. def fix_code(code, directory):
  10. """Formats Python code to conform to the PEP 8 style guide.
  11. """
  12. if not autopep8:
  13. raise Fault('autopep8 not installed, cannot fix code.',
  14. code=400)
  15. old_dir = os.getcwd()
  16. try:
  17. os.chdir(directory)
  18. return autopep8.fix_code(code, apply_config=True)
  19. finally:
  20. os.chdir(old_dir)