]>
crepu.dev Git - config.git/blob - djavu-asus/elpa/elpy-20230803.1455/elpy/yapfutil.py
1 """Glue for the "yapf" library.
8 from elpy
.rpc
import Fault
10 YAPF_NOT_SUPPORTED
= sys
.version_info
< (2, 7) or (
11 sys
.version_info
>= (3, 0) and sys
.version_info
< (3, 4))
14 if YAPF_NOT_SUPPORTED
:
17 from yapf
.yapflib
import yapf_api
18 from yapf
.yapflib
import file_resources
19 except ImportError: # pragma: no cover
23 def fix_code(code
, directory
):
24 """Formats Python code to conform to the PEP 8 style guide.
28 raise Fault('yapf not installed', code
=400)
29 style_config
= file_resources
.GetDefaultStyleForDir(directory
or os
.getcwd())
31 reformatted_source
, _
= yapf_api
.FormatCode(code
,
33 style_config
=style_config
,
35 return reformatted_source
36 except Exception as e
:
37 raise Fault("Error during formatting: {}".format(e
),