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.
|
|
"""Glue for the "yapf" library.
"""
import osimport sys
from elpy.rpc import Fault
YAPF_NOT_SUPPORTED = sys.version_info < (2, 7) or ( sys.version_info >= (3, 0) and sys.version_info < (3, 4))
try: if YAPF_NOT_SUPPORTED: yapf_api = None else: from yapf.yapflib import yapf_api from yapf.yapflib import file_resourcesexcept ImportError: # pragma: no cover yapf_api = None
def fix_code(code, directory): """Formats Python code to conform to the PEP 8 style guide.
"""
if not yapf_api: raise Fault('yapf not installed', code=400) style_config = file_resources.GetDefaultStyleForDir(directory or os.getcwd()) try: reformatted_source, _ = yapf_api.FormatCode(code, filename='<stdin>', style_config=style_config, verify=False) return reformatted_source except Exception as e: raise Fault("Error during formatting: {}".format(e), code=400)
|